Convert stats page to a live view

This commit is contained in:
Claudio Ortolina
2024-10-29 16:32:34 +00:00
parent 804727082c
commit 7d574c7fd9
6 changed files with 38 additions and 46 deletions
@@ -1,7 +0,0 @@
defmodule MusicLibraryWeb.StatsHTML do
use MusicLibraryWeb, :html
alias MusicLibrary.Records.Record
embed_templates "stats_html/*"
end
@@ -1,9 +1,10 @@
defmodule MusicLibraryWeb.StatsController do
use MusicLibraryWeb, :controller
defmodule MusicLibraryWeb.StatsLive.Index do
use MusicLibraryWeb, :live_view
alias MusicLibrary.{Records, Wishlist}
alias Records.Record
def index(conn, _params) do
def mount(_params, _session, socket) do
collection_count_by_format =
Records.count_records_by_format()
|> Enum.sort_by(fn {_format, count} -> count end, :desc)
@@ -19,15 +20,16 @@ defmodule MusicLibraryWeb.StatsController do
latest_record = Records.get_latest_record!()
conn
|> assign(:page_title, gettext("Stats"))
|> render(:index,
collection_count_by_format: collection_count_by_format,
collection_count_by_type: collection_count_by_type,
collection_count: collection_count,
wishlist_count: wishlist_count,
latest_record: latest_record,
nav_section: :stats
)
{:ok,
socket
|> assign(
page_title: gettext("Stats"),
collection_count_by_format: collection_count_by_format,
collection_count_by_type: collection_count_by_type,
collection_count: collection_count,
wishlist_count: wishlist_count,
latest_record: latest_record,
nav_section: :stats
)}
end
end
+2 -1
View File
@@ -29,7 +29,8 @@ defmodule MusicLibraryWeb.Router do
pipe_through :require_login
get "/covers/:record_id", CoverController, :show
get "/", StatsController, :index
live "/", StatsLive.Index, :index
live "/records", RecordLive.Index, :index
live "/records/import", RecordLive.Index, :import