WIP
This commit is contained in:
parent
4d327d751b
commit
0cbf22b025
2 changed files with 7 additions and 9 deletions
|
@ -4,6 +4,7 @@ defmodule ChoreTracker.Chores do
|
|||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias ChoreTracker.Chores.ChoreLog
|
||||
alias ChoreTracker.Repo
|
||||
alias ChoreTracker.Chores.Chore
|
||||
alias ChoreTracker.Accounts.User
|
||||
|
@ -18,7 +19,8 @@ defmodule ChoreTracker.Chores do
|
|||
|
||||
"""
|
||||
def list_chores do
|
||||
from(chore in Chore, preload: [:logs]) |> Repo.all()
|
||||
logs = from(log in ChoreLog, limit: 1)
|
||||
from(chore in Chore, preload: [logs: ^logs]) |> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -16,7 +16,10 @@ defmodule ChoreTrackerWeb.OverviewLive do
|
|||
<:col :let={chore}><span class="text-2xl"><%= chore.emoji %></span></:col>
|
||||
<:col :let={chore} label="Chore"><%= chore.name %></:col>
|
||||
<:col :let={chore} label="Last executed">
|
||||
<%= display_latest_log(chore) %>
|
||||
<%= case chore.logs do
|
||||
[log | _] -> log.inserted_at
|
||||
[] -> "Never"
|
||||
end %>
|
||||
</:col>
|
||||
<:action :let={chore}>
|
||||
<.link
|
||||
|
@ -51,11 +54,4 @@ defmodule ChoreTrackerWeb.OverviewLive do
|
|||
chores = Chores.list_chores()
|
||||
assign(socket, chores: chores)
|
||||
end
|
||||
|
||||
def display_latest_log(%Chores.Chore{} = chore) do
|
||||
case chore.logs |> List.first() do
|
||||
nil -> "Never"
|
||||
log -> log.inserted_at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue