fix: wrong day of the week + calendar not updating
This commit is contained in:
parent
92715e9a97
commit
1ccab387a9
2 changed files with 23 additions and 22 deletions
|
@ -46,6 +46,7 @@ defmodule ExmrWeb.ExamLive.Index do
|
||||||
socket =
|
socket =
|
||||||
socket
|
socket
|
||||||
|> assign(:exams, [exam | socket.assigns.exams])
|
|> assign(:exams, [exam | socket.assigns.exams])
|
||||||
|
|> assign(events: Enum.group_by(Exams.list_exams(), & &1.date))
|
||||||
|
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
end
|
end
|
||||||
|
@ -60,6 +61,7 @@ defmodule ExmrWeb.ExamLive.Index do
|
||||||
|> update(:exams, fn exams ->
|
|> update(:exams, fn exams ->
|
||||||
Enum.reject(exams, fn l -> l.id == exam.id end)
|
Enum.reject(exams, fn l -> l.id == exam.id end)
|
||||||
end)
|
end)
|
||||||
|
|> assign(events: Enum.group_by(Exams.list_exams(), & &1.date))
|
||||||
|
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
end
|
end
|
||||||
|
|
|
@ -79,15 +79,15 @@
|
||||||
<!-- </div> -->
|
<!-- </div> -->
|
||||||
|
|
||||||
<!-- Calendar -->
|
<!-- Calendar -->
|
||||||
<div class="grid grid-cols-7 gap-1">
|
<div class="grid grid-cols-7 gap-1" id="calendar-container" phx-update="replace">
|
||||||
<!-- Weekdays -->
|
<!-- Weekdays -->
|
||||||
<%= 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 %>
|
#{gettext("Fri")} #{gettext("Sat")}) do %>
|
||||||
<div class="font-bold text-center">{day}</div>
|
<div class="font-bold text-center">{weekday}</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<!-- Empty spaces for previous month -->
|
<!-- Empty spaces for previous month -->
|
||||||
<%= 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 %>
|
||||||
<div></div>
|
<div></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
@ -95,24 +95,23 @@
|
||||||
<%= for day <- 1..Date.days_in_month(@current_month) do %>
|
<%= for day <- 1..Date.days_in_month(@current_month) do %>
|
||||||
<% {:ok, date} = Date.new(@current_month.year, @current_month.month, day) %>
|
<% {:ok, date} = Date.new(@current_month.year, @current_month.month, day) %>
|
||||||
|
|
||||||
<div class={[
|
<div
|
||||||
|
id={"day-#{Date.to_string(date)}"}
|
||||||
|
class={[
|
||||||
"border rounded p-0.5 md:p-2 lg:p-3 w-full h-12 md:h-20 hover:scale-125 transition-transform ease-in-out duration-100",
|
"border rounded p-0.5 md:p-2 lg:p-3 w-full h-12 md:h-20 hover:scale-125 transition-transform ease-in-out duration-100",
|
||||||
@current_month == date &&
|
@current_month == date &&
|
||||||
"bg-zinc-200 dark:bg-zinc-800 border-green-500 dark:border-green-300",
|
"bg-zinc-200 dark:bg-zinc-800 border-green-500 dark:border-green-300",
|
||||||
@current_month != date &&
|
@current_month != date &&
|
||||||
"bg-white dark:bg-zinc-950 dark:border-zinc-400 "
|
"bg-white dark:bg-zinc-950 dark:border-zinc-400 "
|
||||||
]}>
|
]}
|
||||||
|
>
|
||||||
<div class="text-xs md:text-sm lg:text-base font-bold">{day}</div>
|
<div class="text-xs md:text-sm lg:text-base font-bold">{day}</div>
|
||||||
|
|
||||||
<!-- Render events for the current day -->
|
<!-- Render events for the current day -->
|
||||||
|
|
||||||
<%= case Map.get(@events, date) do %>
|
<%= if Map.has_key?(@events, date) do %>
|
||||||
<% nil -> %>
|
<ul class="text-xs">
|
||||||
<!-- No events for this day -->
|
<%= for event <- @events[date] do %>
|
||||||
<% events -> %>
|
<li id={"event-#{event.id}"}>{event.subject}</li>
|
||||||
<ul class="mt-2 text-xs">
|
|
||||||
<%= for event <- events do %>
|
|
||||||
<li>{event.subject}</li>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Reference in a new issue