Skip to content

Commit

Permalink
Default a new item's due date to today (#44)
Browse files Browse the repository at this point in the history
* Default a new item's due date to today

* Default to UTC when the user hasn't set the timezone setting

* Run 'mix format'
  • Loading branch information
nskins authored Sep 27, 2023
1 parent d314513 commit a2d5b62
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/todo_web/live/item_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,20 @@ defmodule TodoWeb.ItemLive.Index do
end

defp apply_action(socket, :new, _params) do
# Default to UTC if the user hasn't set the timezone setting.
timezone =
case socket.assigns.current_user.timezone do
nil -> "UTC"
tz -> tz
end

# Default the new item's due date to today.
today = DateTime.to_date(Timex.now(timezone))
item = %Item{due_date: today}

socket
|> assign(:page_title, "New Item")
|> assign(:item, %Item{})
|> assign(:item, item)
end

defp apply_action(socket, :index, _params) do
Expand Down

0 comments on commit a2d5b62

Please sign in to comment.