import { ButtonItem, Dropdown, Focusable, PanelSectionRow, SingleDropdownOption, SuspensefulImage } from '@decky/ui'; import { CSSProperties, FC, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { FaArrowDown, FaArrowUp, FaCheck, FaDownload, FaRecycle } from 'react-icons/fa'; import { DisabledPlugin, InstallType, Plugin } from '../../plugin'; import { StorePlugin, requestPluginInstall } from '../../store'; import ExternalLink from '../ExternalLink'; interface PluginCardProps { storePlugin: StorePlugin; installedPlugin: Plugin | DisabledPlugin | undefined; } const PluginCard: FC = ({ storePlugin, installedPlugin }) => { const [selectedOption, setSelectedOption] = useState(0); const installedVersionIndex = storePlugin.versions.findIndex((version) => version.name === installedPlugin?.version); const installType = // This assumes index in options is inverse to update order (i.e. newer updates are first) installedPlugin && selectedOption < installedVersionIndex ? InstallType.UPDATE : installedPlugin && selectedOption === installedVersionIndex ? InstallType.REINSTALL : installedPlugin && selectedOption > installedVersionIndex ? InstallType.DOWNGRADE : installedPlugin // can happen if installed version is not in store ? InstallType.OVERWRITE : InstallType.INSTALL; const root = storePlugin.tags.some((tag) => tag === 'root'); const { t } = useTranslation(); return (
{storePlugin.name} {storePlugin.author} {storePlugin.description ? ( storePlugin.description ) : ( {t('PluginCard.plugin_no_desc')} )} {root && (
{t('PluginCard.plugin_full_access')}{' '} deckbrew.xyz/root
)}
requestPluginInstall(storePlugin.name, storePlugin.versions[selectedOption], installType) } > {installType === InstallType.UPDATE ? ( <> {t('PluginCard.plugin_update')} ) : installType === InstallType.REINSTALL ? ( <> {t('PluginCard.plugin_reinstall')} ) : installType === InstallType.DOWNGRADE ? ( <> {t('PluginCard.plugin_downgrade')} ) : installType === InstallType.OVERWRITE ? ( <> {t('PluginCard.plugin_overwrite')} ) : ( // installType === InstallType.INSTALL (also fallback) <> {t('PluginCard.plugin_install')} )}
({ data: index, label: (
{version.name} {installedPlugin && installedVersionIndex === index ? : null}
), })) as SingleDropdownOption[] } menuLabel={t('PluginCard.plugin_version_label') as string} selectedOption={selectedOption} onChange={({ data }) => setSelectedOption(data)} />
); }; export default PluginCard;