Review timer functions
- Dominant language
- Elixir
- Stars
- 98
- Forks
- 2
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 4
Description
I've noticed a few things that I want to update or have a detailed looked at to make sure I didn't miss something:
```elixir
{:ok, _timer} =
Timer.start(%{
item_id: item.id,
person_id: person_id,
start: NaiveDateTime.utc_now()
})
```
- [x] Remove the `person_id` value as the schema doesn't have it:
```elixir
schema "timers" do
field :item_id, :id
field :start, :naive_datetime
field :stop, :naive_datetime
timestamps()
end
```
- [ ] Make the `stop` function consistent with the `start`, ie pass the stop value as parameter:
```elixir
{:ok, _timer} = Timer.stop(%{id: timer_id})
```
- [ ] Combine start/stop function to `update` function
- [ ] Review how toggle stop the timer. This mean that when a `done` item returns to `active` status we also stop the timer again?
```elixir
def handle_event("toggle", data, socket) do
# Toggle the status of the item between 3 (:active) and 4 (:done)
status = if Map.has_key?(data, "value"), do: 4, else: 3
# need to restrict getting items to the people who own or have rights to access them!
item = Item.get_item!(Map.get(data, "id"))
Item.update_item(item, %{status: status})
Timer.stop_timer_for_item_id(item.id)
AppWeb.Endpoint.broadcast(@topic, "update", :toggle)
{:noreply, socket}
end
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.