From f41c300a2d193129638686ef9ba8e77223bc0630 Mon Sep 17 00:00:00 2001 From: Jerod Santo Date: Thu, 25 Jul 2024 15:41:33 -0500 Subject: [PATCH] Refine custom feed management --- assets/app/app.js | 3 +- lib/changelog/policies/feed.ex | 1 + .../controllers/home/feed_controller.ex | 25 ++++++------- lib/changelog_web/router.ex | 1 + .../templates/home/feed/_form.html.heex | 7 +++- .../templates/home/feed/index.html.heex | 35 +++++++++++-------- .../templates/home/profile.html.eex | 4 +-- 7 files changed, 43 insertions(+), 33 deletions(-) diff --git a/assets/app/app.js b/assets/app/app.js index 1d9bdd1e4e..30e4aeae07 100644 --- a/assets/app/app.js +++ b/assets/app/app.js @@ -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); }); }); diff --git a/lib/changelog/policies/feed.ex b/lib/changelog/policies/feed.ex index 8fab76dde0..86a9034059 100644 --- a/lib/changelog/policies/feed.ex +++ b/lib/changelog/policies/feed.ex @@ -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) diff --git a/lib/changelog_web/controllers/home/feed_controller.ex b/lib/changelog_web/controllers/home/feed_controller.ex index a8c421a96f..0965f9e9f6 100644 --- a/lib/changelog_web/controllers/home/feed_controller.ex +++ b/lib/changelog_web/controllers/home/feed_controller.ex @@ -14,7 +14,7 @@ defmodule ChangelogWeb.Home.FeedController do conn |> assign(:feeds, feeds) - |> render() + |> render(:index) end def new(conn, _params) do @@ -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) @@ -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! ✨") @@ -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 @@ -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() @@ -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 diff --git a/lib/changelog_web/router.ex b/lib/changelog_web/router.ex index 129295f228..b2522bf78e 100644 --- a/lib/changelog_web/router.ex +++ b/lib/changelog_web/router.ex @@ -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 diff --git a/lib/changelog_web/templates/home/feed/_form.html.heex b/lib/changelog_web/templates/home/feed/_form.html.heex index 580efe9e3a..ac22c68a8b 100644 --- a/lib/changelog_web/templates/home/feed/_form.html.heex +++ b/lib/changelog_web/templates/home/feed/_form.html.heex @@ -89,7 +89,12 @@
-

+

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

+
diff --git a/lib/changelog_web/templates/home/feed/index.html.heex b/lib/changelog_web/templates/home/feed/index.html.heex index 2a761d72bd..12e08fadbc 100644 --- a/lib/changelog_web/templates/home/feed/index.html.heex +++ b/lib/changelog_web/templates/home/feed/index.html.heex @@ -1,42 +1,47 @@
<%= render(HomeView, "_nav.html", assigns) %> -
- <%= link("Add Feed", to: ~p"/~/feeds/new", class: "button") %> -
- + <%= if Enum.any?(@feeds) do %> +
<% widths = %{feed: 18, cover: 12, includes: 50, actions: 20} %> - - - + + + + <%= for feed <- @feeds do %> - + - - <% end %>
FeedIncludesActionsFeedCoverIncludesActions
- -
- <%= feed.name %> +
<%= feed.name %> + + <%= for podcast <- @podcasts do %> <%= if Enum.member?(feed.podcast_ids, podcast.id) do %> <% end %> <% end %> + + Get URL +
+ <%= link("Refresh", to: ~p"/~/feeds/#{feed}/refresh", method: :post) %> +
<%= 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?"]) %>
+ <% end %> + +
+ <%= link("Add Feed", to: ~p"/~/feeds/new", class: "button_large") %> +
diff --git a/lib/changelog_web/templates/home/profile.html.eex b/lib/changelog_web/templates/home/profile.html.eex index 5de5c6bdfa..49938d4f44 100644 --- a/lib/changelog_web/templates/home/profile.html.eex +++ b/lib/changelog_web/templates/home/profile.html.eex @@ -4,9 +4,9 @@
<%= if @current_user.public_profile do %> -

Your <%= link("public profile", to: PersonView.profile_path(@current_user)) %> page shows news you've contributed and podcasts you've been on.

+

Your <%= link("public profile", to: PersonView.profile_path(@current_user)) %> page shows podcast episodes you've been on.

<% else %> -

Profiles pages show news you've contributed and podcasts you've been on. Your profile is private.

+

Profiles pages show podcast episodes you've been on. Your profile is private.

<% end %>