mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
9058abd340
Track is the app's normalized song model and QueueItemRef its thin queue identity -- consumed app-wide (queue, cover, context menus, sharing, lucky-mix, library browse), not a playback-internal detail. They lived in features/playback/store/playerStoreTypes, forcing ~115 core/feature files to reach into the playback feature for the central media type. Move the two interfaces to lib/media/trackTypes; playerStoreTypes keeps PlayerState and now imports them from lib. 115 importers repointed (mixed 'PlayerState, Track' lines split so PlayerState stays). Pure type move (erased at runtime). tsc 0, lint 0.
35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import React, { useLayoutEffect } from 'react';
|
|
import { registerQueueListScrollTopReader, consumePendingQueueListScrollTop } from '@/features/playback/store/queueUndo';
|
|
import type { QueueItemRef, Track } from '@/lib/media/trackTypes';
|
|
|
|
interface Args {
|
|
queue: QueueItemRef[];
|
|
queueIndex: number;
|
|
currentTrack: Track | null;
|
|
queueListRef: React.RefObject<HTMLDivElement | null>;
|
|
suppressNextAutoScrollRef: React.MutableRefObject<boolean>;
|
|
}
|
|
|
|
/** Queue scroll-position bridge for undo: publishes the list's scrollTop to the
|
|
* undo store and restores any pending scrollTop snapshot (set when an undo
|
|
* restores a prior queue state). The "scroll the next track into view" path
|
|
* lives in `QueueList` now that the list is virtualized (scrollToIndex). */
|
|
export function useQueueAutoScroll({
|
|
queue, queueIndex, currentTrack, queueListRef, suppressNextAutoScrollRef,
|
|
}: Args) {
|
|
useLayoutEffect(() => {
|
|
registerQueueListScrollTopReader(() => queueListRef.current?.scrollTop);
|
|
return () => registerQueueListScrollTopReader(null);
|
|
}, [queueListRef]);
|
|
|
|
useLayoutEffect(() => {
|
|
const top = consumePendingQueueListScrollTop();
|
|
if (top === undefined) return;
|
|
const el = queueListRef.current;
|
|
if (!el) return;
|
|
suppressNextAutoScrollRef.current = true;
|
|
el.scrollTop = top;
|
|
el.dispatchEvent(new Event('scroll', { bubbles: false }));
|
|
}, [queue, queueIndex, currentTrack?.id, queueListRef, suppressNextAutoScrollRef]);
|
|
}
|