fix(folders): API-Filter per folder + UI ruft Sounds je aktivem Tab ab; 'Alle' zeigt weiterhin alle

This commit is contained in:
vibe-bot 2025-08-08 02:14:46 +02:00
parent f9bec8b5a1
commit 1f0911c0f7
3 changed files with 9 additions and 3 deletions

View file

@ -190,6 +190,7 @@ app.get('/api/health', (_req: Request, res: Response) => {
app.get('/api/sounds', (req: Request, res: Response) => { app.get('/api/sounds', (req: Request, res: Response) => {
const q = String(req.query.q ?? '').toLowerCase(); const q = String(req.query.q ?? '').toLowerCase();
const folderFilter = typeof req.query.folder === 'string' ? (req.query.folder as string) : '__all__';
const rootEntries = fs.readdirSync(SOUNDS_DIR, { withFileTypes: true }); const rootEntries = fs.readdirSync(SOUNDS_DIR, { withFileTypes: true });
const rootFiles = rootEntries const rootFiles = rootEntries
@ -217,7 +218,11 @@ app.get('/api/sounds', (req: Request, res: Response) => {
} }
const allItems = [...rootFiles, ...folderItems].sort((a, b) => a.name.localeCompare(b.name)); const allItems = [...rootFiles, ...folderItems].sort((a, b) => a.name.localeCompare(b.name));
const filteredItems = allItems.filter((s) => (q ? s.name.toLowerCase().includes(q) : true)); let itemsByFolder = allItems;
if (folderFilter !== '__all__') {
itemsByFolder = allItems.filter((it) => (folderFilter === '' ? it.folder === '' : it.folder === folderFilter));
}
const filteredItems = itemsByFolder.filter((s) => (q ? s.name.toLowerCase().includes(q) : true));
const total = allItems.length; const total = allItems.length;
const rootCount = rootFiles.length; const rootCount = rootFiles.length;

View file

@ -30,14 +30,14 @@ export default function App() {
const interval = setInterval(async () => { const interval = setInterval(async () => {
try { try {
const s = await fetchSounds(query); const s = await fetchSounds(query, activeFolder);
setSounds(s.items); setSounds(s.items);
setTotal(s.total); setTotal(s.total);
setFolders(s.folders); setFolders(s.folders);
} catch {} } catch {}
}, 10000); }, 10000);
return () => clearInterval(interval); return () => clearInterval(interval);
}, []); }, [activeFolder]);
const filtered = useMemo(() => { const filtered = useMemo(() => {
const q = query.trim().toLowerCase(); const q = query.trim().toLowerCase();

View file

@ -5,6 +5,7 @@ const API_BASE = import.meta.env.VITE_API_BASE_URL || '/api';
export async function fetchSounds(q?: string, folderKey?: string): Promise<SoundsResponse> { export async function fetchSounds(q?: string, folderKey?: string): Promise<SoundsResponse> {
const url = new URL(`${API_BASE}/sounds`, window.location.origin); const url = new URL(`${API_BASE}/sounds`, window.location.origin);
if (q) url.searchParams.set('q', q); if (q) url.searchParams.set('q', q);
if (folderKey) url.searchParams.set('folder', folderKey);
const res = await fetch(url.toString()); const res = await fetch(url.toString());
if (!res.ok) throw new Error('Fehler beim Laden der Sounds'); if (!res.ok) throw new Error('Fehler beim Laden der Sounds');
return res.json(); return res.json();