Skip to content

Commit

Permalink
notes: fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushmau5 committed May 19, 2024
1 parent 6c7a2fc commit 27f5639
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
11 changes: 11 additions & 0 deletions lib/accumulator/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@ defmodule Accumulator.Helpers do
def get_future_time(seconds \\ 0) do
DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.add(seconds)
end

def days_ago(date_string) do
date = Date.from_iso8601!(date_string)
today = Date.utc_today()

case Date.diff(today, date) do
0 -> "today"
1 -> "yesterday"
x -> "#{x} days ago"
end
end
end
13 changes: 1 addition & 12 deletions lib/accumulator_web/live/notes_live/notes_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule AccumulatorWeb.NotesLive do
|> stream(:notes, [])
|> assign(
page_title: "Notes",
workspaces: Notes.get_public_workspaces(),
workspaces: Notes.get_all_workspaces(),
selected_workspace: nil,
# Note submission form
form: create_empty_form(:note),
Expand Down Expand Up @@ -352,17 +352,6 @@ defmodule AccumulatorWeb.NotesLive do

# Private functions

defp days_ago(date_string) do
date = Date.from_iso8601!(date_string)
today = Date.utc_today()

case Date.diff(today, date) do
0 -> "today"
1 -> "yesterday"
x -> "#{x} days ago"
end
end

defp empty_form() do
%Note{} |> Note.changeset() |> to_form()
end
Expand Down
4 changes: 3 additions & 1 deletion lib/accumulator_web/live/notes_live/notes_live.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
phx-hook="ScrollToBottom"
>
<div :for={{dom_id, [date, notes]} <- @streams.notes} id={dom_id}>
<div class="leading-10 font-bold"><%= date %> (<%= days_ago(date) %>)</div>
<div class="leading-10 font-bold">
<%= 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)
Expand Down

0 comments on commit 27f5639

Please sign in to comment.