Skip to content

Commit

Permalink
notes: show day of the week along with dates
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushmau5 committed May 24, 2024
1 parent 360c539 commit 3af6b65
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/accumulator/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ defmodule Accumulator.Helpers do
|> NaiveDateTime.add(1, :day)
|> DateTime.from_naive!("Etc/UTC")
end

def day_of_week_string(date_string) do
day = Date.from_iso8601!(date_string) |> Date.day_of_week()
index = day - 1

["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|> Enum.at(index)
end
end
6 changes: 4 additions & 2 deletions lib/accumulator_web/live/notes_live/notes_live.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@
>
<div :for={{dom_id, [date, notes]} <- @streams.notes} id={dom_id}>
<div class="leading-10 font-bold">
<%= date %> (<%= Accumulator.Helpers.days_ago(date) %>)
<%= Accumulator.Helpers.day_of_week_string(date) %> <%= date %> (<%= Accumulator.Helpers.days_ago(
date
) %>)
</div>
<div :for={note <- notes} class="my-1 bg-[#3d3d3d] p-2 rounded-md" id={"note-#{note.id}"}>
<article :if={note.text} class="note-text break-words">
Expand All @@ -111,7 +113,7 @@
</article>
<div class="flex mt-2 justify-between">
<div class="text-xs opacity-40">
<.local_time id={"note-#{note.id}-date"} date={note.updated_at} />
<.local_time id={"note-#{note.id}-date"} date={note.inserted_at} />
</div>
<div class="flex items-center gap-2 ">
<button phx-click="delete" phx-value-id={note.id} class="hover:opacity-80">
Expand Down
6 changes: 4 additions & 2 deletions lib/accumulator_web/live/notes_live/notes_public_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ defmodule AccumulatorWeb.NotesPublicLive do
>
<div :for={{dom_id, [date, notes]} <- @streams.notes} id={dom_id}>
<div class="leading-10 font-bold">
<%= date %> (<%= Accumulator.Helpers.days_ago(date) %>)
<%= Accumulator.Helpers.day_of_week_string(date) %> <%= date %> (<%= Accumulator.Helpers.days_ago(
date
) %>)
</div>
<div :for={note <- notes} class="my-1 bg-[#3d3d3d] p-2 rounded-md" id={"note-#{note.id}"}>
<article :if={note.text} class="note-text break-words">
<%= Earmark.as_html!(note.text, escape: false, compact_output: false)
|> Phoenix.HTML.raw() %>
</article>
<div class="text-xs opacity-40 mt-2">
<.local_time id={"note-#{note.id}-date"} date={note.updated_at} />
<.local_time id={"note-#{note.id}-date"} date={note.inserted_at} />
</div>
</div>
</div>
Expand Down

0 comments on commit 3af6b65

Please sign in to comment.