-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add refresh metadata button to cards
- Loading branch information
Showing
6 changed files
with
287 additions
and
105 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
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,48 @@ | ||
import { Box, Button, Text } from '@mantine/core'; | ||
import { useModals } from '@mantine/modals'; | ||
|
||
function RefreshMetadataModalContent({ onRefresh, onClose }: { onRefresh: () => void; onClose: () => void }) { | ||
return ( | ||
<> | ||
<Text mb={4} size="sm"> | ||
This will update all downloaded chapters with the latest metadata from AniList | ||
</Text> | ||
<Box | ||
sx={(theme) => ({ | ||
display: 'flex', | ||
gap: theme.spacing.xs, | ||
justifyContent: 'end', | ||
marginTop: theme.spacing.md, | ||
})} | ||
> | ||
<Button variant="default" color="dark" onClick={onClose}> | ||
Cancel | ||
</Button> | ||
<Button | ||
variant="filled" | ||
color="teal" | ||
onClick={() => { | ||
onRefresh(); | ||
onClose(); | ||
}} | ||
> | ||
Refresh | ||
</Button> | ||
</Box> | ||
</> | ||
); | ||
} | ||
|
||
export const useRefreshModal = (title: string, onRefresh: () => void) => { | ||
const modals = useModals(); | ||
|
||
const openRemoveModal = () => { | ||
const id = modals.openModal({ | ||
title: `Refresh Metadata for ${title}?`, | ||
centered: true, | ||
children: <RefreshMetadataModalContent onRefresh={onRefresh} onClose={() => modals.closeModal(id)} />, | ||
}); | ||
}; | ||
|
||
return openRemoveModal; | ||
}; |
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,75 @@ | ||
import { Alert, Box, Button, Checkbox, Code, Text } from '@mantine/core'; | ||
import { useModals } from '@mantine/modals'; | ||
import { useState } from 'react'; | ||
|
||
function RemoveModalContent({ | ||
title, | ||
onRemove, | ||
onClose, | ||
}: { | ||
title: string; | ||
onRemove: (shouldRemoveFiles: boolean) => void; | ||
onClose: () => void; | ||
}) { | ||
const [shouldRemoveFiles, setShouldRemoveFiles] = useState(false); | ||
return ( | ||
<> | ||
<Text mb={4} size="sm"> | ||
Are you sure you want to remove | ||
<Code className="text-base font-bold" color="red"> | ||
{title} | ||
</Code> | ||
? | ||
</Text> | ||
<Alert | ||
icon={ | ||
<Checkbox | ||
checked={shouldRemoveFiles} | ||
color="red" | ||
onChange={(event) => setShouldRemoveFiles(event.currentTarget.checked)} | ||
/> | ||
} | ||
title="Remove files?" | ||
color="red" | ||
> | ||
This action is destructive and all downloaded files will be removed | ||
</Alert> | ||
<Box | ||
sx={(theme) => ({ | ||
display: 'flex', | ||
gap: theme.spacing.xs, | ||
justifyContent: 'end', | ||
marginTop: theme.spacing.md, | ||
})} | ||
> | ||
<Button variant="default" color="dark" onClick={onClose}> | ||
Cancel | ||
</Button> | ||
<Button | ||
variant="filled" | ||
color="red" | ||
onClick={() => { | ||
onRemove(shouldRemoveFiles); | ||
onClose(); | ||
}} | ||
> | ||
Remove | ||
</Button> | ||
</Box> | ||
</> | ||
); | ||
} | ||
|
||
export const useRemoveModal = (title: string, onRemove: (shouldRemoveFiles: boolean) => void) => { | ||
const modals = useModals(); | ||
|
||
const openRemoveModal = () => { | ||
const id = modals.openModal({ | ||
title: `Remove ${title}?`, | ||
centered: true, | ||
children: <RemoveModalContent title={title} onRemove={onRemove} onClose={() => modals.closeModal(id)} />, | ||
}); | ||
}; | ||
|
||
return openRemoveModal; | ||
}; |
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.