-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add "migration" tab to "Browse" screen * Add missing useEffect cleanup for navbar title and actions * Make "SourceGridLayout" reusable * Add migration tab to "Browse" * Add migration logic
- Loading branch information
Showing
39 changed files
with
1,310 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* 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 DialogTitle from '@mui/material/DialogTitle'; | ||
import DialogContent from '@mui/material/DialogContent'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import Button from '@mui/material/Button'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Stack } from '@mui/material'; | ||
import { Link, useNavigate, useParams } from 'react-router-dom'; | ||
import { useState } from 'react'; | ||
import FormGroup from '@mui/material/FormGroup'; | ||
import { CheckboxInput } from '@/components/atoms/CheckboxInput.tsx'; | ||
import { Mangas, MigrateMode } from '@/lib/data/Mangas.ts'; | ||
import { makeToast } from '@/components/util/Toast.tsx'; | ||
|
||
export const MigrateDialog = ({ mangaIdToMigrateTo, onClose }: { mangaIdToMigrateTo: number; onClose: () => void }) => { | ||
const { t } = useTranslation(); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const { mangaId: mangaIdAsString } = useParams<{ mangaId: string }>(); | ||
const mangaId = Number(mangaIdAsString); | ||
|
||
const [includeChapters, setIncludeChapters] = useState(true); | ||
const [includeCategories, setIncludeCategories] = useState(true); | ||
|
||
const [isMigrationInProcess, setIsMigrationInProcess] = useState(false); | ||
|
||
const migrate = async (mode: MigrateMode) => { | ||
if (mangaId == null) { | ||
throw new Error(`MigrateDialog::migrate: unexpected mangaId "${mangaId}"`); | ||
} | ||
|
||
makeToast(t('migrate.label.info'), 'info'); | ||
|
||
setIsMigrationInProcess(true); | ||
|
||
try { | ||
await Mangas.migrate(mangaId, mangaIdToMigrateTo, { | ||
mode, | ||
migrateChapters: includeChapters, | ||
migrateCategories: includeCategories, | ||
}); | ||
|
||
navigate(`/manga/${mangaIdToMigrateTo}`); | ||
} catch (e) { | ||
setIsMigrationInProcess(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Dialog open fullWidth onClose={onClose}> | ||
<DialogTitle>{t('migrate.dialog.title')}</DialogTitle> | ||
<DialogContent dividers> | ||
<FormGroup> | ||
<CheckboxInput | ||
disabled={isMigrationInProcess} | ||
label={t('chapter.title')} | ||
checked={includeChapters} | ||
onChange={(_, checked) => setIncludeChapters(checked)} | ||
/> | ||
<CheckboxInput | ||
disabled={isMigrationInProcess} | ||
label={t('category.title.category_one')} | ||
checked={includeCategories} | ||
onChange={(_, checked) => setIncludeCategories(checked)} | ||
/> | ||
</FormGroup> | ||
</DialogContent> | ||
<DialogActions> | ||
<Stack sx={{ width: '100%' }} direction="row" justifyContent="space-between"> | ||
<Button disabled={isMigrationInProcess} component={Link} to={`/manga/${mangaIdToMigrateTo}`}> | ||
{t('migrate.dialog.action.button.show_entry')} | ||
</Button> | ||
<Stack direction="row"> | ||
<Button disabled={isMigrationInProcess} onClick={onClose}> | ||
{t('global.button.cancel')} | ||
</Button> | ||
<Button disabled={isMigrationInProcess} onClick={() => migrate('copy')}> | ||
{t('global.button.copy')} | ||
</Button> | ||
<Button disabled={isMigrationInProcess} onClick={() => migrate('migrate')}> | ||
{t('global.button.migrate')} | ||
</Button> | ||
</Stack> | ||
</Stack> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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 Card from '@mui/material/Card'; | ||
import CardContent from '@mui/material/CardContent'; | ||
import { Box, CardActionArea, Chip } from '@mui/material'; | ||
import Avatar from '@mui/material/Avatar'; | ||
import Typography from '@mui/material/Typography'; | ||
import { Link } from 'react-router-dom'; | ||
import { requestManager } from '@/lib/requests/RequestManager.ts'; | ||
import { GetMigratableSourcesQuery } from '@/lib/graphql/generated/graphql.ts'; | ||
import { translateExtensionLanguage } from '@/screens/util/Extensions.ts'; | ||
|
||
export type TMigratableSource = NonNullable<GetMigratableSourcesQuery['mangas']['nodes'][number]['source']> & { | ||
mangaCount: number; | ||
}; | ||
|
||
// TODO - cleanup source/extension components | ||
export const MigrationCard = ({ id, name, lang, iconUrl, mangaCount }: TMigratableSource) => ( | ||
<Card> | ||
<CardActionArea component={Link} to={`/migrate/source/${id}/`}> | ||
<CardContent | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
p: 2, | ||
}} | ||
> | ||
<Box sx={{ display: 'flex' }}> | ||
<Avatar | ||
variant="rounded" | ||
sx={{ | ||
width: 56, | ||
height: 56, | ||
flex: '0 0 auto', | ||
mr: 2, | ||
}} | ||
alt={name} | ||
src={requestManager.getValidImgUrlFor(iconUrl)} | ||
/> | ||
<Box sx={{ display: 'flex', flexDirection: 'column' }}> | ||
<Typography variant="h5" component="h2"> | ||
{name} | ||
</Typography> | ||
<Typography variant="caption" display="block"> | ||
{translateExtensionLanguage(lang)} | ||
</Typography> | ||
</Box> | ||
</Box> | ||
<Chip sx={{ borderRadius: '5px' }} size="small" label={mangaCount} /> | ||
</CardContent> | ||
</CardActionArea> | ||
</Card> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.