mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
- Settings → 行为设置: two new toggles (保存/加载播放清单, 单曲直接播放不清空队列) that round-trip savedQueuesEnabled / playKeepsQueue and keep the nav gate in sync. - New "已存队列" page (/saved-queues): save the current queue (with a 共享 option), load (replace) / append / delete saved queues; renders a "feature disabled" state on 403 so it degrades gracefully when the flag is off. - Nav entry gated on the savedQueuesEnabled store flag (hidden for guests). - useSavedQueues API composable + a pure, unit-tested list/ownership helper. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
28 lines
875 B
TypeScript
28 lines
875 B
TypeScript
// Pure, framework-free helpers for the Saved Queues feature (#119). Kept
|
|
// separate from the API composable so the list/ownership logic is unit-testable
|
|
// without a DOM or axios.
|
|
|
|
export interface SavedQueueMeta {
|
|
id: number;
|
|
ownerId: string;
|
|
name: string;
|
|
songCount: number;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
/** Must match SHARED_QUEUE_OWNER in src/data/database.ts. */
|
|
export const SHARED_OWNER = '__shared__';
|
|
|
|
/** Whether a saved queue lives in the shared bucket (vs. private to a user). */
|
|
export function isShared(q: Pick<SavedQueueMeta, 'ownerId'>): boolean {
|
|
return q.ownerId === SHARED_OWNER;
|
|
}
|
|
|
|
/** Newest-updated first; stable for equal timestamps. */
|
|
export function sortQueues<T extends { updatedAt: string }>(qs: T[]): T[] {
|
|
return [...qs].sort((a, b) =>
|
|
a.updatedAt < b.updatedAt ? 1 : a.updatedAt > b.updatedAt ? -1 : 0,
|
|
);
|
|
}
|