fix(ui): ensure only one track menu open globally
cx
This commit is contained in:
1 parent
945d0f4ca5
commit
5162315d41
2 files changed
+8
-4
No files matched your search
@@ -20,12 +20,11 @@
|
||||
import { shouldHidePlaylistFeatures } from '$lib/utils/offlineHelpers';
|
||||
import {
|
||||
getActiveTrackMenuId,
|
||||
allocateTrackMenuId,
|
||||
setActiveTrackMenuId,
|
||||
subscribeActiveTrackMenuId
|
||||
} from '$lib/stores/activeTrackMenu';
|
||||
|
||||
let trackMenuIdCounter = 1;
|
||||
|
||||
interface Props {
|
||||
onPlayNow?: () => void;
|
||||
onPlayTrackOnly?: () => void;
|
||||
@@ -66,7 +65,7 @@
|
||||
onRemoveDownload
|
||||
}: Props = $props();
|
||||
|
||||
const menuId = trackMenuIdCounter++;
|
||||
const menuId = allocateTrackMenuId();
|
||||
|
||||
let isOpen = $state(false);
|
||||
let shareOpen = $state(false);
|
||||
|
||||
@@ -2,6 +2,12 @@ type Listener = (menuId: number | null) => void;
|
||||
|
||||
let activeMenuId: number | null = null;
|
||||
const listeners = new Set<Listener>();
|
||||
let nextMenuId = 1;
|
||||
|
||||
export function allocateTrackMenuId(): number {
|
||||
// Monotonic id to ensure only one TrackMenu instance matches the active id at a time.
|
||||
return nextMenuId++;
|
||||
}
|
||||
|
||||
export function getActiveTrackMenuId(): number | null {
|
||||
return activeMenuId;
|
||||
@@ -20,4 +26,3 @@ export function subscribeActiveTrackMenuId(listener: Listener): () => void {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user