From 1ccab387a9d35e26d2dcc50a630d2717211a0e2e Mon Sep 17 00:00:00 2001 From: Vladimir Rubin Date: Mon, 23 Dec 2024 19:45:10 +0200 Subject: [PATCH] fix: wrong day of the week + calendar not updating --- lib/exmr_web/live/exam_live/index.ex | 2 + lib/exmr_web/live/exam_live/index.html.heex | 43 ++++++++++----------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/exmr_web/live/exam_live/index.ex b/lib/exmr_web/live/exam_live/index.ex index 501ec7a..bc05f1f 100644 --- a/lib/exmr_web/live/exam_live/index.ex +++ b/lib/exmr_web/live/exam_live/index.ex @@ -46,6 +46,7 @@ defmodule ExmrWeb.ExamLive.Index do socket = socket |> assign(:exams, [exam | socket.assigns.exams]) + |> assign(events: Enum.group_by(Exams.list_exams(), & &1.date)) {:noreply, socket} end @@ -60,6 +61,7 @@ defmodule ExmrWeb.ExamLive.Index do |> update(:exams, fn exams -> Enum.reject(exams, fn l -> l.id == exam.id end) end) + |> assign(events: Enum.group_by(Exams.list_exams(), & &1.date)) {:noreply, socket} end diff --git a/lib/exmr_web/live/exam_live/index.html.heex b/lib/exmr_web/live/exam_live/index.html.heex index d51dfb1..eca1b7a 100644 --- a/lib/exmr_web/live/exam_live/index.html.heex +++ b/lib/exmr_web/live/exam_live/index.html.heex @@ -79,15 +79,15 @@ -
+
- <%= for day <- ~w(#{gettext("Sun")} #{gettext("Mon")} #{gettext("Tue")} #{gettext("Wed")} #{gettext("Thu")} + <%= for weekday <- ~w(#{gettext("Sun")} #{gettext("Mon")} #{gettext("Tue")} #{gettext("Wed")} #{gettext("Thu")} #{gettext("Fri")} #{gettext("Sat")}) do %> -
{day}
+
{weekday}
<% end %> - <%= for _ <- 1..(Date.day_of_week(@current_month)) do %> + <%= for _ <- 1..(Date.day_of_week(Date.new!(@current_month.year, @current_month.month, 1))) do %>
<% end %> @@ -95,26 +95,25 @@ <%= for day <- 1..Date.days_in_month(@current_month) do %> <% {:ok, date} = Date.new(@current_month.year, @current_month.month, day) %> -
+
{day}
- - + - <%= case Map.get(@events, date) do %> - <% nil -> %> - - <% events -> %> -
    - <%= for event <- events do %> -
  • {event.subject}
  • - <% end %> -
+ <%= if Map.has_key?(@events, date) do %> +
    + <%= for event <- @events[date] do %> +
  • {event.subject}
  • + <% end %> +
<% end %>
<% end %>