diff --git a/lib/atomic_web/components/activity.ex b/lib/atomic_web/components/activity.ex index 6f98b8e6..aed7ba50 100644 --- a/lib/atomic_web/components/activity.ex +++ b/lib/atomic_web/components/activity.ex @@ -33,12 +33,12 @@ defmodule AtomicWeb.Components.Activity do
<%= @activity.description %>
+<%= maybe_slice_string(@activity.description, 300) %>
<%= gettext("Please log in to view this content.") %>
+- Organizations to follow +
+ <%= title(@current_user) %>
+ <%= if length(@schedule.daily) == 0 && length(@schedule.weekly) == 0 do %> +
Today
- <%= entry.title %> -
-- <%= display_time(entry.start) %> - <%= display_time(entry.finish) %> +
+ <%= entry.title %>
++ <%= display_time(entry.start) %> - <%= display_time(entry.finish) %> +
+- <%= entry.description %> + <%= maybe_slice_string(entry.description, 100) %>
+
This week
- <%= entry.title %> -
-- <%= pretty_display_date(entry.start) %> +
+ <%= entry.title %>
++ <%= pretty_display_date(entry.start) %> +
+- <%= entry.description %> + <%= maybe_slice_string(entry.description, 150) %>
+ <%= gettext("Nothing to do in the next week.") %> +
++ <%= gettext("Try enrolling in some activities.") %> +
+ <.button patch={~p"/activities"} color={:white} size={:md} icon="hero-academic-cap"> + <%= gettext("Browse activities") %> + + """ + end + + defp show_empty(assigns) when assigns.tab == "all" do + ~H""" ++ <%= gettext("No activities scheduled to the next week.") %> +
+ """ + end end diff --git a/lib/atomic_web/live/home_live/index.ex b/lib/atomic_web/live/home_live/index.ex index f4ebf82a..c4224b28 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, Dropdown} import AtomicWeb.HomeLive.Components.{FollowSuggestions, Schedule} alias Atomic.Activities @@ -26,8 +26,10 @@ defmodule AtomicWeb.HomeLive.Index do socket |> assign(:current_page, :home) |> assign(:page_title, gettext("Home")) - |> assign(:schedule, fetch_schedule(socket)) + |> assign(:schedule_default, fetch_default_schedule()) + |> assign(:schedule_user, fetch_user_schedule(socket.assigns.current_user)) |> assign(:current_tab, current_tab(socket, params)) + |> assign(:schedule, :default) |> assign(:organizations, list_organizations_to_follow(socket.assigns))} end @@ -71,6 +73,12 @@ 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 @@ -93,18 +101,29 @@ defmodule AtomicWeb.HomeLive.Index do |> assign(:current_tab, "schedule")} end - defp fetch_schedule(socket) when socket.assigns.is_authenticated? do + def handle_event("show-schedule-default", _, socket) do + {:noreply, + socket + |> assign(:schedule, :default)} + end + + def handle_event("show-schedule-user", _, socket) do + {:noreply, + socket + |> assign(:schedule, :user)} + end + + defp fetch_user_schedule(nil), do: %{daily: [], weekly: []} + + defp fetch_user_schedule(user) do {daily, weekly} = - Activities.list_user_activities(socket.assigns.current_user.id, - preloads: [:organization], - order_by: [desc: :start] - ) + Activities.list_user_activities(user.id, preloads: [:organization], order_by: [desc: :start]) |> Enum.reduce({[], []}, &process_activity/2) %{daily: Enum.take(daily, 3), weekly: Enum.take(weekly, 3)} end - defp fetch_schedule(_socket) do + defp fetch_default_schedule do {daily, weekly} = Activities.list_activities(preloads: [:organization], order_by: [desc: :start]) |> Enum.reduce({[], []}, &process_activity/2) @@ -113,7 +132,7 @@ defmodule AtomicWeb.HomeLive.Index do end defp process_activity(activity, {daily_acc, weekly_acc}) do - case within_today_or_this_week(activity.start) do + case within_today_or_this_week(activity.start |> NaiveDateTime.to_date()) do :today -> {[activity | daily_acc], weekly_acc} diff --git a/lib/atomic_web/live/home_live/index.html.heex b/lib/atomic_web/live/home_live/index.html.heex index 57d96496..022fe426 100644 --- a/lib/atomic_web/live/home_live/index.html.heex +++ b/lib/atomic_web/live/home_live/index.html.heex @@ -30,7 +30,7 @@ <.tab id="tab-following" active={@current_tab == "following"} phx-click="load-following" phx-hook="ScrollToTop"> <%= gettext("Following") %> - <%= if length(@schedule.weekly) + length(@schedule.daily) > 0 do %> + <%= if length(@schedule_default.weekly) + length(@schedule_default.daily) > 0 do %> <.tab id="tab-schedule" active={@current_tab == "schedule"} phx-click="load-schedule" phx-hook="ScrollToTop" class="lg:hidden"> <%= gettext("Schedule") %> @@ -39,35 +39,74 @@