1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-11 02:16:23 +00:00

move handleDelete outside of onClick react component

This commit is contained in:
Wolfie 2024-03-14 22:56:13 -04:00
parent 0cd01a54a0
commit 230630fb99
No known key found for this signature in database
GPG key ID: DE384EE9BF2D909A
2 changed files with 10 additions and 9 deletions

View file

@ -69,6 +69,7 @@ export const NoteModal = (props: ModalProps & { onClose: () => void; }) => {
const notes = noteHandler.getNotes(currentNotebook); const notes = noteHandler.getNotes(currentNotebook);
if (!notes) return <></>; if (!notes) return <></>;
const { TabBar, selectedTab } = CreateTabBar({ tabs: noteHandler.getAllNotes(), firstSelectedTab: currentNotebook, onChangeTab: setCurrentNotebook }); const { TabBar, selectedTab } = CreateTabBar({ tabs: noteHandler.getAllNotes(), firstSelectedTab: currentNotebook, onChangeTab: setCurrentNotebook });
return ( return (

View file

@ -5,7 +5,7 @@
*/ */
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps,ModalRoot, ModalSize } from "@utils/modal"; import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize } from "@utils/modal";
import { Button, React, Text } from "@webpack/common"; import { Button, React, Text } from "@webpack/common";
import noteHandler from "plugins/holynotes/noteHandler"; import noteHandler from "plugins/holynotes/noteHandler";
@ -15,7 +15,10 @@ import { RenderMessage } from "./RenderMessage";
export default ({ onClose, notebook, ...props }: ModalProps & { onClose: () => void; notebook: string; }) => { export default ({ onClose, notebook, ...props }: ModalProps & { onClose: () => void; notebook: string; }) => {
const notes = noteHandler.getNotes(notebook); const notes = noteHandler.getNotes(notebook);
if (!notes) return <></>; const handleDelete = () => {
onClose();
noteHandler.deleteNotebook(notebook);
};
return ( return (
<ModalRoot <ModalRoot
@ -28,25 +31,22 @@ export default ({ onClose, notebook, ...props }: ModalProps & { onClose: () => v
</ModalHeader> </ModalHeader>
<ModalContent> <ModalContent>
<ErrorBoundary> <ErrorBoundary>
{Object.keys(notes).length === 0 || !notes ? ( {notes && Object.keys(notes).length > 0 ? (
<Error />
) : (
Object.values(notes).map(note => ( Object.values(notes).map(note => (
<RenderMessage <RenderMessage
note={note} note={note}
notebook={notebook} notebook={notebook}
fromDeleteModal={true} /> fromDeleteModal={true} />
)) ))
) : (
<Error />
)} )}
</ErrorBoundary> </ErrorBoundary>
</ModalContent> </ModalContent>
<ModalFooter> <ModalFooter>
<Button <Button
color={Button.Colors.RED} color={Button.Colors.RED}
onClick={() => { onClick={handleDelete}
noteHandler.deleteNotebook(notebook);
onClose();
}}
> >
DELETE DELETE
</Button> </Button>