Render a minimal artist page
This commit is contained in:
@@ -3,3 +3,11 @@
|
||||
@import "tailwindcss/utilities";
|
||||
|
||||
/* This file is for your main application CSS */
|
||||
|
||||
/* The bio html comes directly from the Last.fm api,
|
||||
* so there's no way to inject Tailwind classes in the <a> elements.
|
||||
* To work around that, we set a class to the bio container snd style its children.
|
||||
*/
|
||||
.bio a {
|
||||
@apply font-semibold text-zinc-700 hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200;
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
defmodule LastFm.TrackTest do
|
||||
defmodule LastFm.ArtistTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
@api_response_path Path.expand("../support/fixtures/artist.getinfo.json", __DIR__)
|
||||
|
||||
@@ -171,9 +171,9 @@ defmodule MusicLibrary.RecordsTest do
|
||||
describe "get_artist/1" do
|
||||
test "it returns records with essential data" do
|
||||
record = record_fixture()
|
||||
expected = record.artists |> hd()
|
||||
[expected] = record.artists
|
||||
|
||||
artist = Records.get_artist(expected.musicbrainz_id)
|
||||
artist = Records.get_artist!(expected.musicbrainz_id)
|
||||
|
||||
assert expected == artist
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user