Skip to content

Commit fc708e9

Browse files
committed
Make developer calendar look better
1 parent 015dc7a commit fc708e9

File tree

3 files changed

+83
-17
lines changed

3 files changed

+83
-17
lines changed

lib/components_guide_web/components/calendar_component.ex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ defmodule ComponentsGuideWeb.CalendarComponent do
2020
day: day,
2121
day_offset: day_offset
2222
})
23+
|> Map.put_new(:extra, fn _ -> "" end)
2324

2425
~H"""
25-
<h2><%= Calendar.strftime(@date_range.first, "%B %Y") %></h2>
26+
<h2 class="text-center"><%= Calendar.strftime(@date_range.first, "%B %Y") %></h2>
2627
<table class="text-center">
27-
<thead>
28+
<thead class="border-0">
2829
<tr>
2930
<th abbr="Monday">Mon</th>
3031
<th abbr="Tuesday">Tue</th>
@@ -37,13 +38,14 @@ defmodule ComponentsGuideWeb.CalendarComponent do
3738
</thead>
3839
<tbody>
3940
<%= for week_n <- 1..max_week do %>
40-
<tr>
41+
<tr class="min-h-16">
4142
<%= for day_n <- 1..7 do %>
4243
<% day = day_n + day_offset + ((week_n - 1) * 7) %>
4344
<%= if day in @date_range.first.day..@date_range.last.day do %>
4445
<% current = day == @day %>
45-
<td aria-current={if current, do: "date", else: "false"} class={if current, do: "bg-red-900", else: "bg-black"}>
46-
<%= day %>
46+
<td aria-current={if current, do: "date", else: "false"} class={if current, do: "bg-green-900 text-green-100", else: "bg-black"}>
47+
<div class="text-sm"><%= day %></div>
48+
<%= @extra.(Date.new!(year, month, day)) %>
4749
</td>
4850
<% else %>
4951
<td role="presentation" class=""></td>

lib/components_guide_web/controllers/calendar_controller.ex

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ defmodule ComponentsGuideWeb.CalendarController do
2222
}
2323

2424
react = %{
25-
react18: %{release: {2022, 3, 29}}
25+
react18: %{release: {2022, 3, 29}},
26+
react_query4: %{release: {2022, 7, 18}},
2627
}
2728

2829
jest = %{
@@ -90,6 +91,7 @@ defmodule ComponentsGuideWeb.CalendarController do
9091
deno1_23: "https://deno.com/blog/v1.23",
9192
deno1_24: "https://deno.com/blog/v1.24",
9293
react18: "https://reactjs.org/blog/2022/03/29/react-v18.html",
94+
react_query4: "https://tanstack.com/blog/announcing-tanstack-query-v4",
9395
firefox99: "https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/99",
9496
firefox100: "https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/100",
9597
firefox101: "https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/101",
@@ -102,14 +104,44 @@ defmodule ComponentsGuideWeb.CalendarController do
102104
jest28: "https://jestjs.io/blog/2022/04/25/jest-28"
103105
}
104106

107+
dates_to_items =
108+
for group <- groups do
109+
for {id, %{release: yymmdd}} <- group do
110+
{yymmdd, id}
111+
end
112+
end
113+
|> List.flatten()
114+
|> Enum.group_by(fn {k, _} -> k end, fn {_, v} -> v end)
115+
|> Map.new()
116+
117+
IO.inspect(dates_to_items)
118+
105119
today = Date.utc_today()
106120

121+
calendar_extra = fn date ->
122+
yymmdd = Date.to_erl(date)
123+
124+
ids = Map.get(dates_to_items, yymmdd, [])
125+
ComponentsGuideWeb.CalendarView.icon_links(ids, links)
126+
127+
# case Map.get(dates_to_items, yymmdd) do
128+
# nil ->
129+
# ""
130+
131+
# ids ->
132+
# for id <- ids do
133+
# ComponentsGuideWeb.CalendarView.icon_link(id)
134+
# end
135+
# end
136+
end
137+
107138
assigns = [
108139
page_title:
109140
"Calendar of when important tools are released, become LTS, and reach end-of-life",
110141
today: today,
111142
current_week: today |> Date.to_erl() |> iso_week_number(),
112-
list: create_list(groups, links)
143+
list: create_list(groups, links),
144+
calendar_extra: calendar_extra
113145
]
114146

115147
render(conn, "index.html", assigns)
@@ -188,6 +220,31 @@ defmodule ComponentsGuideWeb.CalendarView do
188220
end
189221
end
190222

223+
def icon_link(id, link) do
224+
assigns = %{
225+
what: pretty_name(id),
226+
href: link || "#",
227+
icon: pretty_icon(id)
228+
}
229+
230+
~H"""
231+
<a href={@href}>
232+
<span class="text-3xl not-prose"><%= @icon %></span>
233+
<%= @what %>
234+
</a>
235+
"""
236+
end
237+
238+
def icon_links(ids, links) do
239+
assigns = %{ids: ids}
240+
241+
~H"""
242+
<%= for id <- @ids do %>
243+
<%= ComponentsGuideWeb.CalendarView.icon_link(id, Map.get(links, id)) %>
244+
<% end %>
245+
"""
246+
end
247+
191248
defp week_diff(date) do
192249
today = Date.utc_today()
193250
{current_year, current_week} = :calendar.iso_week_number(Date.to_erl(today))
@@ -212,6 +269,7 @@ defmodule ComponentsGuideWeb.CalendarView do
212269
<<"postgres" <> version>> -> "Postgres #{pretty_version(version)}"
213270
<<"swift" <> version>> -> "Swift #{pretty_version(version)}"
214271
<<"go" <> version>> -> "Go #{pretty_version(version)}"
272+
<<"react_query" <> version>> -> "React Query #{pretty_version(version)}"
215273
<<"react" <> version>> -> "React #{pretty_version(version)}"
216274
<<"jest" <> version>> -> "Jest #{pretty_version(version)}"
217275
<<"aws_lambda_nodejs" <> version>> -> "AWS Lambda Node.js #{pretty_version(version)}"
@@ -250,6 +308,9 @@ defmodule ComponentsGuideWeb.CalendarView do
250308
<<"go" <> _>> ->
251309
"https://cdn.jsdelivr.net/npm/simple-icons@v6/icons/go.svg"
252310

311+
<<"react_query" <> _>> ->
312+
"https://cdn.jsdelivr.net/npm/simple-icons@v7/icons/reactquery.svg"
313+
253314
<<"react" <> _>> ->
254315
"https://cdn.jsdelivr.net/npm/simple-icons@v6/icons/react.svg"
255316

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1+
<div class="prose md:prose-xl prose-invert max-w-6xl mx-auto pt-8 px-3">
2+
<h1 class="text-center">Developer Calendar</h1>
3+
<CalendarComponent.calendar_grid date={@today} extra={@calendar_extra} />
4+
</div>
5+
16
<div class="prose md:prose-xl prose-invert max-w-2xl mx-auto pt-8 pb-16 px-3">
2-
<h1>Developer Calendar</h1>
3-
<form id="filter-calendar" class="flex flex-wrap gap-6 -mt-8 mb-8 select-none">
4-
<label><input type="checkbox" name="end_of_life" checked class="rounded text-sky-500"> End of life</label>
5-
<label><input type="checkbox" name="released" checked class="rounded text-sky-500"> Released</label>
6-
<label><input type="checkbox" name="lts_starts" checked class="rounded text-sky-500"> LTS</label>
7-
</form>
87
<article>
8+
<h2>All releases</h2>
9+
<form id="filter-calendar" class="flex flex-wrap gap-6 -mt-8 mb-8 select-none">
10+
<label><input type="checkbox" name="end_of_life" checked class="rounded text-sky-500"> End of life</label>
11+
<label><input type="checkbox" name="released" checked class="rounded text-sky-500"> Released</label>
12+
<label><input type="checkbox" name="lts_starts" checked class="rounded text-sky-500"> LTS</label>
13+
</form>
914
<%= for item <- @list do %>
1015
<%= present_item(item) %>
1116
<% end %>
1217
</article>
13-
<CalendarComponent.calendar_grid date={@today} />
1418
</div>
1519

16-
<div class="prose prose-invert max-w-2xl mx-auto pt-8 pb-16 px-3">
17-
<hr>
20+
<section class="prose prose-invert max-w-2xl mx-auto pt-8 pb-16 px-3">
1821
<p><%= "Why number of weeks? Since most teams work in weekly or fortnightly sprints, I figure it’s helpful to see what will land in the next sprint or so." %></p>
1922
<p>Sources:</p>
2023
<ul>
@@ -26,7 +29,7 @@
2629
<li><a href="https://endoflife.date/postgresql">Postgres on endoflife.date</a></li>
2730
<li><a href="https://simpleicons.org">Simple Icons</a></li>
2831
</ul>
29-
</div>
32+
</section>
3033

3134
<script type="module">
3235
const form = document.getElementById("filter-calendar");

0 commit comments

Comments
 (0)