From 8f73f0039d1c9ef3f9af95826e976e85f08f55cf Mon Sep 17 00:00:00 2001 From: FilipeR13 Date: Fri, 13 Sep 2024 01:35:17 +0100 Subject: [PATCH] fix: page following when its not authenticated --- lib/atomic_web/components/unauthenticated.ex | 25 +++++++++++++++ .../live/activity_live/form_component.ex | 2 +- lib/atomic_web/live/home_live/index.ex | 7 +++- lib/atomic_web/live/home_live/index.html.heex | 32 +++++++++++-------- 4 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 lib/atomic_web/components/unauthenticated.ex diff --git a/lib/atomic_web/components/unauthenticated.ex b/lib/atomic_web/components/unauthenticated.ex new file mode 100644 index 000000000..6b23d29d7 --- /dev/null +++ b/lib/atomic_web/components/unauthenticated.ex @@ -0,0 +1,25 @@ +defmodule AtomicWeb.Components.Unauthenticated do + @moduledoc """ + A component for displaying an unauthenticated state. + """ + use AtomicWeb, :component + + attr :id, :string, default: "unauthenticated-state", required: false + attr :url, :string, default: "users/sign_in", required: false + + def unauthenticated_state(assigns) do + ~H""" +
+ <.icon name={:user_circle} class="mx-auto h-12 w-12 text-zinc-400" /> +

You are not authenticated

+

Please sign in to view this content.

+
+ <.link navigate={Routes.user_session_path(AtomicWeb.Endpoint, :new)} class="inline-flex items-center rounded-md bg-orange-500 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-orange-600 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-orange-500"> + + <.icon name={:arrow_right_end_on_rectangle} solid class="h-5 w-5" /> + +
+
+ """ + end +end diff --git a/lib/atomic_web/live/activity_live/form_component.ex b/lib/atomic_web/live/activity_live/form_component.ex index 4e039b8f0..ec6eb3176 100644 --- a/lib/atomic_web/live/activity_live/form_component.ex +++ b/lib/atomic_web/live/activity_live/form_component.ex @@ -75,7 +75,7 @@ defmodule AtomicWeb.ActivityLive.FormComponent do consume_uploaded_entries(socket, :image, fn %{path: path}, entry -> Activities.update_activity_image(activity, %{ "image" => %Plug.Upload{ - content_type: entry.content_type, + content_type: entry.client_type, filename: entry.client_name, path: path } diff --git a/lib/atomic_web/live/home_live/index.ex b/lib/atomic_web/live/home_live/index.ex index f4ebf82a5..3bac0ca29 100644 --- a/lib/atomic_web/live/home_live/index.ex +++ b/lib/atomic_web/live/home_live/index.ex @@ -2,7 +2,7 @@ defmodule AtomicWeb.HomeLive.Index do @moduledoc false use AtomicWeb, :live_view - import AtomicWeb.Components.{Activity, Announcement, Tabs} + import AtomicWeb.Components.{Activity, Announcement, Tabs, Unauthenticated} import AtomicWeb.HomeLive.Components.{FollowSuggestions, Schedule} alias Atomic.Activities @@ -71,6 +71,11 @@ defmodule AtomicWeb.HomeLive.Index do def handle_event("load-following", _, socket) when socket.assigns.current_tab == "following", do: {:noreply, socket} + def handle_event("load-following", _, socket) when socket.assigns.is_authenticated? == false, + do: {:noreply, + socket + |> assign(:current_tab, "following")} + def handle_event("load-following", _, socket) do current_user = socket.assigns.current_user diff --git a/lib/atomic_web/live/home_live/index.html.heex b/lib/atomic_web/live/home_live/index.html.heex index aba4aed0b..cbb388df0 100644 --- a/lib/atomic_web/live/home_live/index.html.heex +++ b/lib/atomic_web/live/home_live/index.html.heex @@ -39,19 +39,25 @@ <%= if @current_tab != "schedule" do %> - + <%= if @is_authenticated? == false && @current_tab == "following" do %> +
+ <.unauthenticated_state /> +
+ <% else %> + + <% end %> <% else %> <.schedule schedule={@schedule} /> <% end %>