From e9f3a431877fe6fa1d496fd98d54d072d19b7087 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Mon, 9 Sep 2024 23:20:24 +0100 Subject: [PATCH 01/30] refactor: announcement forms --- lib/atomic/organizations.ex | 22 +++++++++++-- .../live/announcement_live/form_component.ex | 33 +++++++++++++++++-- .../form_component.html.heex | 18 +++++++--- lib/atomic_web/live/home_live/index.html.heex | 10 ++++-- 4 files changed, 71 insertions(+), 12 deletions(-) diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index 98f23f588..0e63f2407 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -564,7 +564,7 @@ defmodule Atomic.Organizations do {:error, %Ecto.Changeset{}} """ - def create_announcement_with_post(attrs \\ %{}) do + def create_announcement_with_post(attrs \\ %{}, after_save \\ &{:ok, &1}) do Multi.new() |> Multi.insert(:post, fn _ -> %Post{} @@ -580,7 +580,7 @@ defmodule Atomic.Organizations do |> Repo.transaction() |> case do {:ok, %{announcement: announcement, post: _post}} -> - {:ok, announcement} + after_save.({:ok, announcement}) {:error, _reason, changeset, _actions} -> {:error, changeset} @@ -639,4 +639,22 @@ defmodule Atomic.Organizations do def change_announcement(%Announcement{} = announcement, attrs \\ %{}) do Announcement.changeset(announcement, attrs) end + + @doc """ + Updates an announcement image. + + ## Examples + + iex> update_announcement_image(announcement, %{field: new_value}) + {:ok, %Announcement{}} + + iex> update_announcement_image(announcement, %{field: bad_value}) + {:error, %Ecto.Changeset{}} + + """ + def update_announcement_image(%Announcement{} = announcement, attrs) do + announcement + |> Announcement.image_changeset(attrs) + |> Repo.update() + end end diff --git a/lib/atomic_web/live/announcement_live/form_component.ex b/lib/atomic_web/live/announcement_live/form_component.ex index dc264e029..7d21121b2 100644 --- a/lib/atomic_web/live/announcement_live/form_component.ex +++ b/lib/atomic_web/live/announcement_live/form_component.ex @@ -2,6 +2,7 @@ defmodule AtomicWeb.AnnouncementLive.FormComponent do use AtomicWeb, :live_component alias Atomic.Organizations + alias AtomicWeb.Components.ImageUploader import AtomicWeb.Components.Forms @@ -17,7 +18,8 @@ defmodule AtomicWeb.AnnouncementLive.FormComponent do {:ok, socket |> assign(assigns) - |> assign(:changeset, changeset)} + |> assign(:changeset, changeset) + |> allow_upload(:image, accept: Uploaders.Post.extension_whitelist(), max_entries: 1)} end @impl true @@ -35,10 +37,16 @@ defmodule AtomicWeb.AnnouncementLive.FormComponent do save_announcement(socket, socket.assigns.action, announcement_params) end + @impl true + def handle_event("cancel-image", %{"ref" => ref}, socket) do + {:noreply, cancel_upload(socket, :image, ref)} + end + defp save_announcement(socket, :edit, announcement_params) do case Organizations.update_announcement( socket.assigns.announcement, - announcement_params + announcement_params, + &consume_image_data(socket, &1) ) do {:ok, _announcement} -> {:noreply, @@ -55,7 +63,7 @@ defmodule AtomicWeb.AnnouncementLive.FormComponent do announcement_params = Map.put(announcement_params, "organization_id", socket.assigns.organization.id) - case Organizations.create_announcement_with_post(announcement_params) do + case Organizations.create_announcement_with_post(announcement_params, &consume_image_data(socket, &1)) do {:ok, _announcement} -> {:noreply, socket @@ -66,4 +74,23 @@ defmodule AtomicWeb.AnnouncementLive.FormComponent do {:noreply, assign(socket, :changeset, changeset)} end end + + defp consume_image_data(socket, announcement) do + consume_uploaded_entries(socket, :image, fn %{path: path}, entry -> + Organizations.update_announcement_image(announcement, %{ + "image" => %Plug.Upload{ + content_type: entry.content_type, + filename: entry.client_name, + path: path + } + }) + end) + |> case do + [{:ok, announcement}] -> + {:ok, announcement} + + _errors -> + {:ok, announcement} + end + end end diff --git a/lib/atomic_web/live/announcement_live/form_component.html.heex b/lib/atomic_web/live/announcement_live/form_component.html.heex index 731989009..07ee84607 100644 --- a/lib/atomic_web/live/announcement_live/form_component.html.heex +++ b/lib/atomic_web/live/announcement_live/form_component.html.heex @@ -1,10 +1,20 @@
<.form :let={f} for={@changeset} id="announcement-form" phx-target={@myself} phx-change="validate" phx-submit="save"> - <.field field={f[:title]} help_text={gettext("The title of the announcement")} type="text" placeholder="Title" required /> +
+
+
+ <.field field={f[:title]} type="text" placeholder="Choose a title for the announcement" required class="w-full" /> - <.field field={f[:description]} help_text={gettext("Announcement description")} type="text" placeholder="Description" required /> - -
+ <.field field={f[:description]} type="textarea" placeholder="Write a description" required class="w-full h-44 overflow-auto" /> +
+
+ +
+ <.live_component module={ImageUploader} id="uploader" uploads={@uploads} target={@myself} /> +
+
+ +
<.button size={:md} color={:white} icon={:cube} type="submit"><%= gettext("Save Changes") %>
diff --git a/lib/atomic_web/live/home_live/index.html.heex b/lib/atomic_web/live/home_live/index.html.heex index 094b6e80a..0f7a10d74 100644 --- a/lib/atomic_web/live/home_live/index.html.heex +++ b/lib/atomic_web/live/home_live/index.html.heex @@ -46,9 +46,13 @@ <.activity activity={post.activity} /> <% else %> - <.link navigate={Routes.announcement_show_path(@socket, :show, post.announcement)}> - <.announcement announcement={post.announcement} /> - + <%= if post.announcement do %> + <.link navigate={Routes.announcement_show_path(@socket, :show, post.announcement)}> + <.announcement announcement={post.announcement} /> + + <% else %> +

No announcements available

+ <% end %> <% end %> From 750bedf48ac354c559735c1b98054053c74ca229 Mon Sep 17 00:00:00 2001 From: FilipeR13 Date: Tue, 10 Sep 2024 18:43:43 +0100 Subject: [PATCH 02/30] fix: upload images annoucments --- lib/atomic_web/live/announcement_live/form_component.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/form_component.ex b/lib/atomic_web/live/announcement_live/form_component.ex index 7d21121b2..3cf53370e 100644 --- a/lib/atomic_web/live/announcement_live/form_component.ex +++ b/lib/atomic_web/live/announcement_live/form_component.ex @@ -75,11 +75,11 @@ defmodule AtomicWeb.AnnouncementLive.FormComponent do end end - defp consume_image_data(socket, announcement) do + defp consume_image_data(socket, {:ok, announcement}) do consume_uploaded_entries(socket, :image, fn %{path: path}, entry -> Organizations.update_announcement_image(announcement, %{ "image" => %Plug.Upload{ - content_type: entry.content_type, + content_type: entry.client_type, filename: entry.client_name, path: path } From 8f56c58ca272c10b8b21189836742a81928583aa Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Tue, 10 Sep 2024 23:29:14 +0100 Subject: [PATCH 03/30] feat: completed announcement feed page --- lib/atomic_web/live/announcement_live/index.ex | 2 +- .../live/announcement_live/index.html.heex | 15 +++------------ lib/atomic_web/live/home_live/index.html.heex | 10 +++------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/index.ex b/lib/atomic_web/live/announcement_live/index.ex index 2c26e45bb..9c30eedc4 100644 --- a/lib/atomic_web/live/announcement_live/index.ex +++ b/lib/atomic_web/live/announcement_live/index.ex @@ -1,7 +1,7 @@ defmodule AtomicWeb.AnnouncementLive.Index do use AtomicWeb, :live_view - import AtomicWeb.Components.{Button, Empty, Pagination, Tabs} + import AtomicWeb.Components.{Announcement,Button, Empty, Pagination, Tabs} alias Atomic.Accounts alias Atomic.Organizations diff --git a/lib/atomic_web/live/announcement_live/index.html.heex b/lib/atomic_web/live/announcement_live/index.html.heex index fe6cce42f..3eb892fe8 100644 --- a/lib/atomic_web/live/announcement_live/index.html.heex +++ b/lib/atomic_web/live/announcement_live/index.html.heex @@ -29,18 +29,9 @@
    <%= for announcement <- @announcements do %> -
  • - <.link navigate={Routes.announcement_show_path(@socket, :show, announcement)} class="block hover:bg-zinc-50"> -
    -
    -

    - <%= announcement.title %> -

    -
    -

    - <%= announcement.description %> -

    -
    +
  • + <.link navigate={Routes.announcement_show_path(@socket, :show, announcement)}> + <.announcement announcement={announcement} />
  • <% end %> diff --git a/lib/atomic_web/live/home_live/index.html.heex b/lib/atomic_web/live/home_live/index.html.heex index 0f7a10d74..094b6e80a 100644 --- a/lib/atomic_web/live/home_live/index.html.heex +++ b/lib/atomic_web/live/home_live/index.html.heex @@ -46,13 +46,9 @@ <.activity activity={post.activity} /> <% else %> - <%= if post.announcement do %> - <.link navigate={Routes.announcement_show_path(@socket, :show, post.announcement)}> - <.announcement announcement={post.announcement} /> - - <% else %> -

    No announcements available

    - <% end %> + <.link navigate={Routes.announcement_show_path(@socket, :show, post.announcement)}> + <.announcement announcement={post.announcement} /> + <% end %>
From 55b65af3f59f55d93885984df822bde3c2bafd34 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Tue, 10 Sep 2024 23:49:49 +0100 Subject: [PATCH 04/30] feat: show announcement page --- lib/atomic_web/live/announcement_live/show.ex | 2 ++ .../live/announcement_live/show.html.heex | 15 ++++----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/show.ex b/lib/atomic_web/live/announcement_live/show.ex index 41c8b5c7f..0643e31ec 100644 --- a/lib/atomic_web/live/announcement_live/show.ex +++ b/lib/atomic_web/live/announcement_live/show.ex @@ -1,6 +1,8 @@ defmodule AtomicWeb.AnnouncementLive.Show do use AtomicWeb, :live_view + import AtomicWeb.Components.Announcement + alias Atomic.Accounts alias Atomic.Organizations diff --git a/lib/atomic_web/live/announcement_live/show.html.heex b/lib/atomic_web/live/announcement_live/show.html.heex index 4a0c03b56..39f842064 100644 --- a/lib/atomic_web/live/announcement_live/show.html.heex +++ b/lib/atomic_web/live/announcement_live/show.html.heex @@ -1,15 +1,8 @@
-
-
-
-

- <%= @announcement.title %> -

-
-

- <%= @announcement.description %> -

-
+
+ <.link navigate={Routes.announcement_show_path(@socket, :show, @announcement)}> + <.announcement announcement={@announcement} /> +
From f61df59a91327c8c871e33154457959e3efb5130 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Wed, 11 Sep 2024 10:20:37 +0100 Subject: [PATCH 05/30] fix: textarea size in create an announcement page --- .../live/announcement_live/form_component.html.heex | 8 ++++---- lib/atomic_web/live/announcement_live/show.html.heex | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/form_component.html.heex b/lib/atomic_web/live/announcement_live/form_component.html.heex index 07ee84607..1bdd285a3 100644 --- a/lib/atomic_web/live/announcement_live/form_component.html.heex +++ b/lib/atomic_web/live/announcement_live/form_component.html.heex @@ -1,11 +1,11 @@
- <.form :let={f} for={@changeset} id="announcement-form" phx-target={@myself} phx-change="validate" phx-submit="save"> -
+ <.form :let={f} for={@changeset} id="announcement-form" phx-target={@myself} phx-change="validate" phx-submit="save" class="space-y-6"> +
-
+
<.field field={f[:title]} type="text" placeholder="Choose a title for the announcement" required class="w-full" /> - <.field field={f[:description]} type="textarea" placeholder="Write a description" required class="w-full h-44 overflow-auto" /> + <.field field={f[:description]} type="textarea" placeholder="Write a description" required class="w-full overflow-auto resize-none h-44 xl:h-64" />
diff --git a/lib/atomic_web/live/announcement_live/show.html.heex b/lib/atomic_web/live/announcement_live/show.html.heex index 39f842064..62fcf6857 100644 --- a/lib/atomic_web/live/announcement_live/show.html.heex +++ b/lib/atomic_web/live/announcement_live/show.html.heex @@ -12,4 +12,4 @@ <.icon name={:pencil} solid class="mr-3 w-5 h-5 text-zinc-400" /> Edit
-<% end %> +<% end %> \ No newline at end of file From a010415239c74f4b86c2211f6dfc5d0f916714f1 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Wed, 11 Sep 2024 10:55:24 +0100 Subject: [PATCH 06/30] fix: create announcement elems positioning --- .../announcement_live/form_component.html.heex | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/form_component.html.heex b/lib/atomic_web/live/announcement_live/form_component.html.heex index 1bdd285a3..1acf5f04a 100644 --- a/lib/atomic_web/live/announcement_live/form_component.html.heex +++ b/lib/atomic_web/live/announcement_live/form_component.html.heex @@ -1,20 +1,20 @@ -
+
<.form :let={f} for={@changeset} id="announcement-form" phx-target={@myself} phx-change="validate" phx-submit="save" class="space-y-6"> -
-
-
+
+
+
<.field field={f[:title]} type="text" placeholder="Choose a title for the announcement" required class="w-full" /> <.field field={f[:description]} type="textarea" placeholder="Write a description" required class="w-full overflow-auto resize-none h-44 xl:h-64" />
-
- -
- <.live_component module={ImageUploader} id="uploader" uploads={@uploads} target={@myself} /> + +
+ <.live_component module={ImageUploader} id="uploader" uploads={@uploads} target={@myself} /> +
-
+
<.button size={:md} color={:white} icon={:cube} type="submit"><%= gettext("Save Changes") %>
From 88d0b1227e95ba75c1ce16a3ed4704da438c7f1f Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Wed, 11 Sep 2024 11:04:59 +0100 Subject: [PATCH 07/30] fix: padding --- .../live/announcement_live/form_component.html.heex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/form_component.html.heex b/lib/atomic_web/live/announcement_live/form_component.html.heex index 1acf5f04a..af70039fb 100644 --- a/lib/atomic_web/live/announcement_live/form_component.html.heex +++ b/lib/atomic_web/live/announcement_live/form_component.html.heex @@ -8,14 +8,14 @@ <.field field={f[:description]} type="textarea" placeholder="Write a description" required class="w-full overflow-auto resize-none h-44 xl:h-64" />
-
+
<.live_component module={ImageUploader} id="uploader" uploads={@uploads} target={@myself} /> + +
+ <.button size={:md} color={:white} icon={:cube} type="submit"><%= gettext("Save Changes") %> +
- -
- <.button size={:md} color={:white} icon={:cube} type="submit"><%= gettext("Save Changes") %> -
From 1c8defcc9d2e23aae4e9cefe69ca5930e5ef4dfa Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Wed, 11 Sep 2024 12:05:18 +0100 Subject: [PATCH 08/30] feat: completed create announcement page --- lib/atomic_web/live/announcement_live/form_component.html.heex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/atomic_web/live/announcement_live/form_component.html.heex b/lib/atomic_web/live/announcement_live/form_component.html.heex index af70039fb..30fc1bb11 100644 --- a/lib/atomic_web/live/announcement_live/form_component.html.heex +++ b/lib/atomic_web/live/announcement_live/form_component.html.heex @@ -9,7 +9,7 @@
- <.live_component module={ImageUploader} id="uploader" uploads={@uploads} target={@myself} /> + <.live_component module={ImageUploader} id="uploader" uploads={@uploads} target={@myself} class="object-cover" />
<.button size={:md} color={:white} icon={:cube} type="submit"><%= gettext("Save Changes") %> From 57d689d9663dda7955599ba9afbef890e8fc467c Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Wed, 11 Sep 2024 12:15:22 +0100 Subject: [PATCH 09/30] fix: show announcement page padding --- .../live/announcement_live/show.html.heex | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/show.html.heex b/lib/atomic_web/live/announcement_live/show.html.heex index 62fcf6857..c135aa0b8 100644 --- a/lib/atomic_web/live/announcement_live/show.html.heex +++ b/lib/atomic_web/live/announcement_live/show.html.heex @@ -4,12 +4,12 @@ <.announcement announcement={@announcement} />
-
-<%= if @has_permissions? do %> - <.link patch={Routes.announcement_edit_path(@socket, :edit, @announcement.organization, @announcement)} class="px-2 button"> - - -<% end %> \ No newline at end of file + <%= if @has_permissions? do %> + <.link patch={Routes.announcement_edit_path(@socket, :edit, @announcement.organization, @announcement)} class="px-4 button"> + + + <% end %> +
\ No newline at end of file From 380213714bcd031afc6ede541593a0e6a6f46d2f Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Thu, 12 Sep 2024 09:45:58 +0100 Subject: [PATCH 10/30] fix: format --- lib/atomic_web/live/announcement_live/form_component.ex | 5 ++++- lib/atomic_web/live/announcement_live/index.ex | 2 +- lib/atomic_web/live/announcement_live/show.html.heex | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/form_component.ex b/lib/atomic_web/live/announcement_live/form_component.ex index 3cf53370e..a8ee37d5c 100644 --- a/lib/atomic_web/live/announcement_live/form_component.ex +++ b/lib/atomic_web/live/announcement_live/form_component.ex @@ -63,7 +63,10 @@ defmodule AtomicWeb.AnnouncementLive.FormComponent do announcement_params = Map.put(announcement_params, "organization_id", socket.assigns.organization.id) - case Organizations.create_announcement_with_post(announcement_params, &consume_image_data(socket, &1)) do + case Organizations.create_announcement_with_post( + announcement_params, + &consume_image_data(socket, &1) + ) do {:ok, _announcement} -> {:noreply, socket diff --git a/lib/atomic_web/live/announcement_live/index.ex b/lib/atomic_web/live/announcement_live/index.ex index 9c30eedc4..2ce31a781 100644 --- a/lib/atomic_web/live/announcement_live/index.ex +++ b/lib/atomic_web/live/announcement_live/index.ex @@ -1,7 +1,7 @@ defmodule AtomicWeb.AnnouncementLive.Index do use AtomicWeb, :live_view - import AtomicWeb.Components.{Announcement,Button, Empty, Pagination, Tabs} + import AtomicWeb.Components.{Announcement, Button, Empty, Pagination, Tabs} alias Atomic.Accounts alias Atomic.Organizations diff --git a/lib/atomic_web/live/announcement_live/show.html.heex b/lib/atomic_web/live/announcement_live/show.html.heex index c135aa0b8..62a16617a 100644 --- a/lib/atomic_web/live/announcement_live/show.html.heex +++ b/lib/atomic_web/live/announcement_live/show.html.heex @@ -12,4 +12,4 @@
<% end %> -
\ No newline at end of file +
From 0d17920ced2c42f886327cb5c12322308abb69d8 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Tue, 17 Sep 2024 22:29:00 +0100 Subject: [PATCH 11/30] fix: text overflow --- lib/atomic_web/live/announcement_live/index.html.heex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/atomic_web/live/announcement_live/index.html.heex b/lib/atomic_web/live/announcement_live/index.html.heex index 3eb892fe8..e1d64bb39 100644 --- a/lib/atomic_web/live/announcement_live/index.html.heex +++ b/lib/atomic_web/live/announcement_live/index.html.heex @@ -31,7 +31,9 @@ <%= for announcement <- @announcements do %>
  • <.link navigate={Routes.announcement_show_path(@socket, :show, announcement)}> - <.announcement announcement={announcement} /> +
    + <.announcement announcement={announcement} /> +
  • <% end %> From f1800bce76e76cef44c401e0d83fd78440bc4421 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Mon, 23 Sep 2024 17:33:40 +0100 Subject: [PATCH 12/30] fix: conflits --- .../live/announcement_live/form_component.html.heex | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/form_component.html.heex b/lib/atomic_web/live/announcement_live/form_component.html.heex index 761b92563..17f7f731e 100644 --- a/lib/atomic_web/live/announcement_live/form_component.html.heex +++ b/lib/atomic_web/live/announcement_live/form_component.html.heex @@ -7,8 +7,6 @@ <.field field={f[:description]} type="textarea" placeholder="Write a description" required class="w-full overflow-auto resize-none h-44 xl:h-64" />
    - -<<<<<<< jc/improve-announcements
    <.live_component module={ImageUploader} id="uploader" uploads={@uploads} target={@myself} class="object-cover" /> @@ -17,10 +15,6 @@
    -======= -
    - <.button size={:md} color={:white} icon="hero-cube" type="submit"><%= gettext("Save Changes") %> ->>>>>>> develop
    From 6b0f7ec44a1fe45d6298d87218d6de697865eb6c Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Mon, 23 Sep 2024 18:04:04 +0100 Subject: [PATCH 13/30] fix: new icons --- lib/atomic_web/live/announcement_live/form_component.html.heex | 2 +- lib/atomic_web/live/announcement_live/show.html.heex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/form_component.html.heex b/lib/atomic_web/live/announcement_live/form_component.html.heex index 17f7f731e..5f6ef756d 100644 --- a/lib/atomic_web/live/announcement_live/form_component.html.heex +++ b/lib/atomic_web/live/announcement_live/form_component.html.heex @@ -11,7 +11,7 @@ <.live_component module={ImageUploader} id="uploader" uploads={@uploads} target={@myself} class="object-cover" />
    - <.button size={:md} color={:white} icon={:cube} type="submit"><%= gettext("Save Changes") %> + <.button size={:md} color={:white} icon="hero-cube" type="submit"><%= gettext("Save Changes") %>
    diff --git a/lib/atomic_web/live/announcement_live/show.html.heex b/lib/atomic_web/live/announcement_live/show.html.heex index c5fa86aab..413995b59 100644 --- a/lib/atomic_web/live/announcement_live/show.html.heex +++ b/lib/atomic_web/live/announcement_live/show.html.heex @@ -7,7 +7,7 @@ <%= if @has_permissions? do %> <.link patch={Routes.announcement_edit_path(@socket, :edit, @announcement.organization, @announcement)} class="px-4 button"> <% end %> From 678c82dddee6c4e460f7bcdad8114aa95861ee39 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Mon, 23 Sep 2024 23:56:15 +0100 Subject: [PATCH 14/30] fix: fix test --- lib/atomic/organizations.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index 0e63f2407..0f80e856c 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -580,7 +580,10 @@ defmodule Atomic.Organizations do |> Repo.transaction() |> case do {:ok, %{announcement: announcement, post: _post}} -> - after_save.({:ok, announcement}) + case after_save.({:ok, announcement}) do + {:ok, announcement} -> {:ok, announcement} + error -> error + end {:error, _reason, changeset, _actions} -> {:error, changeset} From fac57ec015c19218ba9e7309d04e68b238760a78 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Tue, 24 Sep 2024 00:04:16 +0100 Subject: [PATCH 15/30] fix: test --- lib/atomic/organizations.ex | 5 +---- lib/atomic_web/live/announcement_live/form_component.ex | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index 0f80e856c..414bcb320 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -580,10 +580,7 @@ defmodule Atomic.Organizations do |> Repo.transaction() |> case do {:ok, %{announcement: announcement, post: _post}} -> - case after_save.({:ok, announcement}) do - {:ok, announcement} -> {:ok, announcement} - error -> error - end + after_save.(announcement) {:error, _reason, changeset, _actions} -> {:error, changeset} diff --git a/lib/atomic_web/live/announcement_live/form_component.ex b/lib/atomic_web/live/announcement_live/form_component.ex index a8ee37d5c..feb604a82 100644 --- a/lib/atomic_web/live/announcement_live/form_component.ex +++ b/lib/atomic_web/live/announcement_live/form_component.ex @@ -78,7 +78,7 @@ defmodule AtomicWeb.AnnouncementLive.FormComponent do end end - defp consume_image_data(socket, {:ok, announcement}) do + defp consume_image_data(socket, announcement) do consume_uploaded_entries(socket, :image, fn %{path: path}, entry -> Organizations.update_announcement_image(announcement, %{ "image" => %Plug.Upload{ From 424175aff82051c542f9dc4327df63a075fa0dc2 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Tue, 24 Sep 2024 18:03:08 +0100 Subject: [PATCH 16/30] fix: main page nil announcement bug --- lib/atomic/organizations.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index 414bcb320..b0aa06b3d 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -605,10 +605,11 @@ defmodule Atomic.Organizations do {:error, %Ecto.Changeset{}} """ - def update_announcement(%Announcement{} = announcement, attrs, _after_save \\ &{:ok, &1}) do + def update_announcement(%Announcement{} = announcement, attrs, after_save \\ &{:ok, &1}) do announcement |> Announcement.changeset(attrs) |> Repo.update() + |> after_save(after_save) end @doc """ @@ -624,7 +625,10 @@ defmodule Atomic.Organizations do """ def delete_announcement(%Announcement{} = announcement) do - Repo.delete(announcement) + Ecto.Multi.new() + |> Ecto.Multi.delete(:announcement, announcement) + |> Ecto.Multi.delete(:post, Repo.get!(Post, announcement.post_id)) + |> Repo.transaction() end @doc """ From 040ee69a7814f6e02d4360fd6ab6cc18152ad847 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Tue, 24 Sep 2024 18:32:43 +0100 Subject: [PATCH 17/30] fix: delete announcement test --- lib/atomic/organizations.ex | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index b0aa06b3d..f06d5c0a8 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -629,8 +629,13 @@ defmodule Atomic.Organizations do |> Ecto.Multi.delete(:announcement, announcement) |> Ecto.Multi.delete(:post, Repo.get!(Post, announcement.post_id)) |> Repo.transaction() + |> case do + {:ok, _changes} -> {:ok, announcement} + {:error, _step, reason, _changes} -> {:error, reason} + end end + @doc """ Returns an `%Ecto.Changeset{}` for tracking announcement changes. From 5812fae44e9b406cf69e4b44b3f5c3a419f40316 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Tue, 24 Sep 2024 18:34:43 +0100 Subject: [PATCH 18/30] fix: format --- lib/atomic/organizations.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index f06d5c0a8..bb48a7225 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -635,7 +635,6 @@ defmodule Atomic.Organizations do end end - @doc """ Returns an `%Ecto.Changeset{}` for tracking announcement changes. From a7a468be2b77db9a8796dc7e6c2d5b61848c32ce Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Tue, 24 Sep 2024 23:01:19 +0100 Subject: [PATCH 19/30] feat: created an announcement card component --- .../components/announcement_card.ex | 36 +++++++++++++++++++ .../live/announcement_live/index.ex | 1 + .../live/announcement_live/index.html.heex | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 lib/atomic_web/live/announcement_live/components/announcement_card.ex diff --git a/lib/atomic_web/live/announcement_live/components/announcement_card.ex b/lib/atomic_web/live/announcement_live/components/announcement_card.ex new file mode 100644 index 000000000..1904afebf --- /dev/null +++ b/lib/atomic_web/live/announcement_live/components/announcement_card.ex @@ -0,0 +1,36 @@ +defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do + @moduledoc false + use AtomicWeb, :component + + @assigns [:announcement] + + def announcement_card(assigns) do + ~H""" +
    + <.link navigate={Routes.announcement_show_path(AtomicWeb.Endpoint, :show, @announcement)}> +
    +

    + <%= @announcement.title %> +

    +

    + <%= @announcement.description %> +

    + + <.link navigate={Routes.organization_show_path(AtomicWeb.Endpoint, :show, @announcement.organization.id)} class="flex items-center"> + <.icon name="hero-building_office-solid" class="mr-1.5 h-5 w-5 text-zinc-400" /> + + <%= @announcement.organization.name %> + + + +
    + <%= if @announcement.image do %> +
    + Announcement Image +
    + <% end %> + +
    + """ + end +end diff --git a/lib/atomic_web/live/announcement_live/index.ex b/lib/atomic_web/live/announcement_live/index.ex index 2ce31a781..df5a9ac2d 100644 --- a/lib/atomic_web/live/announcement_live/index.ex +++ b/lib/atomic_web/live/announcement_live/index.ex @@ -2,6 +2,7 @@ defmodule AtomicWeb.AnnouncementLive.Index do use AtomicWeb, :live_view import AtomicWeb.Components.{Announcement, Button, Empty, Pagination, Tabs} + import AtomicWeb.AnnouncementLive.Components.AnnouncementCard alias Atomic.Accounts alias Atomic.Organizations diff --git a/lib/atomic_web/live/announcement_live/index.html.heex b/lib/atomic_web/live/announcement_live/index.html.heex index e1d64bb39..3281c332b 100644 --- a/lib/atomic_web/live/announcement_live/index.html.heex +++ b/lib/atomic_web/live/announcement_live/index.html.heex @@ -32,7 +32,7 @@
  • <.link navigate={Routes.announcement_show_path(@socket, :show, announcement)}>
    - <.announcement announcement={announcement} /> + <.announcement_card announcement={announcement} />
  • From 8735240189b9a5588b700a967b7483bfa16b4447 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Tue, 24 Sep 2024 23:04:44 +0100 Subject: [PATCH 20/30] fix: format --- .../live/announcement_live/components/announcement_card.ex | 4 +--- lib/atomic_web/live/announcement_live/index.ex | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/components/announcement_card.ex b/lib/atomic_web/live/announcement_live/components/announcement_card.ex index 1904afebf..30a32246a 100644 --- a/lib/atomic_web/live/announcement_live/components/announcement_card.ex +++ b/lib/atomic_web/live/announcement_live/components/announcement_card.ex @@ -2,8 +2,6 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do @moduledoc false use AtomicWeb, :component - @assigns [:announcement] - def announcement_card(assigns) do ~H"""
    @@ -25,7 +23,7 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do
    <%= if @announcement.image do %> -
    +
    Announcement Image
    <% end %> diff --git a/lib/atomic_web/live/announcement_live/index.ex b/lib/atomic_web/live/announcement_live/index.ex index df5a9ac2d..3c452f24b 100644 --- a/lib/atomic_web/live/announcement_live/index.ex +++ b/lib/atomic_web/live/announcement_live/index.ex @@ -1,7 +1,7 @@ defmodule AtomicWeb.AnnouncementLive.Index do use AtomicWeb, :live_view - import AtomicWeb.Components.{Announcement, Button, Empty, Pagination, Tabs} + import AtomicWeb.Components.{Button, Empty, Pagination, Tabs} import AtomicWeb.AnnouncementLive.Components.AnnouncementCard alias Atomic.Accounts From 7f1935f7993b1f44215b7130a8f40c88875b940e Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Tue, 24 Sep 2024 23:56:03 +0100 Subject: [PATCH 21/30] fix: icon and removed hover effect --- .../live/announcement_live/components/announcement_card.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/components/announcement_card.ex b/lib/atomic_web/live/announcement_live/components/announcement_card.ex index 30a32246a..28eae2ab8 100644 --- a/lib/atomic_web/live/announcement_live/components/announcement_card.ex +++ b/lib/atomic_web/live/announcement_live/components/announcement_card.ex @@ -4,7 +4,7 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do def announcement_card(assigns) do ~H""" -
    +
    <.link navigate={Routes.announcement_show_path(AtomicWeb.Endpoint, :show, @announcement)}>

    @@ -15,7 +15,7 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do

    <.link navigate={Routes.organization_show_path(AtomicWeb.Endpoint, :show, @announcement.organization.id)} class="flex items-center"> - <.icon name="hero-building_office-solid" class="mr-1.5 h-5 w-5 text-zinc-400" /> + <.icon name="hero-building-office-solid" class="mr-1.5 h-5 w-5 text-zinc-400" /> <%= @announcement.organization.name %> From 8f248e55b94101948ca7e7cb70333c4b292b6a16 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Wed, 25 Sep 2024 22:26:42 +0100 Subject: [PATCH 22/30] refacotr: announcement card --- .../components/announcement_card.ex | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/components/announcement_card.ex b/lib/atomic_web/live/announcement_live/components/announcement_card.ex index 28eae2ab8..56cf818a6 100644 --- a/lib/atomic_web/live/announcement_live/components/announcement_card.ex +++ b/lib/atomic_web/live/announcement_live/components/announcement_card.ex @@ -1,30 +1,37 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do @moduledoc false + + import AtomicWeb.Components.Avatar + use AtomicWeb, :component def announcement_card(assigns) do ~H""" -
    +
    <.link navigate={Routes.announcement_show_path(AtomicWeb.Endpoint, :show, @announcement)}> -
    +
    +
    + <.avatar name={@announcement.organization.name} color={:light_gray} class="!h-10 !w-10" size={:xs} type={:organization} src={Uploaders.Logo.url({@announcement.organization.logo, @announcement.organization}, :original)} /> +
    +
    +

    <%= @announcement.organization.name %>

    +

    + Published on + +

    +
    +
    +

    <%= @announcement.title %>

    -

    +

    <%= @announcement.description %>

    - - <.link navigate={Routes.organization_show_path(AtomicWeb.Endpoint, :show, @announcement.organization.id)} class="flex items-center"> - <.icon name="hero-building-office-solid" class="mr-1.5 h-5 w-5 text-zinc-400" /> - - <%= @announcement.organization.name %> - - -
    <%= if @announcement.image do %> -
    - Announcement Image +
    + Announcement Image
    <% end %> From 3d16dca015d7f351ecceb61fd08474f4f808a8b3 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Thu, 3 Oct 2024 11:44:37 +0100 Subject: [PATCH 23/30] fix: padding --- .../live/announcement_live/components/announcement_card.ex | 6 +++--- lib/atomic_web/live/announcement_live/index.html.heex | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/components/announcement_card.ex b/lib/atomic_web/live/announcement_live/components/announcement_card.ex index 56cf818a6..5f8435e81 100644 --- a/lib/atomic_web/live/announcement_live/components/announcement_card.ex +++ b/lib/atomic_web/live/announcement_live/components/announcement_card.ex @@ -7,9 +7,9 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do def announcement_card(assigns) do ~H""" -
    +
    <.link navigate={Routes.announcement_show_path(AtomicWeb.Endpoint, :show, @announcement)}> -
    +
    <.avatar name={@announcement.organization.name} color={:light_gray} class="!h-10 !w-10" size={:xs} type={:organization} src={Uploaders.Logo.url({@announcement.organization.logo, @announcement.organization}, :original)} />
    @@ -21,7 +21,7 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do

    -
    +

    <%= @announcement.title %>

    diff --git a/lib/atomic_web/live/announcement_live/index.html.heex b/lib/atomic_web/live/announcement_live/index.html.heex index 3281c332b..be10ca098 100644 --- a/lib/atomic_web/live/announcement_live/index.html.heex +++ b/lib/atomic_web/live/announcement_live/index.html.heex @@ -29,7 +29,7 @@
      <%= for announcement <- @announcements do %> -
    • +
    • <.link navigate={Routes.announcement_show_path(@socket, :show, announcement)}>
      <.announcement_card announcement={announcement} /> From 4a36fa317173c4905b037d50529da9a5110f88aa Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Thu, 7 Nov 2024 11:30:28 +0000 Subject: [PATCH 24/30] fix: errors after merge --- .../live/announcement_live/components/announcement_card.ex | 1 + lib/atomic_web/live/announcement_live/index.ex | 1 - lib/atomic_web/live/announcement_live/show.ex | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/atomic_web/live/announcement_live/components/announcement_card.ex b/lib/atomic_web/live/announcement_live/components/announcement_card.ex index 5f8435e81..b7218f6ae 100644 --- a/lib/atomic_web/live/announcement_live/components/announcement_card.ex +++ b/lib/atomic_web/live/announcement_live/components/announcement_card.ex @@ -2,6 +2,7 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do @moduledoc false import AtomicWeb.Components.Avatar + alias AtomicWeb.Router.Helpers, as: Routes use AtomicWeb, :component diff --git a/lib/atomic_web/live/announcement_live/index.ex b/lib/atomic_web/live/announcement_live/index.ex index 3c452f24b..2c26e45bb 100644 --- a/lib/atomic_web/live/announcement_live/index.ex +++ b/lib/atomic_web/live/announcement_live/index.ex @@ -2,7 +2,6 @@ defmodule AtomicWeb.AnnouncementLive.Index do use AtomicWeb, :live_view import AtomicWeb.Components.{Button, Empty, Pagination, Tabs} - import AtomicWeb.AnnouncementLive.Components.AnnouncementCard alias Atomic.Accounts alias Atomic.Organizations diff --git a/lib/atomic_web/live/announcement_live/show.ex b/lib/atomic_web/live/announcement_live/show.ex index 0643e31ec..9814e61c1 100644 --- a/lib/atomic_web/live/announcement_live/show.ex +++ b/lib/atomic_web/live/announcement_live/show.ex @@ -5,6 +5,7 @@ defmodule AtomicWeb.AnnouncementLive.Show do alias Atomic.Accounts alias Atomic.Organizations + alias AtomicWeb.Router.Helpers, as: Routes @impl true def mount(_params, _session, socket) do From a80c0fa3aef8d63d5cc1e1767c2bd90da166378b Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Thu, 7 Nov 2024 12:01:58 +0000 Subject: [PATCH 25/30] refactor: announcements is not part of the admin pages --- lib/atomic_web/config.ex | 14 +++++++------- .../live/announcement_live/edit.html.heex | 2 +- lib/atomic_web/live/announcement_live/index.ex | 5 ++++- .../live/announcement_live/index.html.heex | 6 +++--- .../live/announcement_live/new.html.heex | 2 +- lib/atomic_web/router.ex | 6 ++++++ 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/atomic_web/config.ex b/lib/atomic_web/config.ex index 03f60860a..ef36a0edf 100644 --- a/lib/atomic_web/config.ex +++ b/lib/atomic_web/config.ex @@ -43,6 +43,13 @@ defmodule AtomicWeb.Config do url: ~p"/organizations/#{current_organization}/departments", tabs: [] }, + %{ + key: :announcements, + title: "Announcements", + icon: "hero-newspaper", + url: ~p"/organizations/#{current_organization}/announcements", + tabs: [] + }, %{ key: :partners, title: "Partners", @@ -83,13 +90,6 @@ defmodule AtomicWeb.Config do url: ~p"/activities", tabs: [] }, - %{ - key: :announcements, - title: "Announcements", - icon: "hero-newspaper", - url: ~p"/announcements", - tabs: [] - }, %{ key: :organizations, title: "Organizations", diff --git a/lib/atomic_web/live/announcement_live/edit.html.heex b/lib/atomic_web/live/announcement_live/edit.html.heex index c3db0c4f7..6b36d4a31 100644 --- a/lib/atomic_web/live/announcement_live/edit.html.heex +++ b/lib/atomic_web/live/announcement_live/edit.html.heex @@ -5,6 +5,6 @@
      - <.live_component module={AtomicWeb.AnnouncementLive.FormComponent} id={@announcement.id} organization={@current_organization} title={@page_title} action={@live_action} announcement={@announcement} return_to={~p"/announcements/#{@announcement}"} /> + <.live_component module={AtomicWeb.AnnouncementLive.FormComponent} id={@announcement.id} organization={@current_organization} title={@page_title} action={@live_action} announcement={@announcement} return_to={~p"/organizations/#{@current_organization}/announcements"} />
      diff --git a/lib/atomic_web/live/announcement_live/index.ex b/lib/atomic_web/live/announcement_live/index.ex index 2c26e45bb..bf9dfe35d 100644 --- a/lib/atomic_web/live/announcement_live/index.ex +++ b/lib/atomic_web/live/announcement_live/index.ex @@ -12,12 +12,15 @@ defmodule AtomicWeb.AnnouncementLive.Index do end @impl true - def handle_params(params, _, socket) do + def handle_params(%{"organization_id" => organization_id} = params, _, socket) do + organization = Organizations.get_organization!(organization_id) + {:noreply, socket |> assign(:page_title, gettext("Announcements")) |> assign(:current_page, :announcements) |> assign(:current_tab, current_tab(socket, params)) + |> assign(:organization, organization) |> assign(:params, params) |> assign(:has_permissions?, has_permissions?(socket)) |> assign(list_announcements(socket, params)) diff --git a/lib/atomic_web/live/announcement_live/index.html.heex b/lib/atomic_web/live/announcement_live/index.html.heex index 623e7d4b1..e93a2f356 100644 --- a/lib/atomic_web/live/announcement_live/index.html.heex +++ b/lib/atomic_web/live/announcement_live/index.html.heex @@ -1,7 +1,7 @@ <.page title="Announcements"> <:actions> <%= if not @empty? and @has_permissions? do %> - <.button navigate={~p"/announcements/new"}> + <.button navigate={~p"/organizations/#{@current_organization}/announcements/new"} icon="hero-plus"> <%= gettext("New") %> <% end %> @@ -23,14 +23,14 @@ <%= if @empty? and @has_permissions? do %>
      - <.empty_state url={~p"/announcements/new"} placeholder="announcement" /> + <.empty_state url={~p"/organizations/#{@organization}/announcements/new"} placeholder="announcement" />
      <% else %>
        <%= for announcement <- @announcements do %>
      • - <.link navigate={~p"/announcements/#{announcement}"} class="block hover:bg-zinc-50"> + <.link navigate={~p"/organizations/#{@organization}/announcements/#{announcement}"} class="block hover:bg-zinc-50">

        diff --git a/lib/atomic_web/live/announcement_live/new.html.heex b/lib/atomic_web/live/announcement_live/new.html.heex index bda286c44..a944ab481 100644 --- a/lib/atomic_web/live/announcement_live/new.html.heex +++ b/lib/atomic_web/live/announcement_live/new.html.heex @@ -1,5 +1,5 @@ <.page title={gettext("New Announcement")}>

        - <.live_component module={AtomicWeb.AnnouncementLive.FormComponent} id={:new} organization={@current_organization} title={@page_title} action={@live_action} announcement={@announcement} return_to={~p"/announcements"} /> + <.live_component module={AtomicWeb.AnnouncementLive.FormComponent} id={:new} organization={@current_organization} title={@page_title} action={@live_action} announcement={@announcement} return_to={~p"/organizations/#{@current_organization}/announcements"} />
        diff --git a/lib/atomic_web/router.ex b/lib/atomic_web/router.ex index 9843a8c8d..e7d918729 100644 --- a/lib/atomic_web/router.ex +++ b/lib/atomic_web/router.ex @@ -132,6 +132,12 @@ defmodule AtomicWeb.Router do live "/", PartnerLive.Index, :index live "/:id", PartnerLive.Show, :show end + + scope "/announcements" do + pipe_through :confirm_announcement_association + live "/", AnnouncementLive.Index, :index + live "/:id", AnnouncementLive.Show, :show + end end # Only masters can create organizations From 1af4b7966c1d771ba7920f857ee632c4d0485c24 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Thu, 7 Nov 2024 12:17:09 +0000 Subject: [PATCH 26/30] refactor: finished updating the routes --- .../components/announcement_card.ex | 3 +-- lib/atomic_web/live/announcement_live/index.ex | 1 + .../live/announcement_live/index.html.heex | 13 +------------ .../live/announcement_live/show.html.heex | 7 ------- 4 files changed, 3 insertions(+), 21 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/components/announcement_card.ex b/lib/atomic_web/live/announcement_live/components/announcement_card.ex index b7218f6ae..cbda630b7 100644 --- a/lib/atomic_web/live/announcement_live/components/announcement_card.ex +++ b/lib/atomic_web/live/announcement_live/components/announcement_card.ex @@ -2,14 +2,13 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do @moduledoc false import AtomicWeb.Components.Avatar - alias AtomicWeb.Router.Helpers, as: Routes use AtomicWeb, :component def announcement_card(assigns) do ~H"""
        - <.link navigate={Routes.announcement_show_path(AtomicWeb.Endpoint, :show, @announcement)}> + <.link navigate={~p"/organizations/#{@organization}/announcements/#{@announcement}"} class="block">
        <.avatar name={@announcement.organization.name} color={:light_gray} class="!h-10 !w-10" size={:xs} type={:organization} src={Uploaders.Logo.url({@announcement.organization.logo, @announcement.organization}, :original)} /> diff --git a/lib/atomic_web/live/announcement_live/index.ex b/lib/atomic_web/live/announcement_live/index.ex index bf9dfe35d..2e3e2f71c 100644 --- a/lib/atomic_web/live/announcement_live/index.ex +++ b/lib/atomic_web/live/announcement_live/index.ex @@ -2,6 +2,7 @@ defmodule AtomicWeb.AnnouncementLive.Index do use AtomicWeb, :live_view import AtomicWeb.Components.{Button, Empty, Pagination, Tabs} + import AtomicWeb.AnnouncementLive.Components.AnnouncementCard alias Atomic.Accounts alias Atomic.Organizations diff --git a/lib/atomic_web/live/announcement_live/index.html.heex b/lib/atomic_web/live/announcement_live/index.html.heex index e93a2f356..f9cf97840 100644 --- a/lib/atomic_web/live/announcement_live/index.html.heex +++ b/lib/atomic_web/live/announcement_live/index.html.heex @@ -30,18 +30,7 @@
          <%= for announcement <- @announcements do %>
        • - <.link navigate={~p"/organizations/#{@organization}/announcements/#{announcement}"} class="block hover:bg-zinc-50"> -
          -
          -

          - <%= announcement.title %> -

          -
          -

          - <%= announcement.description %> -

          -
          - + <.announcement_card announcement={announcement} organization={@organization} />
        • <% end %>
        diff --git a/lib/atomic_web/live/announcement_live/show.html.heex b/lib/atomic_web/live/announcement_live/show.html.heex index 57ec1cc16..413995b59 100644 --- a/lib/atomic_web/live/announcement_live/show.html.heex +++ b/lib/atomic_web/live/announcement_live/show.html.heex @@ -12,10 +12,3 @@ <% end %>
        -<%= if @has_permissions? do %> - <.link patch={~p"/organizations/#{@announcement.organization}/announcements/#{@announcement}/edit"} class="px-2 button"> - - -<% end %> From abe715e8dbac6e8675d992824e681d3490497460 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Thu, 7 Nov 2024 15:37:05 +0000 Subject: [PATCH 27/30] feat: announcements page only shows posts by the organization logged in --- lib/atomic/organizations.ex | 4 +-- .../components/announcement_card.ex | 8 ++--- .../live/announcement_live/index.ex | 34 ++----------------- .../live/announcement_live/index.html.heex | 14 +------- 4 files changed, 10 insertions(+), 50 deletions(-) diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index bb48a7225..8dac03ac2 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -503,11 +503,11 @@ defmodule Atomic.Organizations do [%Announcement{}, ...] """ - def list_announcements_by_organization_id(id, opts \\ []) do + def list_announcements_by_organization_id(id, %{} = flop, opts \\ []) when is_list(opts) do Announcement |> where(organization_id: ^id) |> apply_filters(opts) - |> Repo.all() + |> Flop.validate_and_run(flop, for: Announcement) end @doc """ diff --git a/lib/atomic_web/live/announcement_live/components/announcement_card.ex b/lib/atomic_web/live/announcement_live/components/announcement_card.ex index cbda630b7..51a2f07a7 100644 --- a/lib/atomic_web/live/announcement_live/components/announcement_card.ex +++ b/lib/atomic_web/live/announcement_live/components/announcement_card.ex @@ -9,7 +9,7 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do ~H"""
        <.link navigate={~p"/organizations/#{@organization}/announcements/#{@announcement}"} class="block"> -
        +
        <.avatar name={@announcement.organization.name} color={:light_gray} class="!h-10 !w-10" size={:xs} type={:organization} src={Uploaders.Logo.url({@announcement.organization.logo, @announcement.organization}, :original)} />
        @@ -21,7 +21,7 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do

        -
        +

        <%= @announcement.title %>

        @@ -30,8 +30,8 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do

        <%= if @announcement.image do %> -
        - Announcement Image +
        + Announcement Image
        <% end %> diff --git a/lib/atomic_web/live/announcement_live/index.ex b/lib/atomic_web/live/announcement_live/index.ex index 2e3e2f71c..3825d6558 100644 --- a/lib/atomic_web/live/announcement_live/index.ex +++ b/lib/atomic_web/live/announcement_live/index.ex @@ -20,42 +20,17 @@ defmodule AtomicWeb.AnnouncementLive.Index do socket |> assign(:page_title, gettext("Announcements")) |> assign(:current_page, :announcements) - |> assign(:current_tab, current_tab(socket, params)) |> assign(:organization, organization) |> assign(:params, params) |> assign(:has_permissions?, has_permissions?(socket)) - |> assign(list_announcements(socket, params)) + |> assign(list_announcements_by_organization(socket, params, organization_id)) |> then(fn complete_socket -> assign(complete_socket, :empty?, Enum.empty?(complete_socket.assigns.announcements)) end)} end - defp list_announcements(socket, params) do - params = Map.put(params, "page_size", 6) - - case current_tab(socket, params) do - "all" -> list_all_announcements(socket, params) - "following" -> list_following_announcements(socket, params) - end - end - - defp list_all_announcements(_socket, params) do - case Organizations.list_announcements(params, preloads: [:organization]) do - {:ok, {announcements, meta}} -> - %{announcements: announcements, meta: meta} - - {:error, flop} -> - %{announcements: [], meta: flop} - end - end - - defp list_following_announcements(socket, params) do - organizations = - Organizations.list_organizations_followed_by_user(socket.assigns.current_user.id) - - case Organizations.list_organizations_announcements(organizations, params, - preloads: [:organization] - ) do + defp list_announcements_by_organization(_socket, params, organization_id) do + case Organizations.list_announcements_by_organization_id(organization_id, params, preloads: [:organization]) do {:ok, {announcements, meta}} -> %{announcements: announcements, meta: meta} @@ -64,9 +39,6 @@ defmodule AtomicWeb.AnnouncementLive.Index do end end - defp current_tab(_socket, params) when is_map_key(params, "tab"), do: params["tab"] - defp current_tab(_socket, _params), do: "all" - defp has_permissions?(socket) when not socket.assigns.is_authenticated?, do: false defp has_permissions?(socket) do diff --git a/lib/atomic_web/live/announcement_live/index.html.heex b/lib/atomic_web/live/announcement_live/index.html.heex index f9cf97840..f4d8c0041 100644 --- a/lib/atomic_web/live/announcement_live/index.html.heex +++ b/lib/atomic_web/live/announcement_live/index.html.heex @@ -7,19 +7,7 @@ <% end %> - <.tabs class="max-w-5-xl mx-auto px-4 sm:px-6 lg:px-8"> - <.link patch="?tab=all" replace={false}> - <.tab active={@current_tab == "all"}> - <%= gettext("All") %> - - - - <.link patch="?tab=following" replace={false}> - <.tab active={@current_tab == "following"}> - <%= gettext("Following") %> - - - + <.tabs> <%= if @empty? and @has_permissions? do %>
        From 01dfeb08c794dcedebafafe2bcd8b09d4b9da381 Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Thu, 7 Nov 2024 15:39:46 +0000 Subject: [PATCH 28/30] fix: format --- .../live/announcement_live/components/announcement_card.ex | 2 +- lib/atomic_web/live/announcement_live/index.ex | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/atomic_web/live/announcement_live/components/announcement_card.ex b/lib/atomic_web/live/announcement_live/components/announcement_card.ex index 51a2f07a7..118aa4570 100644 --- a/lib/atomic_web/live/announcement_live/components/announcement_card.ex +++ b/lib/atomic_web/live/announcement_live/components/announcement_card.ex @@ -30,7 +30,7 @@ defmodule AtomicWeb.AnnouncementLive.Components.AnnouncementCard do

        <%= if @announcement.image do %> -
        +
        Announcement Image
        <% end %> diff --git a/lib/atomic_web/live/announcement_live/index.ex b/lib/atomic_web/live/announcement_live/index.ex index 3825d6558..207e00ad6 100644 --- a/lib/atomic_web/live/announcement_live/index.ex +++ b/lib/atomic_web/live/announcement_live/index.ex @@ -30,7 +30,9 @@ defmodule AtomicWeb.AnnouncementLive.Index do end defp list_announcements_by_organization(_socket, params, organization_id) do - case Organizations.list_announcements_by_organization_id(organization_id, params, preloads: [:organization]) do + case Organizations.list_announcements_by_organization_id(organization_id, params, + preloads: [:organization] + ) do {:ok, {announcements, meta}} -> %{announcements: announcements, meta: meta} From 66bda3fc2e2b19933408a5571c08d6a990b34abc Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Thu, 7 Nov 2024 15:57:32 +0000 Subject: [PATCH 29/30] fix: function documentation --- lib/atomic/organizations.ex | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index 8dac03ac2..8fafdcf52 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -495,12 +495,15 @@ defmodule Atomic.Organizations do end @doc """ - Returns the list of announcements belonging to an organization. + Returns the list of announcements belonging to an organization, filtered and validated by the given parameters. ## Examples - iex> list_announcements_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") - [%Announcement{}, ...] + iex> list_announcements_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621", %{}) + {:ok, [%Announcement{}, ...]} + + iex> list_announcements_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621", %{}, [some_option: true]) + {:ok, [%Announcement{}, ...]} """ def list_announcements_by_organization_id(id, %{} = flop, opts \\ []) when is_list(opts) do From e8c16b7784c4d370160fcdf0ca3c17357607791c Mon Sep 17 00:00:00 2001 From: jojocoelho Date: Thu, 7 Nov 2024 16:02:19 +0000 Subject: [PATCH 30/30] fix: format --- lib/atomic/organizations.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index 8fafdcf52..e2c58e8ae 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -502,7 +502,9 @@ defmodule Atomic.Organizations do iex> list_announcements_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621", %{}) {:ok, [%Announcement{}, ...]} - iex> list_announcements_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621", %{}, [some_option: true]) + iex> list_announcements_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621", %{}, + ...> some_option: true + ...> ) {:ok, [%Announcement{}, ...]} """