Render a minimal artist page
This commit is contained in:
@@ -90,14 +90,14 @@ defmodule MusicLibrary.Records do
|
||||
|
||||
def get_record!(id), do: Repo.get!(Record, id)
|
||||
|
||||
def get_artist(musicbrainz_id) do
|
||||
def get_artist!(musicbrainz_id) do
|
||||
q =
|
||||
from ar in ArtistRecord,
|
||||
where: ar.musicbrainz_id == ^musicbrainz_id,
|
||||
limit: 1,
|
||||
select: ar.artist
|
||||
|
||||
Repo.one(q)
|
||||
Repo.one!(q)
|
||||
end
|
||||
|
||||
def get_artist_records(musicbrainz_id) do
|
||||
@@ -110,6 +110,10 @@ defmodule MusicLibrary.Records do
|
||||
Repo.all(q)
|
||||
end
|
||||
|
||||
def get_artist_info(musicbrainz_id) do
|
||||
last_fm().get_artist_info(musicbrainz_id, last_fm_api_key())
|
||||
end
|
||||
|
||||
def get_cover(id) do
|
||||
q =
|
||||
from r in Record,
|
||||
@@ -186,10 +190,6 @@ defmodule MusicLibrary.Records do
|
||||
end
|
||||
end
|
||||
|
||||
def get_artist(musicbrainz_id) do
|
||||
last_fm().get_artist_info(musicbrainz_id, last_fm_api_key())
|
||||
end
|
||||
|
||||
defp build_record_attrs(release_group, attrs) do
|
||||
release_group
|
||||
|> Record.attrs_from_release_group()
|
||||
@@ -226,6 +226,6 @@ defmodule MusicLibrary.Records do
|
||||
|
||||
defp last_fm_api_key do
|
||||
Application.get_env(:music_library, LastFm)
|
||||
|> Keyword.fetch!(:api_key)
|
||||
|> Keyword.fetch!(:api_key)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,12 +10,14 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
|
||||
|
||||
@impl true
|
||||
def handle_params(%{"musicbrainz_id" => musicbrainz_id}, _, socket) do
|
||||
{:ok, artist} = Records.get_artist(musicbrainz_id)
|
||||
artist = Records.get_artist!(musicbrainz_id)
|
||||
{:ok, artist_info} = Records.get_artist_info(musicbrainz_id)
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:nav_section, :artists)
|
||||
|> assign(:artist, artist)
|
||||
|> assign(:artist_info, artist_info)
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action, artist))}
|
||||
end
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<h1 class="mt-1 flex font-semibold text-base sm:text-lg leading-5 text-zinc-700 dark:text-zinc-300 text-wrap">
|
||||
<%= @artist.name %>
|
||||
</h1>
|
||||
<p class="mt-2 text-sm leading-5 text-zinc-500 dark:text-zinc-400">
|
||||
<%= raw(@artist.bio) || gettext("Biography not available") %>
|
||||
<p class="bio mt-2 text-sm leading-5 text-zinc-500 dark:text-zinc-400">
|
||||
<%= (@artist_info.bio || gettext("Biography not available")) |> raw() %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user