2025-10-04 14:11:28 +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 Dialog from '@mui/material/Dialog';
|
|
|
|
|
import DialogActions from '@mui/material/DialogActions';
|
|
|
|
|
import DialogContent from '@mui/material/DialogContent';
|
|
|
|
|
import DialogTitle from '@mui/material/DialogTitle';
|
|
|
|
|
import FormGroup from '@mui/material/FormGroup';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
import Button from '@mui/material/Button';
|
|
|
|
|
import Stack from '@mui/material/Stack';
|
|
|
|
|
import Typography from '@mui/material/Typography';
|
2025-11-02 17:18:49 +01:00
|
|
|
import { AwaitableComponentProps } from 'awaitable-component';
|
2025-10-04 14:11:28 +02:00
|
|
|
import { CheckboxInput } from '@/base/components/inputs/CheckboxInput.tsx';
|
|
|
|
|
import {
|
|
|
|
|
BACKUP_FLAG_GROUP_TO_TRANSLATION,
|
|
|
|
|
BACKUP_FLAGS,
|
|
|
|
|
BACKUP_FLAGS_BY_GROUP,
|
|
|
|
|
BACKUP_FLAGS_TO_TRANSLATION,
|
|
|
|
|
} from '@/features/backup/Backup.constants.ts';
|
|
|
|
|
import { BackupFlagGroup, BackupFlagInclusionState } from '@/features/backup/Backup.types.ts';
|
|
|
|
|
|
2025-10-04 21:48:44 +02:00
|
|
|
export const BackupFlagInclusionDialog = ({
|
2025-11-02 17:18:49 +01:00
|
|
|
onDismiss,
|
|
|
|
|
onSubmit,
|
|
|
|
|
isVisible,
|
|
|
|
|
onExitComplete,
|
2025-10-04 21:48:44 +02:00
|
|
|
title,
|
2025-11-02 17:18:49 +01:00
|
|
|
}: AwaitableComponentProps<BackupFlagInclusionState> & { title: string }) => {
|
2025-10-04 14:11:28 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
const [includeStateByFlag, setIncludeStateByFlag] = useState(
|
|
|
|
|
Object.fromEntries(BACKUP_FLAGS.map((flag) => [flag, true])) as BackupFlagInclusionState,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
2025-11-24 22:04:01 +01:00
|
|
|
<Dialog open={isVisible} onTransitionExited={onExitComplete} maxWidth="xs" fullWidth onClose={onDismiss}>
|
2025-10-04 21:48:44 +02:00
|
|
|
<DialogTitle>{title}</DialogTitle>
|
2025-10-04 14:11:28 +02:00
|
|
|
<DialogContent>
|
|
|
|
|
<FormGroup sx={{ gap: 2 }}>
|
|
|
|
|
{Object.entries(BACKUP_FLAGS_BY_GROUP).map(([group, flags]) => (
|
2025-10-04 21:48:44 +02:00
|
|
|
<Stack key={group}>
|
2025-10-04 14:11:28 +02:00
|
|
|
<Typography>{t(BACKUP_FLAG_GROUP_TO_TRANSLATION[group as BackupFlagGroup])}</Typography>
|
|
|
|
|
{flags.map((flag) => (
|
|
|
|
|
<CheckboxInput
|
|
|
|
|
key={flag}
|
|
|
|
|
label={t(BACKUP_FLAGS_TO_TRANSLATION[flag])}
|
|
|
|
|
checked={includeStateByFlag[flag]}
|
|
|
|
|
onChange={(_, checked) => {
|
|
|
|
|
setIncludeStateByFlag({
|
|
|
|
|
...includeStateByFlag,
|
|
|
|
|
[flag]: checked,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</Stack>
|
|
|
|
|
))}
|
|
|
|
|
</FormGroup>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
2025-11-02 17:18:49 +01:00
|
|
|
<Button autoFocus onClick={onDismiss} color="primary">
|
2025-10-04 14:11:28 +02:00
|
|
|
{t('global.button.cancel')}
|
|
|
|
|
</Button>
|
2025-11-02 17:18:49 +01:00
|
|
|
<Button onClick={() => onSubmit(includeStateByFlag)} color="primary">
|
2025-10-04 14:11:28 +02:00
|
|
|
{t('global.button.ok')}
|
|
|
|
|
</Button>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
};
|