|
| 1 | +import { ActionIcon, Code, Text, Tooltip } from '@mantine/core'; |
| 2 | +import { showNotification } from '@mantine/notifications'; |
| 3 | +import { IconCheck, IconRefreshAlert, IconX } from '@tabler/icons-react'; |
| 4 | +import { useRouter } from 'next/router'; |
| 5 | +import { trpc } from '../utils/trpc'; |
| 6 | +import { useOutOfSyncChapterModal } from './outOfSyncChapterModal'; |
| 7 | + |
| 8 | +export function CheckOutOfSyncChaptersButton() { |
| 9 | + const router = useRouter(); |
| 10 | + const { id } = router.query; |
| 11 | + |
| 12 | + const checkOutOfSyncChaptersMutation = trpc.manga.checkOutOfSyncChapters.useMutation(); |
| 13 | + |
| 14 | + const check = async () => { |
| 15 | + try { |
| 16 | + await checkOutOfSyncChaptersMutation.mutateAsync({ id: id ? parseInt(id as string, 10) : null }); |
| 17 | + showNotification({ |
| 18 | + icon: <IconCheck size={18} />, |
| 19 | + color: 'teal', |
| 20 | + autoClose: true, |
| 21 | + title: 'Out of Sync Chapters', |
| 22 | + message: <Text>Started checking for out of sync chapters in background</Text>, |
| 23 | + }); |
| 24 | + } catch (err) { |
| 25 | + showNotification({ |
| 26 | + icon: <IconX size={18} />, |
| 27 | + color: 'red', |
| 28 | + autoClose: true, |
| 29 | + title: 'Out of Sync Chapters', |
| 30 | + message: ( |
| 31 | + <Text> |
| 32 | + <Code color="red">{`${err}`}</Code> |
| 33 | + </Text> |
| 34 | + ), |
| 35 | + }); |
| 36 | + } |
| 37 | + }; |
| 38 | + |
| 39 | + const outOfSyncChapterModal = useOutOfSyncChapterModal( |
| 40 | + 'Check for out of sync chapters?', |
| 41 | + 'This will look for out of sync chapters and mark them', |
| 42 | + check, |
| 43 | + ); |
| 44 | + |
| 45 | + return ( |
| 46 | + <Tooltip withArrow position="bottom-end" label="Check for the out of sync chapters"> |
| 47 | + <ActionIcon |
| 48 | + onClick={outOfSyncChapterModal} |
| 49 | + variant="transparent" |
| 50 | + sx={(theme) => ({ |
| 51 | + backgroundColor: theme.white, |
| 52 | + color: theme.black, |
| 53 | + '&:hover': { |
| 54 | + backgroundColor: theme.colors.gray[0], |
| 55 | + }, |
| 56 | + })} |
| 57 | + size="lg" |
| 58 | + > |
| 59 | + <IconRefreshAlert size={18} strokeWidth={2} /> |
| 60 | + </ActionIcon> |
| 61 | + </Tooltip> |
| 62 | + ); |
| 63 | +} |
0 commit comments