The MediaCard consolidation in the discovery doc would have needed ~14 props to cover the differentiating bits (wrapping element a vs button, art-shape, art-fallback strategy, click semantics, title align/size, subtitle count). That's a god-prop blob that's harder to reason about than three explicit cards. Narrowed to the actually-drifted bit: the action cluster (LikeButton + Plus + bottom-right menu slot, including the stopPropagation defensive wrappers). One small component covers AlbumCard / ArtistCard / CompactTrackCard so the focus-ring and button-styling drift can't recur. Each card keeps its own data-fetching, art container, and wrapping element since those have load-bearing differences. The consolidation addresses drift, not LOC for its own sake. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,9 +3,9 @@
|
|||||||
import { FALLBACK_COVER } from '$lib/media/covers';
|
import { FALLBACK_COVER } from '$lib/media/covers';
|
||||||
import { api } from '$lib/api/client';
|
import { api } from '$lib/api/client';
|
||||||
import { enqueueTracks, playQueue } from '$lib/player/store.svelte';
|
import { enqueueTracks, playQueue } from '$lib/player/store.svelte';
|
||||||
import { Plus, Play } from 'lucide-svelte';
|
import { Play } from 'lucide-svelte';
|
||||||
import LikeButton from './LikeButton.svelte';
|
|
||||||
import AlbumMenu from './AlbumMenu.svelte';
|
import AlbumMenu from './AlbumMenu.svelte';
|
||||||
|
import CardActionCluster from './CardActionCluster.svelte';
|
||||||
|
|
||||||
let { album }: { album: AlbumRef } = $props();
|
let { album }: { album: AlbumRef } = $props();
|
||||||
|
|
||||||
@@ -58,24 +58,20 @@
|
|||||||
<div class="text-xs text-text-secondary">{album.year}</div>
|
<div class="text-xs text-text-secondary">{album.year}</div>
|
||||||
{/if}
|
{/if}
|
||||||
</a>
|
</a>
|
||||||
<div class="absolute right-2 top-2 z-10 flex gap-1">
|
<CardActionCluster
|
||||||
<LikeButton entityType="album" entityId={album.id} />
|
likeEntityType="album"
|
||||||
<button
|
likeEntityId={album.id}
|
||||||
type="button"
|
onAdd={onAddClick}
|
||||||
aria-label="Add to queue"
|
addLabel="Add to queue"
|
||||||
onclick={onAddClick}
|
>
|
||||||
class="rounded-full bg-surface px-2 py-1 text-sm text-text-secondary hover:text-text-primary focus-visible:ring-2 focus-visible:ring-accent"
|
{#snippet menu()}
|
||||||
>
|
<AlbumMenu
|
||||||
<Plus size={16} strokeWidth={1} />
|
albumId={album.id}
|
||||||
</button>
|
albumTitle={album.title}
|
||||||
</div>
|
artistId={album.artist_id}
|
||||||
<div class="absolute right-2 bottom-2 z-10">
|
artistName={album.artist_name}
|
||||||
<AlbumMenu
|
/>
|
||||||
albumId={album.id}
|
{/snippet}
|
||||||
albumTitle={album.title}
|
</CardActionCluster>
|
||||||
artistId={album.artist_id}
|
|
||||||
artistName={album.artist_name}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
import type { ArtistRef, TrackRef } from '$lib/api/types';
|
import type { ArtistRef, TrackRef } from '$lib/api/types';
|
||||||
import { api } from '$lib/api/client';
|
import { api } from '$lib/api/client';
|
||||||
import { playQueue, enqueueTracks } from '$lib/player/store.svelte';
|
import { playQueue, enqueueTracks } from '$lib/player/store.svelte';
|
||||||
import { Disc3, Play, Plus } from 'lucide-svelte';
|
import { Disc3, Play } from 'lucide-svelte';
|
||||||
import LikeButton from './LikeButton.svelte';
|
|
||||||
import ArtistMenu from './ArtistMenu.svelte';
|
import ArtistMenu from './ArtistMenu.svelte';
|
||||||
|
import CardActionCluster from './CardActionCluster.svelte';
|
||||||
import { listArtistTracks } from '$lib/api/artists';
|
import { listArtistTracks } from '$lib/api/artists';
|
||||||
|
|
||||||
let { artist }: { artist: ArtistRef } = $props();
|
let { artist }: { artist: ArtistRef } = $props();
|
||||||
@@ -71,21 +71,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="mt-2 truncate text-center text-sm font-medium text-text-primary">{artist.name}</div>
|
<div class="mt-2 truncate text-center text-sm font-medium text-text-primary">{artist.name}</div>
|
||||||
</a>
|
</a>
|
||||||
<div class="absolute right-2 top-2 z-10 flex gap-1">
|
<CardActionCluster
|
||||||
<LikeButton entityType="artist" entityId={artist.id} />
|
likeEntityType="artist"
|
||||||
<button
|
likeEntityId={artist.id}
|
||||||
type="button"
|
onAdd={onAddToQueue}
|
||||||
aria-label={`Add ${artist.name} to queue`}
|
addLabel={`Add ${artist.name} to queue`}
|
||||||
onclick={onAddToQueue}
|
addDisabled={queueing}
|
||||||
disabled={queueing}
|
>
|
||||||
class="rounded-full bg-surface px-2 py-1 text-sm text-text-secondary hover:text-text-primary focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-50"
|
{#snippet menu()}
|
||||||
>
|
<ArtistMenu artistId={artist.id} artistName={artist.name} />
|
||||||
<Plus size={16} strokeWidth={1} />
|
{/snippet}
|
||||||
</button>
|
</CardActionCluster>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="absolute right-2 bottom-2 z-10">
|
|
||||||
<ArtistMenu artistId={artist.id} artistName={artist.name} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { Snippet } from 'svelte';
|
||||||
|
import { Plus } from 'lucide-svelte';
|
||||||
|
import LikeButton from './LikeButton.svelte';
|
||||||
|
|
||||||
|
// Shared chrome for AlbumCard / ArtistCard / CompactTrackCard. Owns
|
||||||
|
// the top-right Like + add-to-queue cluster and the bottom-right
|
||||||
|
// menu slot — the bits that were drifting between the three cards
|
||||||
|
// (focus-ring, play-overlay-adjacent positioning, button styling).
|
||||||
|
//
|
||||||
|
// Per-card data fetching + onPlay/onAdd logic stays in the calling
|
||||||
|
// component; the wrapping element (a vs button) and art container
|
||||||
|
// also stay there since their differences are load-bearing.
|
||||||
|
//
|
||||||
|
// stopPropagation is applied to both wrapper divs so clicks on the
|
||||||
|
// action elements never bubble to the parent — works for both
|
||||||
|
// <a>-wrapped cards (AlbumCard/ArtistCard) and <button>-wrapped
|
||||||
|
// ones (CompactTrackCard).
|
||||||
|
|
||||||
|
let {
|
||||||
|
likeEntityType,
|
||||||
|
likeEntityId,
|
||||||
|
onAdd,
|
||||||
|
addLabel,
|
||||||
|
addDisabled = false,
|
||||||
|
menu
|
||||||
|
}: {
|
||||||
|
likeEntityType: 'track' | 'album' | 'artist';
|
||||||
|
likeEntityId: string;
|
||||||
|
onAdd: (e: MouseEvent) => void;
|
||||||
|
addLabel: string;
|
||||||
|
addDisabled?: boolean;
|
||||||
|
menu: Snippet;
|
||||||
|
} = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||||
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||||
|
<div class="absolute right-2 top-2 z-10 flex gap-1" onclick={(e) => e.stopPropagation()}>
|
||||||
|
<LikeButton entityType={likeEntityType} entityId={likeEntityId} />
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={addLabel}
|
||||||
|
onclick={onAdd}
|
||||||
|
disabled={addDisabled}
|
||||||
|
class="rounded-full bg-surface px-2 py-1 text-sm text-text-secondary hover:text-text-primary focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-50"
|
||||||
|
>
|
||||||
|
<Plus size={16} strokeWidth={1} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||||
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||||
|
<div class="absolute right-2 bottom-2 z-10" onclick={(e) => e.stopPropagation()}>
|
||||||
|
{@render menu()}
|
||||||
|
</div>
|
||||||
@@ -2,9 +2,8 @@
|
|||||||
import type { TrackRef } from '$lib/api/types';
|
import type { TrackRef } from '$lib/api/types';
|
||||||
import { playQueue, enqueueTrack } from '$lib/player/store.svelte';
|
import { playQueue, enqueueTrack } from '$lib/player/store.svelte';
|
||||||
import { FALLBACK_COVER, coverUrl } from '$lib/media/covers';
|
import { FALLBACK_COVER, coverUrl } from '$lib/media/covers';
|
||||||
import { Plus } from 'lucide-svelte';
|
|
||||||
import LikeButton from './LikeButton.svelte';
|
|
||||||
import TrackMenu from './TrackMenu.svelte';
|
import TrackMenu from './TrackMenu.svelte';
|
||||||
|
import CardActionCluster from './CardActionCluster.svelte';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
track,
|
track,
|
||||||
@@ -52,24 +51,14 @@
|
|||||||
<div class="mt-2 truncate text-xs font-medium text-text-primary">{track.title}</div>
|
<div class="mt-2 truncate text-xs font-medium text-text-primary">{track.title}</div>
|
||||||
<div class="truncate text-xs text-text-secondary">{track.artist_name}</div>
|
<div class="truncate text-xs text-text-secondary">{track.artist_name}</div>
|
||||||
</button>
|
</button>
|
||||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
<CardActionCluster
|
||||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
likeEntityType="track"
|
||||||
<!-- Overlay div catches clicks on its inner buttons so they don't
|
likeEntityId={track.id}
|
||||||
bubble to the wrapping play-card button. Not interactive on
|
onAdd={onAddToQueue}
|
||||||
its own; the inner LikeButton + queue button carry their own
|
addLabel={`Add ${track.title} to queue`}
|
||||||
keyboard handling. -->
|
>
|
||||||
<div class="absolute right-2 top-2 z-10 flex gap-1" onclick={(e) => e.stopPropagation()}>
|
{#snippet menu()}
|
||||||
<LikeButton entityType="track" entityId={track.id} />
|
<TrackMenu {track} />
|
||||||
<button
|
{/snippet}
|
||||||
type="button"
|
</CardActionCluster>
|
||||||
aria-label={`Add ${track.title} to queue`}
|
|
||||||
onclick={onAddToQueue}
|
|
||||||
class="rounded-full bg-surface px-2 py-1 text-sm text-text-secondary hover:text-text-primary focus-visible:ring-2 focus-visible:ring-accent"
|
|
||||||
>
|
|
||||||
<Plus size={16} strokeWidth={1} />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="absolute right-2 bottom-2 z-10">
|
|
||||||
<TrackMenu {track} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user