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:
parent
0bd4f9a74f
commit
2e9e14b447
5 changed files with 34 additions and 16 deletions
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* 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 { findByProps } from "@webpack";
|
||||||
import { Button, Forms, Text } from "@webpack/common";
|
import { Button, Forms, Text } from "@webpack/common";
|
||||||
import noteHandler from "plugins/holynotes/noteHandler";
|
import noteHandler from "plugins/holynotes/noteHandler";
|
||||||
|
@ -56,10 +56,16 @@ export default ({ onClose, ...modalProps }: ModalProps & { onClose: () => void;
|
||||||
<Button
|
<Button
|
||||||
look={Button.Looks.FILLED}
|
look={Button.Looks.FILLED}
|
||||||
color={Button.Colors.GREEN}
|
color={Button.Colors.GREEN}
|
||||||
|
style={{ marginRight: "10px" }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
noteHandler.refreshAvatars();
|
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>
|
</div>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</ModalRoot>
|
</ModalRoot>
|
||||||
|
|
|
@ -49,7 +49,7 @@ const renderNotebook = ({
|
||||||
if (sortDirection) messageArray.reverse();
|
if (sortDirection) messageArray.reverse();
|
||||||
|
|
||||||
const filteredMessages = messageArray.filter(message =>
|
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 />;
|
return filteredMessages.length > 0 ? filteredMessages : <Errors />;
|
||||||
|
|
|
@ -92,10 +92,10 @@ export const RenderMessage = ({
|
||||||
Object.assign(
|
Object.assign(
|
||||||
{ ...note },
|
{ ...note },
|
||||||
{
|
{
|
||||||
author: new User({ ...note.author }),
|
author: new User({ ...note?.author }),
|
||||||
timestamp: new Date(note.timestamp),
|
timestamp: new Date(note?.timestamp),
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
embeds: note.embeds.map((embed: { timestamp: string | number | Date; }) =>
|
embeds: note?.embeds?.map((embed: { timestamp: string | number | Date; }) =>
|
||||||
embed.timestamp
|
embed.timestamp
|
||||||
? Object.assign(embed, {
|
? Object.assign(embed, {
|
||||||
timestamp: new Date(embed.timestamp),
|
timestamp: new Date(embed.timestamp),
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { ChannelStore, lodash, Toasts, UserStore } from "@webpack/common";
|
||||||
import { Channel, Message } from "discord-types/general";
|
import { Channel, Message } from "discord-types/general";
|
||||||
|
|
||||||
import { Discord, HolyNotes } from "./types";
|
import { Discord, HolyNotes } from "./types";
|
||||||
import { deleteCacheFromDataStore, saveCacheToDataStore } from "./utils";
|
import { deleteCacheFromDataStore, DeleteEntireStore, saveCacheToDataStore } from "./utils";
|
||||||
|
|
||||||
export const noteHandlerCache = new Map();
|
export const noteHandlerCache = new Map();
|
||||||
|
|
||||||
|
@ -54,10 +54,10 @@ export default new (class NoteHandler {
|
||||||
public addNote = async (message: Message, notebook: string) => {
|
public addNote = async (message: Message, notebook: string) => {
|
||||||
const notes = this.getNotes(notebook);
|
const notes = this.getNotes(notebook);
|
||||||
const channel = ChannelStore.getChannel(message.channel_id);
|
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);
|
noteHandlerCache.set(notebook, newNotes);
|
||||||
saveCacheToDataStore(notebook, newNotes);
|
saveCacheToDataStore(notebook, newNotes as unknown as HolyNotes.Note[]);
|
||||||
|
|
||||||
Toasts.show({
|
Toasts.show({
|
||||||
id: Toasts.genId(),
|
id: Toasts.genId(),
|
||||||
|
@ -81,7 +81,7 @@ export default new (class NoteHandler {
|
||||||
|
|
||||||
public moveNote = async (note: HolyNotes.Note, from: string, to: string) => {
|
public moveNote = async (note: HolyNotes.Note, from: string, to: string) => {
|
||||||
const origNotebook = this.getNotes(from);
|
const origNotebook = this.getNotes(from);
|
||||||
const newNoteBook = lodash.clone(this.getNotes(to));
|
const newNoteBook = lodash.cloneDeep(this.getNotes(to));
|
||||||
|
|
||||||
newNoteBook[note.id] = note;
|
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;
|
let notebookExists = false;
|
||||||
|
|
||||||
for (const key of noteHandlerCache.keys()) {
|
for (const key of noteHandlerCache.keys()) {
|
||||||
|
@ -118,10 +118,10 @@ export default new (class NoteHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
noteHandlerCache.set(notebookName, [{}]);
|
noteHandlerCache.set(notebookName, {});
|
||||||
saveCacheToDataStore(notebookName, [{} as HolyNotes.Note]);
|
saveCacheToDataStore(notebookName, {} as HolyNotes.Note[]);
|
||||||
|
|
||||||
return Toasts.show({
|
if (!silent) return Toasts.show({
|
||||||
id: Toasts.genId(),
|
id: Toasts.genId(),
|
||||||
message: `Successfully created ${notebookName}.`,
|
message: `Successfully created ${notebookName}.`,
|
||||||
type: Toasts.Type.SUCCESS,
|
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,
|
||||||
|
});
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
import { createStore } from "@api/DataStore";
|
import { createStore } from "@api/DataStore";
|
||||||
import { DataStore } from "@api/index";
|
import { DataStore } from "@api/index";
|
||||||
|
|
||||||
import { noteHandlerCache } from "./noteHandler";
|
import noteHandler, { noteHandlerCache } from "./noteHandler";
|
||||||
import { HolyNotes } from "./types";
|
import { HolyNotes } from "./types";
|
||||||
|
|
||||||
export const HolyNoteStore = createStore("HolyNoteData", "HolyNoteStore");
|
export const HolyNoteStore = createStore("HolyNoteData", "HolyNoteStore");
|
||||||
|
@ -40,4 +40,5 @@ export async function DataStoreToCache() {
|
||||||
|
|
||||||
export async function DeleteEntireStore() {
|
export async function DeleteEntireStore() {
|
||||||
await DataStore.clear(HolyNoteStore);
|
await DataStore.clear(HolyNoteStore);
|
||||||
|
return noteHandler.newNoteBook("Main", true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue