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) => {
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 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 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 rootCount = rootFiles.length;

View file

@ -30,14 +30,14 @@ export default function App() {
const interval = setInterval(async () => {
try {
const s = await fetchSounds(query);
const s = await fetchSounds(query, activeFolder);
setSounds(s.items);
setTotal(s.total);
setFolders(s.folders);
} catch {}
}, 10000);
return () => clearInterval(interval);
}, []);
}, [activeFolder]);
const filtered = useMemo(() => {
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> {
const url = new URL(`${API_BASE}/sounds`, window.location.origin);
if (q) url.searchParams.set('q', q);
if (folderKey) url.searchParams.set('folder', folderKey);
const res = await fetch(url.toString());
if (!res.ok) throw new Error('Fehler beim Laden der Sounds');
return res.json();