diff --git a/src/plugins/holynotes/components/modals/HelpModal.tsx b/src/plugins/holynotes/components/modals/HelpModal.tsx index a8ec58079..cd27eedfc 100644 --- a/src/plugins/holynotes/components/modals/HelpModal.tsx +++ b/src/plugins/holynotes/components/modals/HelpModal.tsx @@ -4,7 +4,7 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps,ModalRoot, ModalSize } from "@utils/modal"; +import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize } from "@utils/modal"; import { findByProps } from "@webpack"; import { Button, Forms, Text } from "@webpack/common"; import noteHandler from "plugins/holynotes/noteHandler"; @@ -56,10 +56,16 @@ export default ({ onClose, ...modalProps }: ModalProps & { onClose: () => void; + }}>Refresh Avatars + diff --git a/src/plugins/holynotes/components/modals/Notebook.tsx b/src/plugins/holynotes/components/modals/Notebook.tsx index 2dae430cc..0a6dae4ee 100644 --- a/src/plugins/holynotes/components/modals/Notebook.tsx +++ b/src/plugins/holynotes/components/modals/Notebook.tsx @@ -49,7 +49,7 @@ const renderNotebook = ({ if (sortDirection) messageArray.reverse(); const filteredMessages = messageArray.filter(message => - message.props.note.content.toLowerCase().includes(searchInput.toLowerCase()), + message.props.note?.content?.toLowerCase().includes(searchInput.toLowerCase()), ); return filteredMessages.length > 0 ? filteredMessages : ; diff --git a/src/plugins/holynotes/components/modals/RenderMessage.tsx b/src/plugins/holynotes/components/modals/RenderMessage.tsx index 495efe6dc..7eec266f6 100644 --- a/src/plugins/holynotes/components/modals/RenderMessage.tsx +++ b/src/plugins/holynotes/components/modals/RenderMessage.tsx @@ -92,10 +92,10 @@ export const RenderMessage = ({ Object.assign( { ...note }, { - author: new User({ ...note.author }), - timestamp: new Date(note.timestamp), + author: new User({ ...note?.author }), + timestamp: new Date(note?.timestamp), // @ts-ignore - embeds: note.embeds.map((embed: { timestamp: string | number | Date; }) => + embeds: note?.embeds?.map((embed: { timestamp: string | number | Date; }) => embed.timestamp ? Object.assign(embed, { timestamp: new Date(embed.timestamp), diff --git a/src/plugins/holynotes/noteHandler.ts b/src/plugins/holynotes/noteHandler.ts index 107ca136e..bde40144f 100644 --- a/src/plugins/holynotes/noteHandler.ts +++ b/src/plugins/holynotes/noteHandler.ts @@ -9,7 +9,7 @@ import { ChannelStore, lodash, Toasts, UserStore } from "@webpack/common"; import { Channel, Message } from "discord-types/general"; import { Discord, HolyNotes } from "./types"; -import { deleteCacheFromDataStore, saveCacheToDataStore } from "./utils"; +import { deleteCacheFromDataStore, DeleteEntireStore, saveCacheToDataStore } from "./utils"; export const noteHandlerCache = new Map(); @@ -54,10 +54,10 @@ export default new (class NoteHandler { public addNote = async (message: Message, notebook: string) => { const notes = this.getNotes(notebook); const channel = ChannelStore.getChannel(message.channel_id); - const newNotes = Object.values(Object.assign({ [message.id]: this._formatNote(channel, message) }, notes)); + const newNotes = Object.assign({ [message.id]: this._formatNote(channel, message) }, notes); noteHandlerCache.set(notebook, newNotes); - saveCacheToDataStore(notebook, newNotes); + saveCacheToDataStore(notebook, newNotes as unknown as HolyNotes.Note[]); Toasts.show({ id: Toasts.genId(), @@ -81,7 +81,7 @@ export default new (class NoteHandler { public moveNote = async (note: HolyNotes.Note, from: string, to: string) => { const origNotebook = this.getNotes(from); - const newNoteBook = lodash.clone(this.getNotes(to)); + const newNoteBook = lodash.cloneDeep(this.getNotes(to)); newNoteBook[note.id] = note; @@ -99,7 +99,7 @@ export default new (class NoteHandler { }); }; - public newNoteBook = async (notebookName: string) => { + public newNoteBook = async (notebookName: string, silent?: Boolean) => { let notebookExists = false; for (const key of noteHandlerCache.keys()) { @@ -118,10 +118,10 @@ export default new (class NoteHandler { return; } - noteHandlerCache.set(notebookName, [{}]); - saveCacheToDataStore(notebookName, [{} as HolyNotes.Note]); + noteHandlerCache.set(notebookName, {}); + saveCacheToDataStore(notebookName, {} as HolyNotes.Note[]); - return Toasts.show({ + if (!silent) return Toasts.show({ id: Toasts.genId(), message: `Successfully created ${notebookName}.`, type: Toasts.Type.SUCCESS, @@ -170,4 +170,15 @@ export default new (class NoteHandler { }); }; + + public deleteEverything = async () => { + noteHandlerCache.clear(); + await DeleteEntireStore(); + + Toasts.show({ + id: Toasts.genId(), + message: "Successfully deleted all notes.", + type: Toasts.Type.SUCCESS, + }); + }; }); diff --git a/src/plugins/holynotes/utils.ts b/src/plugins/holynotes/utils.ts index 8569a437a..14e3bb074 100644 --- a/src/plugins/holynotes/utils.ts +++ b/src/plugins/holynotes/utils.ts @@ -7,7 +7,7 @@ import { createStore } from "@api/DataStore"; import { DataStore } from "@api/index"; -import { noteHandlerCache } from "./noteHandler"; +import noteHandler, { noteHandlerCache } from "./noteHandler"; import { HolyNotes } from "./types"; export const HolyNoteStore = createStore("HolyNoteData", "HolyNoteStore"); @@ -40,4 +40,5 @@ export async function DataStoreToCache() { export async function DeleteEntireStore() { await DataStore.clear(HolyNoteStore); + return noteHandler.newNoteBook("Main", true); }