Render a minimal artist page
This commit is contained in:
@@ -3,3 +3,11 @@
|
|||||||
@import "tailwindcss/utilities";
|
@import "tailwindcss/utilities";
|
||||||
|
|
||||||
/* This file is for your main application CSS */
|
/* 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_record!(id), do: Repo.get!(Record, id)
|
||||||
|
|
||||||
def get_artist(musicbrainz_id) do
|
def get_artist!(musicbrainz_id) do
|
||||||
q =
|
q =
|
||||||
from ar in ArtistRecord,
|
from ar in ArtistRecord,
|
||||||
where: ar.musicbrainz_id == ^musicbrainz_id,
|
where: ar.musicbrainz_id == ^musicbrainz_id,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
select: ar.artist
|
select: ar.artist
|
||||||
|
|
||||||
Repo.one(q)
|
Repo.one!(q)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_artist_records(musicbrainz_id) do
|
def get_artist_records(musicbrainz_id) do
|
||||||
@@ -110,6 +110,10 @@ defmodule MusicLibrary.Records do
|
|||||||
Repo.all(q)
|
Repo.all(q)
|
||||||
end
|
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
|
def get_cover(id) do
|
||||||
q =
|
q =
|
||||||
from r in Record,
|
from r in Record,
|
||||||
@@ -186,10 +190,6 @@ defmodule MusicLibrary.Records do
|
|||||||
end
|
end
|
||||||
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
|
defp build_record_attrs(release_group, attrs) do
|
||||||
release_group
|
release_group
|
||||||
|> Record.attrs_from_release_group()
|
|> Record.attrs_from_release_group()
|
||||||
@@ -226,6 +226,6 @@ defmodule MusicLibrary.Records do
|
|||||||
|
|
||||||
defp last_fm_api_key do
|
defp last_fm_api_key do
|
||||||
Application.get_env(:music_library, LastFm)
|
Application.get_env(:music_library, LastFm)
|
||||||
|> Keyword.fetch!(:api_key)
|
|> Keyword.fetch!(:api_key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_params(%{"musicbrainz_id" => musicbrainz_id}, _, socket) do
|
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,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|> assign(:nav_section, :artists)
|
|> assign(:nav_section, :artists)
|
||||||
|> assign(:artist, artist)
|
|> assign(:artist, artist)
|
||||||
|
|> assign(:artist_info, artist_info)
|
||||||
|> assign(:page_title, page_title(socket.assigns.live_action, artist))}
|
|> assign(:page_title, page_title(socket.assigns.live_action, artist))}
|
||||||
end
|
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">
|
<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 %>
|
<%= @artist.name %>
|
||||||
</h1>
|
</h1>
|
||||||
<p class="mt-2 text-sm leading-5 text-zinc-500 dark:text-zinc-400">
|
<p class="bio mt-2 text-sm leading-5 text-zinc-500 dark:text-zinc-400">
|
||||||
<%= raw(@artist.bio) || gettext("Biography not available") %>
|
<%= (@artist_info.bio || gettext("Biography not available")) |> raw() %>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
defmodule LastFm.TrackTest do
|
defmodule LastFm.ArtistTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
@api_response_path Path.expand("../support/fixtures/artist.getinfo.json", __DIR__)
|
@api_response_path Path.expand("../support/fixtures/artist.getinfo.json", __DIR__)
|
||||||
|
|||||||
@@ -171,9 +171,9 @@ defmodule MusicLibrary.RecordsTest do
|
|||||||
describe "get_artist/1" do
|
describe "get_artist/1" do
|
||||||
test "it returns records with essential data" do
|
test "it returns records with essential data" do
|
||||||
record = record_fixture()
|
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
|
assert expected == artist
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user