import { ConfirmModal, Navigation, QuickAccessTab } from 'decky-frontend-lib'; import { FC, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { InstallType } from '../../plugin'; interface MultiplePluginsInstallModalProps { requests: { name: string; version: string; hash: string; install_type: InstallType }[]; onOK(): void | Promise; onCancel(): void | Promise; closeModal?(): void; } // values are the JSON keys used in the translation file const InstallTypeTranslationMapping = { [InstallType.INSTALL]: 'install', [InstallType.REINSTALL]: 'reinstall', [InstallType.UPDATE]: 'update', } as const satisfies Record; type TitleTranslationMapping = 'mixed' | (typeof InstallTypeTranslationMapping)[InstallType]; const MultiplePluginsInstallModal: FC = ({ requests, onOK, onCancel, closeModal, }) => { const [loading, setLoading] = useState(false); const { t } = useTranslation(); // used as part of the title translation // if we know all operations are of a specific type, we can show so in the title to make decision easier const installTypeGrouped = useMemo((): TitleTranslationMapping => { if (requests.every(({ install_type }) => install_type === InstallType.INSTALL)) return 'install'; if (requests.every(({ install_type }) => install_type === InstallType.REINSTALL)) return 'reinstall'; if (requests.every(({ install_type }) => install_type === InstallType.UPDATE)) return 'update'; return 'mixed'; }, [requests]); return ( { setLoading(true); await onOK(); setTimeout(() => Navigation.OpenQuickAccessMenu(QuickAccessTab.Decky), 250); setTimeout(() => DeckyPluginLoader.checkPluginUpdates(), 1000); }} onCancel={async () => { await onCancel(); }} strTitle={
{t(`MultiplePluginsInstallModal.title.${installTypeGrouped}`, { count: requests.length })}
} strOKButtonText={t(`MultiplePluginsInstallModal.ok_button.${loading ? 'loading' : 'idle'}`)} >
{t('MultiplePluginsInstallModal.confirm')}
    {requests.map(({ name, version, install_type, hash }, i) => { const installTypeStr = InstallTypeTranslationMapping[install_type]; const description = t(`MultiplePluginsInstallModal.description.${installTypeStr}`, { name, version, }); return (
  • {description}
    {hash === 'False' && (
    {t('PluginInstallModal.no_hash')}
    )}
  • ); })}
); }; export default MultiplePluginsInstallModal;