import { useEffect, useMemo } from 'react'; import { ArrowUpRight, Clapperboard, LayoutGrid, ShoppingBag, } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import { YinianPageHeader, YinianPageShell, YinianPanel, } from '@/components/yinian/ui'; import { cn } from '@/lib/utils'; import { useAppCenterStore } from '@/stores/app-center'; import type { AppCenterItem } from '@/types/app-center'; const APP_ICONS = { Clapperboard, LayoutGrid, ShoppingBag, }; function getAppIcon(icon: string) { return APP_ICONS[icon as keyof typeof APP_ICONS] ?? LayoutGrid; } export function AppCenter() { const { t } = useTranslation('appCenter'); const navigate = useNavigate(); const init = useAppCenterStore((state) => state.init); const items = useAppCenterStore((state) => state.items); const selectedTagKey = useAppCenterStore((state) => state.selectedTagKey); const selectTag = useAppCenterStore((state) => state.selectTag); useEffect(() => { init(); }, [init]); const categoryCounts = useMemo(() => { const counts = new Map(); for (const item of items) { counts.set(item.categoryKey, (counts.get(item.categoryKey) ?? 0) + 1); } return [...counts.entries()]; }, [items]); const filteredItems = useMemo(() => ( selectedTagKey === 'all' ? items : items.filter((item) => item.tagKeys.includes(selectedTagKey)) ), [items, selectedTagKey]); const openItem = (item: AppCenterItem) => { if (item.type === 'external' && item.url) { void window.electron.openExternal(item.url); return; } if ((item.type === 'native' || item.type === 'webview') && item.route) { navigate(item.route); return; } if (item.type === 'webview' && item.url) { void window.electron.openExternal(item.url); } }; return (

{t('title')}

{t('subtitle')}

{categoryCounts.map(([categoryKey, count]) => { const tagKey = categoryKey.replace('categories.', 'tags.'); return ( ); })}
{filteredItems.length === 0 ? (
{t('empty')}
) : (
{filteredItems.map((item) => { const Icon = getAppIcon(item.icon); return ( ); })}
)}
); } export default AppCenter;