mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
refactor(utils): group utils/ files into topic folders (Phase L, part 1) (#689)
111 of 122 top-level src/utils/ files move into 16 topic folders (audio, cache, cover, share, server, playback, playlist, deviceSync, waveform, mix, format, export, changelog, ui, perf, componentHelpers). True singletons with no cluster stay at the utils/ root. Pure file-move: a path-aware codemod rewrote 539 relative-import specifiers across 275 files; no logic touched. The hot-path coverage gate list (.github/frontend-hot-path-files.txt) is updated to the new paths for the 11 gated utils files — a mechanical consequence of the move, not a CI change. tsc is green.
This commit is contained in:
committed by
GitHub
parent
2409a1fec8
commit
7a7a9f5e6b
@@ -0,0 +1,67 @@
|
||||
import { ALL_NAV_ITEMS } from '../../config/navItems';
|
||||
import type { SidebarItemConfig } from '../../store/sidebarStore';
|
||||
|
||||
export type SidebarNavSection = 'library' | 'system';
|
||||
|
||||
export type SidebarNavDropTarget = {
|
||||
idx: number;
|
||||
before: boolean;
|
||||
section: SidebarNavSection;
|
||||
};
|
||||
|
||||
export function getLibraryItemsForReorder(
|
||||
items: SidebarItemConfig[],
|
||||
randomNavMode: 'hub' | 'separate',
|
||||
): SidebarItemConfig[] {
|
||||
return items.filter(cfg => {
|
||||
if (!ALL_NAV_ITEMS[cfg.id] || ALL_NAV_ITEMS[cfg.id].section !== 'library') return false;
|
||||
if (randomNavMode === 'hub' && (cfg.id === 'randomMix' || cfg.id === 'randomAlbums' || cfg.id === 'luckyMix')) return false;
|
||||
if (randomNavMode === 'separate' && cfg.id === 'randomPicker') return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
export function getSystemItemsForReorder(items: SidebarItemConfig[]): SidebarItemConfig[] {
|
||||
return items.filter(cfg => ALL_NAV_ITEMS[cfg.id]?.section === 'system');
|
||||
}
|
||||
|
||||
/** Same entries as in Settings toggles — safe to hide via drag-out. */
|
||||
export function isSidebarNavItemUserHideable(id: string): boolean {
|
||||
return Boolean(ALL_NAV_ITEMS[id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorders one sidebar section (library or system) like the Settings customizer.
|
||||
* Returns a new `items` array, or null if nothing changes.
|
||||
*/
|
||||
export function applySidebarDropReorder(
|
||||
allItems: SidebarItemConfig[],
|
||||
section: SidebarNavSection,
|
||||
fromIdx: number,
|
||||
target: SidebarNavDropTarget | null,
|
||||
randomNavMode: 'hub' | 'separate',
|
||||
): SidebarItemConfig[] | null {
|
||||
if (!target || target.section !== section) return null;
|
||||
|
||||
const sectionItems =
|
||||
section === 'library'
|
||||
? [...getLibraryItemsForReorder(allItems, randomNavMode)]
|
||||
: [...getSystemItemsForReorder(allItems)];
|
||||
|
||||
const insertBefore = target.before ? target.idx : target.idx + 1;
|
||||
if (insertBefore === fromIdx || insertBefore === fromIdx + 1) return null;
|
||||
|
||||
const [moved] = sectionItems.splice(fromIdx, 1);
|
||||
sectionItems.splice(insertBefore > fromIdx ? insertBefore - 1 : insertBefore, 0, moved);
|
||||
|
||||
const visibleIds = new Set(sectionItems.map(c => c.id));
|
||||
const next = [...allItems];
|
||||
const positions = next
|
||||
.map((cfg, i) => ({ cfg, i }))
|
||||
.filter(({ cfg }) => visibleIds.has(cfg.id))
|
||||
.map(({ i }) => i);
|
||||
positions.forEach((pos, i) => {
|
||||
next[pos] = sectionItems[i];
|
||||
});
|
||||
return next;
|
||||
}
|
||||
Reference in New Issue
Block a user