Skip to content

Commit

Permalink
Refine custom feed management
Browse files Browse the repository at this point in the history
  • Loading branch information
jerodsanto committed Jul 25, 2024
1 parent d1fad5f commit f41c300
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 33 deletions.
3 changes: 2 additions & 1 deletion assets/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ u(document).handle("click", "[data-copy]", function (event) {
const data = [new ClipboardItem({ [type]: blob })];

navigator.clipboard.write(data).then(() => {
let preText = u(el).text();
u(el).text("Copied!");
setTimeout(() => {
u(el).text("Share");
u(el).text(preText);
}, 1500);
});
});
Expand Down
1 change: 1 addition & 0 deletions lib/changelog/policies/feed.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Changelog.Policies.Feed do
def create(actor), do: new(actor)

def edit(actor, feed), do: is_owner(actor, feed)
def refresh(actor, feed), do: edit(actor, feed)
def update(actor, feed), do: edit(actor, feed)
def delete(actor, feed), do: edit(actor, feed)

Expand Down
25 changes: 11 additions & 14 deletions lib/changelog_web/controllers/home/feed_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule ChangelogWeb.Home.FeedController do

conn
|> assign(:feeds, feeds)
|> render()
|> render(:index)
end

def new(conn, _params) do
Expand All @@ -37,9 +37,6 @@ defmodule ChangelogWeb.Home.FeedController do
|> redirect(to: ~p"/~/feeds")

{:error, changeset} ->
require IEx
IEx.pry()

conn
|> put_flash(:error, "There was a problem saving your feed. 😭")
|> assign(:changeset, changeset)
Expand All @@ -57,7 +54,7 @@ defmodule ChangelogWeb.Home.FeedController do

case Repo.update(changeset) do
{:ok, feed} ->
params = replace_next_edit_path(params, ~p"/~/feeds/#{feed}/edit")
FeedUpdater.queue(feed)

conn
|> put_flash(:success, "Your feed has been updated! ✨")
Expand All @@ -70,20 +67,20 @@ defmodule ChangelogWeb.Home.FeedController do
end
end

def delete(conn = %{assigns: %{feed: feed}}, _params) do
def delete(conn = %{assigns: %{feed: feed}}, params) do
Repo.delete!(feed)

conn
|> put_flash(:success, "Your feed has been put out to pasture. 🐑")
|> redirect(to: ~p"/~/feeds")
|> redirect_next(params, ~p"/~/feeds")
end

def refresh(conn = %{assigns: %{feed: feed}}, _params) do
def refresh(conn = %{assigns: %{feed: feed}}, params) do
FeedUpdater.queue(feed)

conn
|> put_flash(:success, "Your feed is being rebuilt as we speak. 🥂")
|> redirect(to: ~p"/~/feeds")
|> redirect_next(params, ~p"/~/feeds")
end

defp preload_current_user_extras(conn = %{assigns: %{current_user: me}}, _) do
Expand All @@ -95,6 +92,11 @@ defmodule ChangelogWeb.Home.FeedController do
assign(conn, :current_user, me)
end

defp assign_feed(conn = %{params: %{"id" => id}}, _params) do
feed = Feed |> Repo.get(id) |> Feed.preload_all()
assign(conn, :feed, feed)
end

defp assign_podcasts(conn, _params) do
podcasts =
Podcast.active()
Expand All @@ -103,9 +105,4 @@ defmodule ChangelogWeb.Home.FeedController do

assign(conn, :podcasts, podcasts)
end

defp assign_feed(conn = %{params: %{"id" => id}}, _params) do
feed = Feed |> Repo.get(id) |> Feed.preload_all()
assign(conn, :feed, feed)
end
end
1 change: 1 addition & 0 deletions lib/changelog_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ defmodule ChangelogWeb.Router do
post "/~/unsubscribe", HomeController, :unsubscribe

resources "/~/feeds", Home.FeedController
post "/~/feeds/:id/refresh", Home.FeedController, :refresh

get "/in", AuthController, :new, as: :sign_in
post "/in", AuthController, :new, as: :sign_in
Expand Down
7 changes: 6 additions & 1 deletion lib/changelog_web/templates/home/feed/_form.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@
</div>

<div class="form-submit">
<p class="form-submit-toc"></p>
<p class="form-submit-toc">
<%= if f.data.id do %>
<%= link("Delete this feed", to: ~p"/~/feeds/#{f.data.id}", method: :delete, data: [confirm: "Are you sure?"]) %>
<% end %>
</p>

<div>
<input type="submit" value="Save">
<div class="form_submit_responses"></div>
Expand Down
35 changes: 20 additions & 15 deletions lib/changelog_web/templates/home/feed/index.html.heex
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
<div class="page_basic">
<%= render(HomeView, "_nav.html", assigns) %>
<div class="actions">
<%= link("Add Feed", to: ~p"/~/feeds/new", class: "button") %>
</div>

<div class="richtext">
<table>
<%= if Enum.any?(@feeds) do %>
<table><% widths = %{feed: 18, cover: 12, includes: 50, actions: 20} %>
<thead>
<tr>
<td style="width: 18%">Feed</td>
<td style="width: 50%">Includes</td>
<td style="width: 32%; text-align: right;">Actions</td>
<th style={"width: #{widths.feed}%"}>Feed</th>
<th style={"width: #{widths.cover}%"}>Cover</th>
<th style={"width: #{widths.includes}%"}>Includes</th>
<th style={"width: #{widths.actions}%; text-align: right;"}>Actions</th>
</tr>
</thead>

<tbody>
<%= for feed <- @feeds do %>
<tr>
<td style="width: 18%">
<img src={PodcastView.cover_url(feed, :small)} style="display: inline-block; width: 50px; margin: 0 auto;">
<br/>
<%= feed.name %>
<td style={"width: #{widths.feed}%"}><%= feed.name %></td>
<td style={"width: #{widths.cover}%"}>
<img src={PodcastView.cover_url(feed, :small)} width="50" height="50">
</td>
<td style="width: 50%">
<td style={"width: #{widths.includes}%"}>
<%= for podcast <- @podcasts do %>
<%= if Enum.member?(feed.podcast_ids, podcast.id) do %>
<img src={PodcastView.cover_url(podcast, :small)} style="display: inline-block; width: 35px; margin: 0 auto;">
<% end %>
<% end %>
</td>
<td style="width: 32%; text-align: right;">
<td style={"width: #{widths.actions}%; text-align: right;"}>
<a href={~p"/feeds/#{feed.slug}"} data-copy={~p"/feeds/#{feed.slug}"}>Get URL</a>
<br/>
<%= link("Refresh", to: ~p"/~/feeds/#{feed}/refresh", method: :post) %>
<br/>
<%= link("Edit", to: ~p"/~/feeds/#{feed}/edit") %>
<%= link("Refresh", to: ~p"/~/feeds/#{feed}/edit") %>
<%= link("Delete", to: ~p"/~/feeds/#{feed}", method: :delete, data: [confirm: "Are you sure?"]) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

<div class="actions" style="float: right; margin-bottom: 15px;">
<%= link("Add Feed", to: ~p"/~/feeds/new", class: "button_large") %>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions lib/changelog_web/templates/home/profile.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<div class="flash flash--inline flash--success">
<div class="flash-message">
<%= if @current_user.public_profile do %>
<p>Your <%= link("public profile", to: PersonView.profile_path(@current_user)) %> page shows news you've contributed and podcasts you've been on.</p>
<p>Your <%= link("public profile", to: PersonView.profile_path(@current_user)) %> page shows podcast episodes you've been on.</p>
<% else %>
<p>Profiles pages show news you've contributed and podcasts you've been on. Your profile is private.</p>
<p>Profiles pages show podcast episodes you've been on. Your profile is private.</p>
<% end %>
</div>
</div>
Expand Down

0 comments on commit f41c300

Please sign in to comment.