release / go (push) Failing after 1m10s
release / web (push) Failing after 10s
release / android (push) Failing after 1m2s
release / govulncheck (push) Successful in 17s
release / integration (push) Successful in 2m31s
release / Build signed APK (push) Failing after 1m43s
release / Build + push container image (push) Skipped
@tanstack/svelte-query 6 is built on runes: - createQuery and createInfiniteQuery take their options as a function and return a reactive object that components read as query.data. - createMutation takes its options the same way. What this commit changes: - Every query creator in src/lib/api now takes its arguments as getters and reads them inside the options, so a query follows the values it depends on. Before, each component rebuilt it in a $derived. - Constant arguments are passed as getters too, so the rule has no exceptions. - Components call a creator once at init: const query = createArtistQuery(() => id). The $derived(create…) and $store pairs are gone. - A query that loads only on demand (a chosen genre or year, the Handled view) has an enabled getter. The page keeps its `cond ? q : null` alias, because a switched-off query reports isPending and the page expects null when nothing is chosen. - Tests: the query mocks return plain objects. liveQuery (test-utils/liveQuery.svelte.ts) gives a test a result it can change mid-test. Argument checks call the getter the page passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
176 lines
4.8 KiB
Svelte
176 lines
4.8 KiB
Svelte
<script lang="ts">
|
|
import {
|
|
ListVideo,
|
|
ListMusic,
|
|
Heart,
|
|
HeartOff,
|
|
ListPlus,
|
|
Radio,
|
|
Disc3,
|
|
User,
|
|
EyeOff,
|
|
Eye
|
|
} from '@lucide/svelte';
|
|
import { goto } from '$app/navigation';
|
|
import { useQueryClient } from '@tanstack/svelte-query';
|
|
import FlagPopover from './FlagPopover.svelte';
|
|
import AddToPlaylistMenu from './AddToPlaylistMenu.svelte';
|
|
import KebabMenu from './KebabMenu.svelte';
|
|
import TrackMenuItem from './TrackMenuItem.svelte';
|
|
import TrackMenuDivider from './TrackMenuDivider.svelte';
|
|
import { createLikedIdsQuery, likeEntity, unlikeEntity } from '#lib/api/likes.js';
|
|
import { createMyQuarantineQuery, unflagTrack } from '#lib/api/quarantine.js';
|
|
import { qk } from '#lib/api/queries.js';
|
|
import { playNext, enqueueTrack, playRadio } from '#lib/player/store.svelte.js';
|
|
import type { TrackRef } from '#lib/api/types.js';
|
|
|
|
let {
|
|
track,
|
|
direction = 'down',
|
|
hideQueueActions = false
|
|
}: {
|
|
track: TrackRef;
|
|
/** Whether the dropdown opens above the trigger ('up') or below ('down').
|
|
Pass 'up' when used near the bottom of the viewport (e.g. PlayerBar). */
|
|
direction?: 'up' | 'down';
|
|
/** Hide "Play next" / "Add to queue". Set true on the PlayerBar where
|
|
the menu's track IS the currently-playing one — those actions have
|
|
no meaningful semantics for the track you're already listening to. */
|
|
hideQueueActions?: boolean;
|
|
} = $props();
|
|
|
|
let menuOpen = $state(false);
|
|
let flagOpen = $state(false);
|
|
let addOpen = $state(false);
|
|
|
|
const queryClient = useQueryClient();
|
|
|
|
const likedQ = createLikedIdsQuery();
|
|
const liked = $derived.by(() => {
|
|
const data = likedQ.data;
|
|
if (!data) return false;
|
|
return data.track_ids.includes(track.id);
|
|
});
|
|
|
|
const hiddenQ = createMyQuarantineQuery();
|
|
const hidden = $derived.by(() => {
|
|
const rows = hiddenQ.data;
|
|
if (!rows) return false;
|
|
return rows.some((r) => r.track_id === track.id);
|
|
});
|
|
|
|
function closeAll() {
|
|
menuOpen = false;
|
|
flagOpen = false;
|
|
addOpen = false;
|
|
}
|
|
|
|
function onPlayNext() {
|
|
playNext(track);
|
|
closeAll();
|
|
}
|
|
|
|
function onAddToQueue() {
|
|
enqueueTrack(track);
|
|
closeAll();
|
|
}
|
|
|
|
function onStartRadio() {
|
|
playRadio(track.id);
|
|
closeAll();
|
|
}
|
|
|
|
async function onToggleLike() {
|
|
closeAll();
|
|
if (liked) {
|
|
await unlikeEntity(queryClient, 'track', track.id);
|
|
} else {
|
|
await likeEntity(queryClient, 'track', track.id);
|
|
}
|
|
}
|
|
|
|
async function onToggleHide() {
|
|
if (hidden) {
|
|
// Unhide: simple — unflag, then refresh the quarantine list.
|
|
await unflagTrack(track.id);
|
|
await queryClient.invalidateQueries({ queryKey: qk.myQuarantine() });
|
|
closeAll();
|
|
} else {
|
|
// Hide: needs a reason. Reuse FlagPopover.
|
|
menuOpen = false;
|
|
flagOpen = true;
|
|
}
|
|
}
|
|
|
|
function onGoToAlbum() {
|
|
closeAll();
|
|
goto(`/albums/${track.album_id}`);
|
|
}
|
|
|
|
function onGoToArtist() {
|
|
closeAll();
|
|
goto(`/artists/${track.artist_id}`);
|
|
}
|
|
|
|
</script>
|
|
|
|
<KebabMenu
|
|
label={`Track actions for ${track.title}`}
|
|
bind:open={menuOpen}
|
|
{direction}
|
|
popoverOpen={flagOpen || addOpen}
|
|
onclose={(why) => {
|
|
addOpen = false;
|
|
if (why === 'escape') flagOpen = false;
|
|
}}
|
|
>
|
|
<!-- Item set + order mirror Android's canonical TrackActionsSheet so
|
|
the kebab reads the same on both clients: queue group → like /
|
|
add-to-playlist / start-radio group → navigation group → hide.
|
|
"Start radio" is shown even under hideQueueActions (reseeding a
|
|
station from the current track is meaningful where play-next /
|
|
add-to-queue are not). No single-click destructive action lives
|
|
here — track removal is intentionally kept out of the kebab. -->
|
|
{#if !hideQueueActions}
|
|
<TrackMenuItem icon={ListVideo} label="Play next" onclick={onPlayNext} />
|
|
<TrackMenuItem icon={ListMusic} label="Add to queue" onclick={onAddToQueue} />
|
|
|
|
<TrackMenuDivider />
|
|
{/if}
|
|
|
|
<TrackMenuItem
|
|
icon={liked ? HeartOff : Heart}
|
|
label={liked ? 'Unlike' : 'Like'}
|
|
onclick={onToggleLike}
|
|
/>
|
|
<TrackMenuItem
|
|
icon={ListPlus}
|
|
label="Add to playlist…"
|
|
onclick={() => { addOpen = true; menuOpen = false; }}
|
|
/>
|
|
<TrackMenuItem icon={Radio} label="Start radio" onclick={onStartRadio} />
|
|
|
|
<TrackMenuDivider />
|
|
|
|
<TrackMenuItem icon={Disc3} label="Go to album" onclick={onGoToAlbum} />
|
|
<TrackMenuItem icon={User} label="Go to artist" onclick={onGoToArtist} />
|
|
|
|
<TrackMenuDivider />
|
|
|
|
<TrackMenuItem
|
|
icon={hidden ? Eye : EyeOff}
|
|
label={hidden ? 'Unhide' : 'Hide'}
|
|
onclick={onToggleHide}
|
|
/>
|
|
|
|
{#snippet after()}
|
|
{#if flagOpen}
|
|
<FlagPopover {track} {direction} onClose={closeAll} />
|
|
{/if}
|
|
|
|
{#if addOpen}
|
|
<AddToPlaylistMenu tracks={[track]} onClose={() => (addOpen = false)} />
|
|
{/if}
|
|
{/snippet}
|
|
</KebabMenu>
|