2025-08-16 16:03:32 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import Box from '@mui/material/Box';
|
|
|
|
|
import Button from '@mui/material/Button';
|
2026-01-10 19:45:02 +01:00
|
|
|
import { useLingui } from '@lingui/react/macro';
|
|
|
|
|
import { INSTALLED_STATE_TO_TRANSLATION_MAP } from '@/features/extension/Extensions.constants.ts';
|
2025-08-16 16:03:32 +02:00
|
|
|
import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts';
|
|
|
|
|
import { getInstalledState, updateExtension } from '@/features/extension/Extensions.utils.ts';
|
|
|
|
|
import { useBackButton } from '@/base/hooks/useBackButton.ts';
|
|
|
|
|
import { ExtensionAction, InstalledState, TExtension } from '@/features/extension/Extensions.types.ts';
|
|
|
|
|
|
|
|
|
|
export const ActionButton = ({ pkgName, isInstalled, isObsolete, hasUpdate }: TExtension) => {
|
|
|
|
|
const handleBack = useBackButton();
|
2026-01-10 19:45:02 +01:00
|
|
|
const { t } = useLingui();
|
2025-08-16 16:03:32 +02:00
|
|
|
|
|
|
|
|
const installedState = getInstalledState(isInstalled, isObsolete, hasUpdate);
|
|
|
|
|
|
|
|
|
|
return (
|
2025-12-23 04:04:14 +01:00
|
|
|
<Box sx={{ px: 1, flexGrow: 1, flexBasis: 0 }}>
|
2025-08-16 16:03:32 +02:00
|
|
|
<Button
|
|
|
|
|
sx={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
color: installedState === InstalledState.OBSOLETE ? 'red' : 'inherit',
|
|
|
|
|
}}
|
|
|
|
|
variant="outlined"
|
|
|
|
|
size="large"
|
|
|
|
|
onClick={async () => {
|
2025-09-06 14:58:19 +02:00
|
|
|
const action = hasUpdate && !isObsolete ? ExtensionAction.UPDATE : ExtensionAction.UNINSTALL;
|
|
|
|
|
|
2025-08-16 16:03:32 +02:00
|
|
|
try {
|
|
|
|
|
await updateExtension(pkgName, isObsolete, action);
|
|
|
|
|
|
|
|
|
|
if (action === ExtensionAction.UNINSTALL) {
|
|
|
|
|
handleBack();
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
defaultPromiseErrorHandler('ExtensionInfo::ActionButton::onClick');
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-01-10 19:45:02 +01:00
|
|
|
{t(INSTALLED_STATE_TO_TRANSLATION_MAP[installedState])}
|
2025-08-16 16:03:32 +02:00
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|