From 8fd11936c251213d741eb63aee96b44be047a120 Mon Sep 17 00:00:00 2001 From: verticalsync <60797172+verticalsync@users.noreply.github.com> Date: Sat, 2 Mar 2024 18:18:40 +0200 Subject: [PATCH] update plugins: Anammox, betterPinDMs, FastMenu --- src/suncordplugins/Anammox/README.md | 8 + src/suncordplugins/Anammox/index.ts | 11 +- src/suncordplugins/FastMenu/README.md | 10 +- src/suncordplugins/FastMenu/index.tsx | 33 +--- .../components/CreateCategoryModal.tsx | 75 ++++---- .../betterPinDMs/components/contextMenu.tsx | 38 +++- src/suncordplugins/betterPinDMs/constants.ts | 25 ++- src/suncordplugins/betterPinDMs/data.ts | 50 ++++-- src/suncordplugins/betterPinDMs/index.tsx | 164 +++++++++++------- src/suncordplugins/betterPinDMs/styles.css | 15 +- 10 files changed, 265 insertions(+), 164 deletions(-) create mode 100644 src/suncordplugins/Anammox/README.md diff --git a/src/suncordplugins/Anammox/README.md b/src/suncordplugins/Anammox/README.md new file mode 100644 index 00000000..7914bd4b --- /dev/null +++ b/src/suncordplugins/Anammox/README.md @@ -0,0 +1,8 @@ +# Anammox + +Removes Nitro-exclusive stuff from various places: +- The shops above private chats +- The gift button in the chat box +- The "billing" section in settings + +While this can be done with css, a plugin is able to do it much more thorougly — for example, the shops are still accessible via keyboard navigation. diff --git a/src/suncordplugins/Anammox/index.ts b/src/suncordplugins/Anammox/index.ts index 938d9a45..25a7782a 100644 --- a/src/suncordplugins/Anammox/index.ts +++ b/src/suncordplugins/Anammox/index.ts @@ -1,11 +1,4 @@ -/* - * Vencord, a Discord client mod - * Copyright (c) 2024 Vendicated and contributors - * SPDX-License-Identifier: GPL-3.0-or-later - */ - import { definePluginSettings } from "@api/Settings"; -import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; export const settings = definePluginSettings({ @@ -38,7 +31,7 @@ export const settings = definePluginSettings({ export default definePlugin({ name: "Anammox", description: "A microbial process that plays an important part in the nitrogen cycle", - authors: [Devs.Kyuuhachi], + authors: [{ id: 236588665420251137n, name: "Kyuuhachi" }], settings, patches: [ @@ -97,7 +90,7 @@ export default definePlugin({ { // Emoji list find: "useEmojiGrid:function()", replacement: { - match: /(\w+)=\w+.default.isEmojiCategoryNitroLocked\(\{[^}]*\}\);/, + match: /(\w+)=!\w+&&\w+.default.isEmojiCategoryNitroLocked\(\{[^}]*\}\);/, replace: "$&$1||" }, predicate: () => settings.store.emojiList, diff --git a/src/suncordplugins/FastMenu/README.md b/src/suncordplugins/FastMenu/README.md index 904d346f..b7905063 100644 --- a/src/suncordplugins/FastMenu/README.md +++ b/src/suncordplugins/FastMenu/README.md @@ -1,14 +1,12 @@ # FastMenu - Several patches to speed up the loading of the main settings menu: - -- Remove the fade-zoom animation when opening it. -- Remove another animation for fading in the menu contents (why do they have two). -- Eagerly load the menu contents; without this the first time has an extra delay. +- Remove the fade-zoom animation when opening it. +- Remove another animation for fading in the menu contents (why do they have two). +- Eagerly load the menu contents; without this the first time has an extra delay. ### A note on themes -If you use a theme like _Modal settings window_, this plugin interferes with +If you use a theme like *Modal settings window*, this plugin interferes with that since it uses `visibility` instead of `opacity` to hide background layers. I'm undecided on whether to switch to `opacity` for compatibility or stick with `visibility` because that's the correct way to do it. diff --git a/src/suncordplugins/FastMenu/index.tsx b/src/suncordplugins/FastMenu/index.tsx index 9ef2693c..135c3d0e 100644 --- a/src/suncordplugins/FastMenu/index.tsx +++ b/src/suncordplugins/FastMenu/index.tsx @@ -1,12 +1,5 @@ -/* - * Vencord, a Discord client mod - * Copyright (c) 2024 Vendicated and contributors - * SPDX-License-Identifier: GPL-3.0-or-later - */ - import { definePluginSettings } from "@api/Settings"; import { classNameFactory } from "@api/Styles"; -import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy, wreq } from "@webpack"; import { ComponentDispatch, Forms, useEffect, useRef } from "@webpack/common"; @@ -21,21 +14,20 @@ const settings = definePluginSettings({ type: OptionType.BOOLEAN, default: true, onChange(val) { - if (val) eagerLoad(); + if(val) eagerLoad(); } }, }); const lazyLayers: string[] = []; function eagerLoad() { - // @ts-ignore lazyLayers.forEach(wreq.el); } export default definePlugin({ name: "FastMenu", description: "Makes the settings menu open faster.", - authors: [Devs.Kyuuhachi], + authors: [{ id: 236588665420251137n, name: "Kyuuhachi" }], settings, patches: [ @@ -62,16 +54,10 @@ export default definePlugin({ }, { // load menu stuff on hover, not on click find: "Messages.USER_SETTINGS_WITH_BUILD_OVERRIDE.format", - replacement: ((module_id: string) => [ - { - match: /handleOpenSettingsContextMenu.{0,250}?\i\.el\(("\d+")\)\.then/, - replace: (text, w) => (module_id = w, text) - }, - { - match: /(?<=Messages\.USER_SETTINGS,)/, - replace: () => `async onMouseEnter(){let r=Vencord.Webpack.wreq;await r.el(${module_id});r(${module_id});},`, - }, - ])(null as any), + replacement: { + match: /(?<=handleOpenSettingsContextMenu.{0,250}?\i\.el\(("\d+")\)\.then.*?Messages\.USER_SETTINGS,)(?=onClick:)/, + replace: "onMouseEnter(){let r=Vencord.Webpack.wreq;r.el($1).then(r.bind(r,$1));}," + }, predicate: () => settings.store.eagerLoad, }, ], @@ -97,18 +83,17 @@ export default definePlugin({ style={{ visibility: hidden ? "hidden" : "visible" }} {...props} />; - if (baseLayer) return node; - // @ts-ignore + if(baseLayer) return node; else return {node}; }, lazyLayer(moduleId: string, name: string) { - if (name !== "CollectiblesShop") + if(name !== "CollectiblesShop") lazyLayers.push(moduleId); }, start() { - if (settings.store.eagerLoad) + if(settings.store.eagerLoad) eagerLoad(); }, }); diff --git a/src/suncordplugins/betterPinDMs/components/CreateCategoryModal.tsx b/src/suncordplugins/betterPinDMs/components/CreateCategoryModal.tsx index 6cfd7f49..2a0e2cce 100644 --- a/src/suncordplugins/betterPinDMs/components/CreateCategoryModal.tsx +++ b/src/suncordplugins/betterPinDMs/components/CreateCategoryModal.tsx @@ -54,7 +54,7 @@ const useCategory = (categoryId: string | null, initalChannelId: string | null) id: Toasts.genId(), name: `Pin Category ${categories.length + 1}`, color: 10070709, - colapsed: false, + collapsed: false, channels: [initalChannelId] }); }, []); @@ -70,7 +70,8 @@ export function NewCategoryModal({ categoryId, modalProps, initalChannelId }: Pr if (!category) return null; - const onClick = async () => { + const onSave = async (e: React.FormEvent | React.MouseEvent) => { + e.preventDefault(); if (!categoryId) await createCategory(category); else @@ -86,41 +87,41 @@ export function NewCategoryModal({ categoryId, modalProps, initalChannelId }: Pr {categoryId ? "Edit" : "New"} Category - - - Name - setCategory({ ...category, name: e })} - /> - - - - - - Color - setCategory({ ...category, color: c! })} - value={category.color} - renderDefaultButton={() => null} - renderCustomButton={() => ( - setCategory({ ...category, color: c! })} - key={category.name} - showEyeDropper={false} - /> - )} - /> - - - - - - + {/* form is here so when you press enter while in the text input it submits */} +
+ + + Name + setCategory({ ...category, name: e })} + /> + + + + Color + setCategory({ ...category, color: c! })} + value={category.color} + renderDefaultButton={() => null} + renderCustomButton={() => ( + setCategory({ ...category, color: c! })} + key={category.name} + showEyeDropper={false} + /> + )} + /> + + + + + +
); } diff --git a/src/suncordplugins/betterPinDMs/components/contextMenu.tsx b/src/suncordplugins/betterPinDMs/components/contextMenu.tsx index 95710ac9..395a1fab 100644 --- a/src/suncordplugins/betterPinDMs/components/contextMenu.tsx +++ b/src/suncordplugins/betterPinDMs/components/contextMenu.tsx @@ -7,8 +7,8 @@ import { addContextMenuPatch, findGroupChildrenByChildId, NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu"; import { Menu } from "@webpack/common"; -import { forceUpdate } from ".."; -import { addChannelToCategory, categories, isPinned, removeChannelFromCategory } from "../data"; +import { addChannelToCategory, canMoveChannelInDirection, categories, isPinned, moveChannel, removeChannelFromCategory } from "../data"; +import { forceUpdate, settings } from "../index"; import { openCategoryModal } from "./CreateCategoryModal"; function PinMenuItem(channelId: string) { @@ -43,12 +43,34 @@ function PinMenuItem(channelId: string) { )} {pinned && ( - removeChannelFromCategory(channelId).then(() => forceUpdate())} - /> + <> + removeChannelFromCategory(channelId).then(() => forceUpdate())} + /> + + { + !settings.store.sortDmsByNewestMessage && canMoveChannelInDirection(channelId, -1) && ( + moveChannel(channelId, -1).then(() => forceUpdate())} + /> + ) + } + + { + !settings.store.sortDmsByNewestMessage && canMoveChannelInDirection(channelId, 1) && ( + moveChannel(channelId, 1).then(() => forceUpdate())} + /> + ) + } + )} diff --git a/src/suncordplugins/betterPinDMs/constants.ts b/src/suncordplugins/betterPinDMs/constants.ts index 87350d42..dec23047 100644 --- a/src/suncordplugins/betterPinDMs/constants.ts +++ b/src/suncordplugins/betterPinDMs/constants.ts @@ -5,4 +5,27 @@ */ export const DEFAULT_COLOR = 10070709; -export const SWATCHES = [1752220, 3066993, 3447003, 10181046, 15277667, 15844367, 15105570, 15158332, 9807270, 6323595, 1146986, 2067276, 2123412, 7419530, 11342935, 12745742, 11027200, 10038562, 9936031, 5533306]; + +export const SWATCHES = [ + 1752220, + 3066993, + 3447003, + 10181046, + 15277667, + 15844367, + 15105570, + 15158332, + 9807270, + 6323595, + + 1146986, + 2067276, + 2123412, + 7419530, + 11342935, + 12745742, + 11027200, + 10038562, + 9936031, + 5533306 +]; diff --git a/src/suncordplugins/betterPinDMs/data.ts b/src/suncordplugins/betterPinDMs/data.ts index e092b26a..8ad8d958 100644 --- a/src/suncordplugins/betterPinDMs/data.ts +++ b/src/suncordplugins/betterPinDMs/data.ts @@ -15,7 +15,7 @@ export interface Category { name: string; color: number; channels: string[]; - colapsed?: boolean; + collapsed?: boolean; } export const KEYS = { @@ -25,6 +25,7 @@ export const KEYS = { OLD_CATEGORY_KEY: "betterPinDmsCategories" }; + export let categories: Category[] = []; export async function saveCats(cats: Category[]) { @@ -33,7 +34,7 @@ export async function saveCats(cats: Category[]) { } export async function initCategories(userId: string) { - return categories = await DataStore.get(KEYS.CATEGORY_BASE_KEY + userId) ?? []; + categories = await DataStore.get(KEYS.CATEGORY_BASE_KEY + userId) ?? []; } export function getCategory(id: string) { @@ -85,23 +86,52 @@ export function isPinned(id: string) { return categories.some(c => c.channels.includes(id)); } -export const canMoveCategoryInDirection = (id: string, direction: -1 | 1) => { - const a = categories.map(m => m.id).indexOf(id); - const b = a + direction; +export const canMoveArrayInDirection = (array: any[], index: number, direction: -1 | 1) => { + const a = array[index]; + const b = array[index + direction]; - return categories[a] && categories[b]; + return a && b; +}; + +export const canMoveCategoryInDirection = (id: string, direction: -1 | 1) => { + const index = categories.findIndex(m => m.id === id); + return canMoveArrayInDirection(categories, index, direction); }; export const canMoveCategory = (id: string) => canMoveCategoryInDirection(id, -1) || canMoveCategoryInDirection(id, 1); +export const canMoveChannelInDirection = (channelId: string, direction: -1 | 1) => { + const category = categories.find(c => c.channels.includes(channelId)); + if (!category) return false; + + const index = category.channels.indexOf(channelId); + return canMoveArrayInDirection(category.channels, index, direction); +}; + + +function swapElementsInArray(array: any[], index1: number, index2: number) { + if (!array[index1] || !array[index2]) return; + [array[index1], array[index2]] = [array[index2], array[index1]]; +} + // stolen from PinDMs export async function moveCategory(id: string, direction: -1 | 1) { - const a = categories.map(m => m.id).indexOf(id); + const a = categories.findIndex(m => m.id === id); const b = a + direction; - if (!categories[a] || !categories[b]) return; + swapElementsInArray(categories, a, b); + + saveCats(categories); +} + +export async function moveChannel(channelId: string, direction: -1 | 1) { + const category = categories.find(c => c.channels.includes(channelId)); + if (!category) return; + + const a = category.channels.indexOf(channelId); + const b = a + direction; - [categories[a], categories[b]] = [categories[b], categories[a]]; + swapElementsInArray(category.channels, a, b); saveCats(categories); } @@ -110,7 +140,7 @@ export async function collapseCategory(id: string, value = true) { const category = categories.find(c => c.id === id); if (!category) return; - category.colapsed = value; + category.collapsed = value; saveCats(categories); } diff --git a/src/suncordplugins/betterPinDMs/index.tsx b/src/suncordplugins/betterPinDMs/index.tsx index 7710234d..87ca0989 100644 --- a/src/suncordplugins/betterPinDMs/index.tsx +++ b/src/suncordplugins/betterPinDMs/index.tsx @@ -6,27 +6,36 @@ import "./styles.css"; +import { definePluginSettings, Settings } from "@api/Settings"; import { Devs } from "@utils/constants"; import { classes } from "@utils/misc"; -import definePlugin from "@utils/types"; -import { findByPropsLazy, waitFor } from "@webpack"; +import definePlugin, { OptionType } from "@utils/types"; +import { findByPropsLazy, findStoreLazy, waitFor } from "@webpack"; import { Alerts, Button, ContextMenuApi, FluxDispatcher, Menu, React, UserStore } from "@webpack/common"; import { Channel } from "discord-types/general"; -import { Settings } from "Vencord"; import { addContextMenus, removeContextMenus } from "./components/contextMenu"; import { openCategoryModal, requireSettingsMenu } from "./components/CreateCategoryModal"; -import { canMoveCategory, canMoveCategoryInDirection, categories, initCategories, isPinned, migrateData, moveCategory, removeCategory } from "./data"; -import * as data from "./data"; +import { canMoveCategory, canMoveCategoryInDirection, categories, Category, collapseCategory, initCategories, isPinned, migrateData, moveCategory, removeCategory } from "./data"; + +interface ChannelComponentProps { + children: React.ReactNode, + channel: Channel, + selected: boolean; +} const headerClasses = findByPropsLazy("privateChannelsHeaderContainer"); +const PrivateChannelSortStore = findStoreLazy("PrivateChannelSortStore") as { getPrivateChannelIds: () => string[]; }; + export let instance: any; export const forceUpdate = () => instance?.props?._forceUpdate?.(); // the flux property in definePlugin doenst fire, probably because startAt isnt Init waitFor(["dispatch", "subscribe"], m => { m.subscribe("CONNECTION_OPEN", async () => { + if (!Settings.plugins.BetterPinDMs?.enabled) return; + const id = UserStore.getCurrentUser()?.id; await initCategories(id); await migrateData(); @@ -36,11 +45,26 @@ waitFor(["dispatch", "subscribe"], m => { }); +export const settings = definePluginSettings({ + sortDmsByNewestMessage: { + type: OptionType.BOOLEAN, + description: "Sort DMs by newest message", + default: false, + onChange: () => forceUpdate() + }, + + dmSectioncollapsed: { + type: OptionType.BOOLEAN, + description: "Collapse DM sections", + default: false, + } +}); export default definePlugin({ name: "BetterPinDMs", description: "Pin DMs but with categories", authors: [Devs.Aria, Devs.Ven, Devs.Strencher], + settings, patches: [ { @@ -49,28 +73,23 @@ export default definePlugin({ replacement: [ { match: /(?<=\i,{channels:\i,)privateChannelIds:(\i)/, - replace: "privateChannelIds:$1.filter(c=>!$self.isPinned(c)),pinCount2:$self.usePinCount($1)" + replace: "privateChannelIds:$1.filter(c=>!$self.isPinned(c))" }, { - match: /(renderRow:this\.renderRow,sections:)(\[\i,)Math.max\((\i)\.length,1\)/, - replace: "$1$self.sections = $2...this.props.pinCount2??[],Math.max($3.length,0)" + match: /(?<=renderRow:this\.renderRow,)sections:\[.+?1\)]/, + replace: "...$self.makeProps(this,{$&})" }, { - match: /\(\i,{},"no-private-channels"/, - replace: "(Vencord.Util.NoopComponent,{},\"no-private-channels\"" + match: /this\.renderDM=\(.+?(\i\.default),{channel.+?this.renderRow=(\i)=>{/, + replace: "$&if($self.isChannelIndex($2.section, $2.row))return $self.renderChannel($2.section,$2.row,$1);" }, { match: /this\.renderSection=(\i)=>{/, replace: "$&if($self.isCategoryIndex($1.section))return $self.renderCategory($1);" }, - // { - // match: /(this\.renderDM=\((\i),(\i)\)=>{.{1,200}this\.state,.{1,200})(\i\[\i\];return)/, - // replace: "$1$self.isCategoryIndex($2)?$self.getChannel($2,$3,this.props.channels):$4" - // }, { - - match: /(this\.renderDM=\((\i),(\i)\)=>{)(.{1,300}return null==\i.{1,20}\((\i\.default),{channel:)/, - replace: "$1if($self.isCategoryIndex($2))return $self.renderChannel(this,$2,$3,this.props.channels,$5);$4" + match: /(?<=span",{)className:\i\.headerText,/, + replace: "onClick: (e) => $self.collapseDMList(e),$&" }, { match: /(this\.getRowHeight=.{1,100}return 1===)(\i)/, @@ -84,20 +103,20 @@ export default definePlugin({ match: /this.getRowHeight=\((\i),(\i)\)=>{/, replace: "$&if($self.isChannelHidden($1,$2))return 0;" }, - - { - match: /this.getSectionHeight=(\i)=>{/, - replace: "$&if($self.isCategoryIndex($1))return 40;" - }, { // Copied from PinDMs // Override scrollToChannel to properly account for pinned channels match: /(?<=scrollTo\(\{to:\i\}\):\(\i\+=)(\d+)\*\(.+?(?=,)/, replace: "$self.getScrollOffset(arguments[0],$1,this.props.padding,this.state.preRenderedChildren,$&)" + }, + { + match: /(?<=scrollToChannel\(\i\){.{1,300})this\.props\.privateChannelIds/, + replace: "[...$&,...$self.getAllUncollapsedChannels()]" } ] }, + // forceUpdate moment // https://regex101.com/r/kDN9fO/1 { @@ -118,7 +137,7 @@ export default definePlugin({ // channelIds = __OVERLAY__ ? stuff : [...getStaticPaths(),...channelIds)] match: /(?<=\i=__OVERLAY__\?\i:\[\.\.\.\i\(\),\.\.\.)\i/, // ....concat(pins).concat(toArray(channelIds).filter(c => !isPinned(c))) - replace: "$self.getAllChannels().concat($&.filter(c=>!$self.isPinned(c)))" + replace: "$self.getAllUncollapsedChannels().concat($&.filter(c=>!$self.isPinned(c)))" } }, @@ -126,13 +145,13 @@ export default definePlugin({ // fix alt+shift+up/down { find: ".getFlattenedGuildIds()],", + predicate: () => !Settings.plugins.PinDMs?.enabled, replacement: { match: /(?<=\i===\i\.ME\?)\i\.\i\.getPrivateChannelIds\(\)/, - replace: "$self.getAllChannels().concat($&.filter(c=>!$self.isPinned(c)))" + replace: "$self.getAllUncollapsedChannels().concat($&.filter(c=>!$self.isPinned(c)))" } }, ], - data, sections: null as number[] | null, set _instance(i: any) { @@ -141,9 +160,6 @@ export default definePlugin({ }, isPinned, - forceUpdate() { - this.instance?.props?._forceUpdate?.(); - }, start() { if (Settings.plugins.PinDMs?.enabled) { @@ -173,22 +189,47 @@ export default definePlugin({ removeContextMenus(); }, - getSub() { - return Vencord.Settings.plugins.PinDMs.enabled ? 2 : 1; + makeProps(instance, { sections }: { sections: number[]; }) { + this.sections = sections; + + this.sections.splice(1, 0, ...this.usePinCount(instance.props.privateChannelIds || [])); + + if (this.instance?.props?.privateChannelIds?.length === 0) { + this.sections[this.sections.length - 1] = 0; + } + + return { + sections: this.sections, + chunkSize: this.getChunkSize(), + }; }, categoryLen() { return categories.length; }, + getChunkSize() { + return 256 + this.getSections().reduce((acc, v) => acc += v, 0) * 20; + }, + getAllChannels() { return categories.map(c => c.channels).flat(); }, + getAllUncollapsedChannels() { + return categories.filter(c => !c.collapsed).map(c => c.channels).flat(); + }, + usePinCount(channelIds: string[]) { return channelIds.length ? this.getSections() : []; }, + collapseDMList() { + // console.log("HI"); + settings.store.dmSectioncollapsed = !settings.store.dmSectioncollapsed; + forceUpdate(); + }, + getSections() { return categories.reduce((acc, category) => { acc.push(category.channels.length === 0 ? 1 : category.channels.length); @@ -197,45 +238,51 @@ export default definePlugin({ }, isCategoryIndex(sectionIndex: number) { - return this.sections && sectionIndex > (this.getSub() - 1) && sectionIndex < this.sections.length - 1; + return this.sections && sectionIndex > 0 && sectionIndex < this.sections.length - 1; }, isChannelIndex(sectionIndex: number, channelIndex: number) { - return this.sections && this.isCategoryIndex(sectionIndex) && categories[sectionIndex - this.getSub()]?.channels[channelIndex]; + if (settings.store.dmSectioncollapsed && sectionIndex !== 0) + return true; + return this.isCategoryIndex(sectionIndex) && categories[sectionIndex - 1]?.channels[channelIndex]; }, isChannelHidden(categoryIndex: number, channelIndex: number) { + if (categoryIndex === 0) return false; + + if (settings.store.dmSectioncollapsed && this.getSections().length + 1 === categoryIndex) + return true; if (!this.instance || !this.isChannelIndex(categoryIndex, channelIndex)) return false; + const category = categories[categoryIndex - 1]; if (!category) return false; - return category.colapsed && this.instance.props.selectedChannelId !== category.channels[channelIndex]; + return category.collapsed && this.instance.props.selectedChannelId !== category.channels[channelIndex]; }, getScrollOffset(channelId: string, rowHeight: number, padding: number, preRenderedChildren: number, originalOffset: number) { if (!isPinned(channelId)) return ( (rowHeight + padding) * 2 // header - + rowHeight * this.getAllChannels().length // pins + + rowHeight * this.getAllUncollapsedChannels().length // pins + originalOffset // original pin offset minus pins ); - return rowHeight * (this.getAllChannels().indexOf(channelId) + preRenderedChildren) + padding; + return rowHeight * (this.getAllUncollapsedChannels().indexOf(channelId) + preRenderedChildren) + padding; }, renderCategory({ section }: { section: number; }) { - const category = categories[section - this.getSub()]; - // console.log("renderCat", section, category); + const category = categories[section - 1]; if (!category) return null; return (

{ - await data.collapseCategory(category.id, !category.colapsed); - this.forceUpdate(); + await collapseCategory(category.id, !category.collapsed); + forceUpdate(); }} onContextMenu={e => { ContextMenuApi.openContextMenu(e, () => ( @@ -255,7 +302,7 @@ export default definePlugin({ id="vc-pindms-delete-category" color="danger" label="Delete Category" - action={() => removeCategory(category.id).then(() => this.forceUpdate())} + action={() => removeCategory(category.id).then(() => forceUpdate())} /> { @@ -270,14 +317,14 @@ export default definePlugin({ canMoveCategoryInDirection(category.id, -1) && moveCategory(category.id, -1).then(() => this.forceUpdate())} + action={() => moveCategory(category.id, -1).then(() => forceUpdate())} /> } { canMoveCategoryInDirection(category.id, 1) && moveCategory(category.id, 1).then(() => this.forceUpdate())} + action={() => moveCategory(category.id, 1).then(() => forceUpdate())} /> } @@ -292,32 +339,25 @@ export default definePlugin({ {category?.name ?? "uh oh"} - {/* - {category.channels.length} - */} -

); }, - // this is crazy - renderChannel(instance: any, sectionIndex: number, index: number, channels: Record, ChannelComponent: React.ComponentType<{ children: React.ReactNode, channel: Channel, selected: boolean; }>) { - const { channel, category } = this.getChannel(sectionIndex, index, channels); - // console.log("renderChannel", sectionIndex, index, channel); + renderChannel(sectionIndex: number, index: number, ChannelComponent: React.ComponentType) { + const { channel, category } = this.getChannel(sectionIndex, index, this.instance.props.channels); if (!channel || !category) return null; - const selected = instance.props.selectedChannelId === channel.id; + const selected = this.instance.props.selectedChannelId === channel.id; - if (!selected && category.colapsed) return null; + if (!selected && category.collapsed) return null; return ( {channel.id} @@ -325,11 +365,19 @@ export default definePlugin({ }, getChannel(sectionIndex: number, index: number, channels: Record) { - const category = categories[sectionIndex - this.getSub()]; - const channelId = category?.channels[index]; + const category = categories[sectionIndex - 1]; + if (!category) return { channel: null, category: null }; - // console.log("getChannel", sectionIndex, index, channelId); + const channelId = this.getCategoryChannels(category)[index]; return { channel: channels[channelId], category }; + }, + + getCategoryChannels(category: Category) { + if (settings.store.sortDmsByNewestMessage) { + return PrivateChannelSortStore.getPrivateChannelIds().filter(c => category?.channels?.includes(c)); + } + + return category?.channels ?? []; } }); diff --git a/src/suncordplugins/betterPinDMs/styles.css b/src/suncordplugins/betterPinDMs/styles.css index e5ed146c..9b3a301e 100644 --- a/src/suncordplugins/betterPinDMs/styles.css +++ b/src/suncordplugins/betterPinDMs/styles.css @@ -25,24 +25,17 @@ display: none; } -.vc-pindms-colapse-icon { +.vc-pindms-collapse-icon { width: 16px; height: 16px; color: var(--interactive-normal); transform: rotate(90deg) } -.vc-pindms-colapsed .vc-pindms-colapse-icon { +.vc-pindms-collapsed .vc-pindms-collapse-icon { transform: rotate(0deg); } -.vc-pindms-channel-count { - display: grid; - place-content: center; - border-radius: 8px; - background-color: var(--background-accent); - color: var(--white-500); - height: 16px; - min-width: 16px; - min-height: 16px; +[class^="privateChannelsHeaderContainer"] > [class^="headerText"] { + cursor: pointer; }