From 9a6bb041b24cbefcb3b15d35e8a44f053d2378b4 Mon Sep 17 00:00:00 2001 From: Pas <74743263+Pasithea0@users.noreply.github.com> Date: Sun, 19 Oct 2025 18:08:00 -0600 Subject: [PATCH] Make custom source effect source select menus --- .../atoms/settings/SourceSelectingView.tsx | 30 +++++++++++++++++-- src/pages/parts/player/SourceSelectPart.tsx | 29 ++++++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/components/player/atoms/settings/SourceSelectingView.tsx b/src/components/player/atoms/settings/SourceSelectingView.tsx index fd1251a0..6b058ee1 100644 --- a/src/components/player/atoms/settings/SourceSelectingView.tsx +++ b/src/components/player/atoms/settings/SourceSelectingView.tsx @@ -11,6 +11,7 @@ import { Menu } from "@/components/player/internals/ContextMenu"; import { SelectableLink } from "@/components/player/internals/ContextMenu/Links"; import { useOverlayRouter } from "@/hooks/useOverlayRouter"; import { usePlayerStore } from "@/stores/player/store"; +import { usePreferencesStore } from "@/stores/preferences"; export interface SourceSelectionViewProps { id: string; @@ -141,12 +142,37 @@ export function SourceSelectionView({ const router = useOverlayRouter(id); const metaType = usePlayerStore((s) => s.meta?.type); const currentSourceId = usePlayerStore((s) => s.sourceId); + const preferredSourceOrder = usePreferencesStore((s) => s.sourceOrder); + const enableSourceOrder = usePreferencesStore((s) => s.enableSourceOrder); + const sources = useMemo(() => { if (!metaType) return []; - return getCachedMetadata() + const allSources = getCachedMetadata() .filter((v) => v.type === "source") .filter((v) => v.mediaTypes?.includes(metaType)); - }, [metaType]); + + if (!enableSourceOrder || preferredSourceOrder.length === 0) { + return allSources; + } + + // Sort sources according to preferred order + const orderedSources = []; + const remainingSources = [...allSources]; + + // Add sources in preferred order + for (const sourceId of preferredSourceOrder) { + const sourceIndex = remainingSources.findIndex((s) => s.id === sourceId); + if (sourceIndex !== -1) { + orderedSources.push(remainingSources[sourceIndex]); + remainingSources.splice(sourceIndex, 1); + } + } + + // Add remaining sources that weren't in the preferred order + orderedSources.push(...remainingSources); + + return orderedSources; + }, [metaType, preferredSourceOrder, enableSourceOrder]); return ( <> diff --git a/src/pages/parts/player/SourceSelectPart.tsx b/src/pages/parts/player/SourceSelectPart.tsx index 49312ed9..cd371b7d 100644 --- a/src/pages/parts/player/SourceSelectPart.tsx +++ b/src/pages/parts/player/SourceSelectPart.tsx @@ -10,6 +10,7 @@ import { } from "@/components/player/hooks/useSourceSelection"; import { Menu } from "@/components/player/internals/ContextMenu"; import { SelectableLink } from "@/components/player/internals/ContextMenu/Links"; +import { usePreferencesStore } from "@/stores/preferences"; // Embed option component function EmbedOption(props: { @@ -126,14 +127,38 @@ export function SourceSelectPart(props: { media: ScrapeMedia }) { null, ); const routerId = "manualSourceSelect"; + const preferredSourceOrder = usePreferencesStore((s) => s.sourceOrder); + const enableSourceOrder = usePreferencesStore((s) => s.enableSourceOrder); const sources = useMemo(() => { const metaType = props.media.type; if (!metaType) return []; - return getCachedMetadata() + const allSources = getCachedMetadata() .filter((v) => v.type === "source") .filter((v) => v.mediaTypes?.includes(metaType)); - }, [props.media.type]); + + if (!enableSourceOrder || preferredSourceOrder.length === 0) { + return allSources; + } + + // Sort sources according to preferred order + const orderedSources = []; + const remainingSources = [...allSources]; + + // Add sources in preferred order + for (const sourceId of preferredSourceOrder) { + const sourceIndex = remainingSources.findIndex((s) => s.id === sourceId); + if (sourceIndex !== -1) { + orderedSources.push(remainingSources[sourceIndex]); + remainingSources.splice(sourceIndex, 1); + } + } + + // Add remaining sources that weren't in the preferred order + orderedSources.push(...remainingSources); + + return orderedSources; + }, [props.media.type, preferredSourceOrder, enableSourceOrder]); if (selectedSourceId) { return (