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

Fix few problems after i tried to fix types

This commit is contained in:
Wolfie 2024-03-16 20:47:54 -04:00
parent 0bd4f9a74f
commit 2e9e14b447
No known key found for this signature in database
GPG key ID: DE384EE9BF2D909A
5 changed files with 34 additions and 16 deletions

View file

@ -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;
<Button
look={Button.Looks.FILLED}
color={Button.Colors.GREEN}
style={{ marginRight: "10px" }}
onClick={() => {
noteHandler.refreshAvatars();
}}
>Refresh Avatars</Button>
}}>Refresh Avatars</Button>
<Button
look={Button.Looks.FILLED}
color={Button.Colors.RED}
onClick={() => {
noteHandler.deleteEverything();
}}>Delete All Notes</Button>
</div>
</ModalFooter>
</ModalRoot>

View file

@ -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 : <Errors />;

View file

@ -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),

View file

@ -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,
});
};
});

View file

@ -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);
}