Files
mystuff_frontend/src/api.ts
Lars Behrends 432416cfc5 Use Zustand store; modularize API & routes
Introduce a centralized Zustand store and refactor app state out of App.tsx into src/store/appStore.ts. Modularize API surface by moving media/cast/settings/converters/types into src/lib/api/* and re-exporting from src/api.ts for backward compatibility. Replace inline route helpers with dedicated route components (MediaDetailRoute, CastDetailRoute, CategoryBrowseRoute) and wire CATEGORY_PATHS/PATH_TO_CATEGORY constants. Update AddMediaView UI (icons, layout) and adjust settings/category handling to use DEFAULT_SETTINGS and the store. Add zustand to package.json/package-lock.json and include a new React SKILL.md. Overall changes improve state management, API organization, and route/component separation for better maintainability and code-splitting.
2026-04-16 14:53:46 +02:00

50 lines
1.5 KiB
TypeScript

// Re-export all API functions for backward compatibility
export * from './lib/api/mediaApi';
export * from './lib/api/castApi';
export * from './lib/api/settingsApi';
export * from './lib/api/converters';
export * from './lib/api/types';
// Legacy functions for compatibility
export async function fetchAllTags(): Promise<string[]> {
try {
const { fetchAllMedia } = await import('./lib/api/mediaApi');
const media = await fetchAllMedia(1, 1000);
const tagSet = new Set<string>();
media.forEach(item => {
item.tags?.forEach(tag => tagSet.add(tag));
item.genres?.forEach(genre => tagSet.add(genre));
});
return Array.from(tagSet).sort();
} catch (error) {
console.error('Error fetching all tags:', error);
return [];
}
}
export async function fetchMediaByTag(tag: string) {
try {
const { fetchAllMedia } = await import('./lib/api/mediaApi');
const media = await fetchAllMedia(1, 1000);
return media.filter(item =>
item.tags?.some(t => t.toLowerCase().includes(tag.toLowerCase())) ||
item.genres?.some(g => g.toLowerCase().includes(tag.toLowerCase()))
);
} catch (error) {
console.error('Error fetching media by tag:', error);
return [];
}
}
export async function fetchMediaFromApi(apiUrl?: string) {
const { fetchAllMedia } = await import('./lib/api/mediaApi');
return fetchAllMedia();
}
export async function fetchMediaFromLocalJson() {
const { fetchAllMedia } = await import('./lib/api/mediaApi');
return fetchAllMedia();
}