-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact(rss): use individual save system
- Loading branch information
Showing
12 changed files
with
242 additions
and
297 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
73 changes: 53 additions & 20 deletions
73
src/components/GuildDashboard/SpecialCategoryComponents/RssFeeds/FeedDeleteButton.tsx
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 |
---|---|---|
@@ -1,31 +1,64 @@ | ||
import DeleteIcon from "@mui/icons-material/Delete"; | ||
import RestoreIcon from "@mui/icons-material/Restore"; | ||
import { Button } from "@mui/material"; | ||
import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle } from "@mui/material"; | ||
import { Fragment, useState } from "react"; | ||
|
||
import { useGuildConfigRssFeedsEditionContext } from "../../../../repository/context/GuildConfigEditionContext"; | ||
import { getGuildDashboardTranslations } from "../../../../i18n/i18n"; | ||
import { useGuildConfigEditionContext } from "../../../../repository/context/GuildConfigEditionContext"; | ||
import { useDeleteGuildRssFeedMutation } from "../../../../repository/redux/api/api"; | ||
import { RssFeed } from "../../../../repository/types/api"; | ||
|
||
interface FeedDeleteButtonProps { | ||
feedId: string; | ||
feed: Pick<RssFeed, "id" | "type" | "link" | "displayName">; | ||
} | ||
export default function FeedDeleteButton({ feedId }: FeedDeleteButtonProps) { | ||
const { deleteFeed, unDeleteFeed, isFeedMarkedForDeletion } = useGuildConfigRssFeedsEditionContext(); | ||
export default function FeedDeleteButton({ feed }: FeedDeleteButtonProps) { | ||
const { guildId } = useGuildConfigEditionContext(); | ||
const [deleteFeedMutation, { isLoading }] = useDeleteGuildRssFeedMutation(); | ||
const [isConfirmModalOpen, setIsConfirmModalOpen] = useState(false); | ||
|
||
const isMarkedForDeletion = isFeedMarkedForDeletion(feedId); | ||
const deleteCurrentFeed = () => deleteFeed(feedId); | ||
const restoreCurrentFeed = () => unDeleteFeed(feedId); | ||
async function deleteCurrentFeed() { | ||
if (isLoading) return; | ||
await deleteFeedMutation({ guildId, feedId: feed.id }); | ||
closeConfirmModal(); | ||
} | ||
|
||
const openConfirmModal = () => setIsConfirmModalOpen(true); | ||
const closeConfirmModal = () => setIsConfirmModalOpen(false); | ||
|
||
if (isMarkedForDeletion) { | ||
return ( | ||
<Button color="error" variant="outlined" onClick={restoreCurrentFeed} startIcon={<RestoreIcon />}> | ||
Restore this feed | ||
</Button> | ||
); | ||
} else { | ||
return ( | ||
<Button color="error" variant="outlined" onClick={deleteCurrentFeed} startIcon={<DeleteIcon />}> | ||
return ( | ||
<Fragment> | ||
<Button color="error" variant="outlined" onClick={openConfirmModal} startIcon={<DeleteIcon />}> | ||
Delete this feed | ||
</Button> | ||
); | ||
} | ||
<ConfirmationDialog open={isConfirmModalOpen} feed={feed} onCancel={closeConfirmModal} onConfirm={deleteCurrentFeed} /> | ||
</Fragment> | ||
); | ||
} | ||
|
||
|
||
interface ConfirmationDialogProps { | ||
open: boolean; | ||
feed: FeedDeleteButtonProps["feed"]; | ||
onCancel: () => void; | ||
onConfirm: () => void; | ||
} | ||
function ConfirmationDialog({ open, feed, onCancel, onConfirm }: ConfirmationDialogProps) { | ||
const feedType = getGuildDashboardTranslations("rss_type." + feed.type, feed.type); | ||
const description = `This action is irreversible. The ${feedType} feed '${feed.displayName ?? feed.link}' will be deleted forever.`; | ||
|
||
return ( | ||
<Dialog maxWidth="xs" open={open} onClose={onCancel}> | ||
<DialogTitle>Are you sure you want to delete this feed?</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText> | ||
{description} | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button autoFocus color="gray" onClick={onCancel}> | ||
Cancel | ||
</Button> | ||
<Button color="error" onClick={onConfirm}>Delete</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
45 changes: 15 additions & 30 deletions
45
...Components/RssFeeds/FeedPreviewButton.tsx → ...tegoryComponents/RssFeeds/FeedPreview.tsx
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.