Show last listen at for each collected record
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
defmodule MusicLibraryWeb.CollectionLive.Show do
|
||||
use MusicLibraryWeb, :live_view
|
||||
|
||||
import MusicLibrary.ScrobbleActivity, only: [localize_scrobbled_at: 2]
|
||||
|
||||
import MusicLibraryWeb.RecordComponents,
|
||||
only: [
|
||||
format_label: 1,
|
||||
@@ -19,6 +21,7 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
||||
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(:timezone, resolve_timezone!())
|
||||
|> assign(:can_scrobble?, ScrobbleActivity.can_scrobble?())
|
||||
|> assign(:release_with_tracks, nil)}
|
||||
end
|
||||
@@ -26,6 +29,7 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
||||
@impl true
|
||||
def handle_params(%{"id" => id}, _, socket) do
|
||||
record = Records.get_record!(id)
|
||||
last_listened_track = Records.get_last_listened_track(id)
|
||||
|
||||
socket =
|
||||
if record.selected_release_id do
|
||||
@@ -38,7 +42,8 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
||||
socket
|
||||
|> assign(:current_section, :collection)
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action, record))
|
||||
|> assign(:record, record)}
|
||||
|> assign(:record, record)
|
||||
|> assign(:last_listened_track, last_listened_track)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
@@ -154,4 +159,9 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
||||
|
||||
defp title_segment(:show), do: gettext("Show")
|
||||
defp title_segment(:edit), do: gettext("Edit")
|
||||
|
||||
defp resolve_timezone! do
|
||||
Application.get_env(:music_library, MusicLibraryWeb)
|
||||
|> Keyword.fetch!(:timezone)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -251,6 +251,15 @@
|
||||
{Records.Record.format_as_date(@record.updated_at)}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="py-2 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
|
||||
<dt class="text-xs md:text-sm font-medium leading-6 text-zinc-900 dark:text-zinc-400">
|
||||
{gettext("Last listened at")}
|
||||
</dt>
|
||||
<dd class="mt-1 text-xs md:text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
|
||||
{@last_listened_track &&
|
||||
localize_scrobbled_at(@last_listened_track.scrobbled_at_uts, @timezone)}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user