import { useState } from 'react'; import { Eye, EyeOff, LifeBuoy, Palette, Settings2, Sparkles } from 'lucide-react'; import { activateAdminThemeInput, previewAdminThemeInput, type AdminTheme, type AdminThemesMeta, useActivateAdminTheme, useAdminThemes, usePreviewAdminTheme, useStopAdminThemePreview, } from '@/api/admin/themes/queries'; import { httpErrorToHuman } from '@/api/http'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; import { LinkButton } from '@/components/elements/Button'; import Icon from '@/components/elements/Icon'; import ListToolbar from '@/components/elements/ListToolbar'; import NamedIcon from '@/components/elements/NamedIcon'; import { NewButton } from '@/components/elements/NewButton'; import Spinner from '@/components/elements/Spinner'; import { Alert } from '@/components/elements/alert'; import { Dialog } from '@/components/elements/dialog'; import { ServerError } from '@/components/elements/ScreenBlock'; import { cn } from '@/lib/cn'; import ThemeSettingsDialog from './ThemeSettingsDialog'; const actionClass = 'h-8 px-2.5 text-sm'; function ThemeMarkContent({ theme }: { theme: AdminTheme }) { const [failed, setFailed] = useState(false); if (theme.icon_url && !failed) { return ( setFailed(true)} /> ); } return theme.icon ? : ; } function ThemeMark({ theme }: { theme: AdminTheme }) { return ( ); } const badges = (theme: AdminTheme): { label: string; className: string }[] => [ theme.active && { label: 'Active', className: 'bg-success/15 text-success' }, theme.previewing && { label: 'Previewing', className: 'bg-accent/15 text-accent' }, theme.builtin && { label: 'Built in', className: 'bg-secondary text-secondary-foreground' }, !theme.enabled && { label: 'Disabled', className: 'bg-warning/15 text-warning' }, ].filter((badge) => badge !== false); function ThemeCard({ theme }: { theme: AdminTheme }) { const activate = useActivateAdminTheme(); const preview = usePreviewAdminTheme(); const usable = theme.problem === null; return (

{theme.name}

{badges(theme).map((badge) => ( {badge.label} ))}

{[theme.version && `v${theme.version}`, theme.author && `by ${theme.author}`, theme.id] .filter(Boolean) .join(' · ')}

{theme.description || 'No description provided.'}

{theme.extends && (

Built on {theme.extends}

)} {theme.problem && (

{theme.problem}

)}
activate.mutate(activateAdminThemeInput(theme.id, theme.name))} > {theme.active ? 'Active' : 'Activate'} preview.mutate(previewAdminThemeInput(theme.id, theme.name))} > Preview for me {theme.settings_count > 0 && ( ( Settings )} > {({ open, onClose }) => } )}
); } function ThemeToolbar({ meta }: { meta?: AdminThemesMeta }) { const stopPreview = useStopAdminThemePreview(); return (
{meta?.preview && ( stopPreview.mutate({})} > Stop preview )} {meta?.safe_mode ? 'Leave safe mode' : 'Safe mode'}
); } export default function ThemesContainer() { const { data, error, refetch } = useAdminThemes(); const themes = (data?.data ?? []).map((item) => item.attributes); if (error) { return refetch()} />; } return ( {data?.meta?.safe_mode && ( Safe mode is on for your session: you see the classic theme without any extension bundles. )} {data ? ( <>
{themes.map((theme) => ( ))}
) : ( )}
); }