mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-18 02:47:03 -04:00
Refactor ContextMenuAPI (#2236)
This commit is contained in:
parent
612fdf8952
commit
42a9fa2d47
25 changed files with 220 additions and 245 deletions
|
@ -16,7 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { addContextMenuPatch, findGroupChildrenByChildId, NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu";
|
||||
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
|
||||
import { Menu } from "@webpack/common";
|
||||
|
||||
import { isPinned, movePin, PinOrder, settings, snapshotArray, togglePin } from "./settings";
|
||||
|
@ -50,13 +50,13 @@ function PinMenuItem(channelId: string) {
|
|||
);
|
||||
}
|
||||
|
||||
const GroupDMContext: NavContextMenuPatchCallback = (children, props) => () => {
|
||||
const GroupDMContext: NavContextMenuPatchCallback = (children, props) => {
|
||||
const container = findGroupChildrenByChildId("leave-channel", children);
|
||||
if (container)
|
||||
container.unshift(PinMenuItem(props.channel.id));
|
||||
};
|
||||
|
||||
const UserContext: NavContextMenuPatchCallback = (children, props) => () => {
|
||||
const UserContext: NavContextMenuPatchCallback = (children, props) => {
|
||||
const container = findGroupChildrenByChildId("close-dm", children);
|
||||
if (container) {
|
||||
const idx = container.findIndex(c => c?.props?.id === "close-dm");
|
||||
|
@ -64,12 +64,7 @@ const UserContext: NavContextMenuPatchCallback = (children, props) => () => {
|
|||
}
|
||||
};
|
||||
|
||||
export function addContextMenus() {
|
||||
addContextMenuPatch("gdm-context", GroupDMContext);
|
||||
addContextMenuPatch("user-context", UserContext);
|
||||
}
|
||||
|
||||
export function removeContextMenus() {
|
||||
removeContextMenuPatch("gdm-context", GroupDMContext);
|
||||
removeContextMenuPatch("user-context", UserContext);
|
||||
}
|
||||
export const contextMenus = {
|
||||
"gdm-context": GroupDMContext,
|
||||
"user-context": UserContext
|
||||
};
|
||||
|
|
|
@ -20,7 +20,7 @@ import { Devs } from "@utils/constants";
|
|||
import definePlugin from "@utils/types";
|
||||
import { Channel } from "discord-types/general";
|
||||
|
||||
import { addContextMenus, removeContextMenus } from "./contextMenus";
|
||||
import { contextMenus } from "./contextMenus";
|
||||
import { getPinAt, isPinned, settings, snapshotArray, sortedSnapshot, usePinnedDms } from "./settings";
|
||||
|
||||
export default definePlugin({
|
||||
|
@ -29,9 +29,7 @@ export default definePlugin({
|
|||
authors: [Devs.Ven, Devs.Strencher],
|
||||
|
||||
settings,
|
||||
|
||||
start: addContextMenus,
|
||||
stop: removeContextMenus,
|
||||
contextMenus,
|
||||
|
||||
usePinCount(channelIds: string[]) {
|
||||
const pinnedDms = usePinnedDms();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue