Skip to content

Commit f5a11d6

Browse files
committed
Refactor calendar to make current date option
1 parent 2a5c16c commit f5a11d6

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/components_guide_web/components/calendar_component.ex

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@ defmodule ComponentsGuideWeb.CalendarComponent do
22
use ComponentsGuideWeb, :component
33

44
def calendar_grid(assigns) do
5-
%{year: year, month: month, day: day} = today = assigns[:date]
6-
start_date = Date.beginning_of_month(today)
7-
end_date = Date.end_of_month(today)
5+
%{year: year, month: month} = assigns
6+
7+
day =
8+
case assigns[:current_date] do
9+
nil ->
10+
nil
11+
12+
%{day: day} ->
13+
day
14+
end
15+
16+
# %{year: year, month: month, day: day} = today = assigns[:date]
17+
date = Date.new!(year, month, 1)
18+
start_date = Date.beginning_of_month(date)
19+
end_date = Date.end_of_month(date)
820
date_range = Date.range(start_date, end_date)
921

1022
day_inset = Date.day_of_week(start_date)

lib/components_guide_web/templates/calendar/index.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="prose md:prose-xl prose-invert max-w-6xl mx-auto pt-8 px-3">
22
<h1 class="text-center">Developer Calendar</h1>
3-
<CalendarComponent.calendar_grid date={@today} extra={@calendar_extra} />
3+
<CalendarComponent.calendar_grid year={@today.year} month={@today.month} current_date={@today} extra={@calendar_extra} />
44
</div>
55

66
<div class="prose md:prose-xl prose-invert max-w-2xl mx-auto pt-8 pb-16 px-3">

0 commit comments

Comments
 (0)