mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-11 10:26:21 +00:00
Add Button To Access Notebook
This commit is contained in:
parent
60ec125105
commit
35991f2501
1 changed files with 50 additions and 3 deletions
|
@ -21,16 +21,21 @@ import "./style.css";
|
||||||
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
|
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
|
||||||
import { DataStore } from "@api/index";
|
import { DataStore } from "@api/index";
|
||||||
import { addButton, removeButton } from "@api/MessagePopover";
|
import { addButton, removeButton } from "@api/MessagePopover";
|
||||||
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
|
import { classes } from "@utils/misc";
|
||||||
import { openModal } from "@utils/modal";
|
import { openModal } from "@utils/modal";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
|
import { findByProps, findExportedComponentLazy } from "@webpack";
|
||||||
import { ChannelStore, Menu } from "@webpack/common";
|
import { ChannelStore, Menu } from "@webpack/common";
|
||||||
import { Message } from "discord-types/general";
|
import { Message } from "discord-types/general";
|
||||||
|
|
||||||
import { Popover as NoteButtonPopover } from "./components/icons/NoteButton";
|
import { Popover as NoteButtonPopover, Popover } from "./components/icons/NoteButton";
|
||||||
import { NoteModal } from "./components/modals/Notebook";
|
import { NoteModal } from "./components/modals/Notebook";
|
||||||
import noteHandler, { noteHandlerCache } from "./noteHandler";
|
import noteHandler, { noteHandlerCache } from "./noteHandler";
|
||||||
import { DataStoreToCache } from "./utils";
|
import { DataStoreToCache, HolyNoteStore } from "./utils";
|
||||||
|
|
||||||
|
const HeaderBarIcon = findExportedComponentLazy("Icon", "Divider");
|
||||||
|
|
||||||
const messageContextMenuPatch: NavContextMenuPatchCallback = async (children, { message }: { message: Message; }) => {
|
const messageContextMenuPatch: NavContextMenuPatchCallback = async (children, { message }: { message: Message; }) => {
|
||||||
children.push(
|
children.push(
|
||||||
|
@ -46,6 +51,22 @@ const messageContextMenuPatch: NavContextMenuPatchCallback = async (children, {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function ToolBarHeader() {
|
||||||
|
const iconClasses = findByProps("iconWrapper", "clickable");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ErrorBoundary noop={true}>
|
||||||
|
<HeaderBarIcon
|
||||||
|
tooltip="Holy Notes"
|
||||||
|
position="bottom"
|
||||||
|
className={classes("vc-note-button", iconClasses.iconWrapper, iconClasses.clickable)}
|
||||||
|
icon={e => Popover(e)}
|
||||||
|
onClick={() => openModal(props => <NoteModal {...props} />)}
|
||||||
|
/>
|
||||||
|
</ErrorBoundary>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "HolyNotes",
|
name: "HolyNotes",
|
||||||
|
@ -53,18 +74,43 @@ export default definePlugin({
|
||||||
authors: [Devs.Wolfie],
|
authors: [Devs.Wolfie],
|
||||||
dependencies: ["MessagePopoverAPI", "ChatInputButtonAPI"],
|
dependencies: ["MessagePopoverAPI", "ChatInputButtonAPI"],
|
||||||
|
|
||||||
|
patches: [
|
||||||
|
{
|
||||||
|
find: "toolbar:function",
|
||||||
|
replacement: {
|
||||||
|
match: /(function \i\(\i\){)(.{1,200}toolbar.{1,100}mobileToolbar)/,
|
||||||
|
replace: "$1$self.toolbarAction(arguments[0]);$2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
toolboxActions: {
|
toolboxActions: {
|
||||||
async "Open Notes"() {
|
async "Open Notes"() {
|
||||||
openModal(props => <NoteModal {...props} />);
|
openModal(props => <NoteModal {...props} />);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
contextMenus: {
|
contextMenus: {
|
||||||
"message": messageContextMenuPatch
|
"message": messageContextMenuPatch
|
||||||
},
|
},
|
||||||
|
|
||||||
|
toolbarAction(e) {
|
||||||
|
if (Array.isArray(e.toolbar))
|
||||||
|
return e.toolbar.push(
|
||||||
|
<ErrorBoundary noop={true}>
|
||||||
|
<ToolBarHeader />
|
||||||
|
</ErrorBoundary>
|
||||||
|
);
|
||||||
|
|
||||||
|
e.toolbar = [
|
||||||
|
<ErrorBoundary noop={true}>
|
||||||
|
<ToolBarHeader />
|
||||||
|
</ErrorBoundary>,
|
||||||
|
e.toolbar,
|
||||||
|
];
|
||||||
|
},
|
||||||
async start() {
|
async start() {
|
||||||
if (await DataStore.keys().then(keys => !keys.includes("Main"))) return noteHandler.newNoteBook("Main");
|
if (await DataStore.keys(HolyNoteStore).then(keys => !keys.includes("Main"))) return noteHandler.newNoteBook("Main");
|
||||||
if (!noteHandlerCache.has("Main")) await DataStoreToCache();
|
if (!noteHandlerCache.has("Main")) await DataStoreToCache();
|
||||||
|
|
||||||
addButton("HolyNotes", message => {
|
addButton("HolyNotes", message => {
|
||||||
|
@ -74,6 +120,7 @@ export default definePlugin({
|
||||||
message: message,
|
message: message,
|
||||||
channel: ChannelStore.getChannel(message.channel_id),
|
channel: ChannelStore.getChannel(message.channel_id),
|
||||||
onClick: () => noteHandler.addNote(message, "Main")
|
onClick: () => noteHandler.addNote(message, "Main")
|
||||||
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue