|
|
|
@ -20,7 +20,7 @@ import { definePluginSettings } from "@api/Settings";
|
|
|
|
|
import { Devs } from "@utils/constants";
|
|
|
|
|
import definePlugin, { OptionType } from "@utils/types";
|
|
|
|
|
import { findByPropsLazy, findStoreLazy } from "@webpack";
|
|
|
|
|
import { FluxDispatcher, i18n } from "@webpack/common";
|
|
|
|
|
import { FluxDispatcher, i18n, useMemo } from "@webpack/common";
|
|
|
|
|
|
|
|
|
|
import FolderSideBar from "./FolderSideBar";
|
|
|
|
|
|
|
|
|
@ -117,8 +117,8 @@ export default definePlugin({
|
|
|
|
|
},
|
|
|
|
|
// If we are rendering the Better Folders sidebar, we filter out guilds that are not in folders and unexpanded folders
|
|
|
|
|
{
|
|
|
|
|
match: /(useStateFromStoresArray\).{0,25}let \i)=(\i\.\i.getGuildsTree\(\))/,
|
|
|
|
|
replace: (_, rest, guildsTree) => `${rest}=$self.getGuildTree(!!arguments[0].isBetterFolders,${guildsTree},arguments[0].betterFoldersExpandedIds)`
|
|
|
|
|
match: /\[(\i)\]=(\(0,\i\.useStateFromStoresArray\).{0,40}getGuildsTree\(\).+?}\))(?=,)/,
|
|
|
|
|
replace: (_, originalTreeVar, rest) => `[betterFoldersOriginalTree]=${rest},${originalTreeVar}=$self.getGuildTree(!!arguments[0].isBetterFolders,betterFoldersOriginalTree,arguments[0].betterFoldersExpandedIds)`
|
|
|
|
|
},
|
|
|
|
|
// If we are rendering the Better Folders sidebar, we filter out everything but the servers and folders from the GuildsBar Guild List children
|
|
|
|
|
{
|
|
|
|
@ -252,19 +252,21 @@ export default definePlugin({
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getGuildTree(isBetterFolders: boolean, oldTree: any, expandedFolderIds?: Set<any>) {
|
|
|
|
|
if (!isBetterFolders || expandedFolderIds == null) return oldTree;
|
|
|
|
|
getGuildTree(isBetterFolders: boolean, originalTree: any, expandedFolderIds?: Set<any>) {
|
|
|
|
|
return useMemo(() => {
|
|
|
|
|
if (!isBetterFolders || expandedFolderIds == null) return originalTree;
|
|
|
|
|
|
|
|
|
|
const newTree = new GuildsTree();
|
|
|
|
|
// Children is every folder and guild which is not in a folder, this filters out only the expanded folders
|
|
|
|
|
newTree.root.children = oldTree.root.children.filter(guildOrFolder => expandedFolderIds.has(guildOrFolder.id));
|
|
|
|
|
// Nodes is every folder and guild, even if it's in a folder, this filters out only the expanded folders and guilds inside them
|
|
|
|
|
newTree.nodes = Object.fromEntries(
|
|
|
|
|
Object.entries(oldTree.nodes)
|
|
|
|
|
.filter(([_, guildOrFolder]: any[]) => expandedFolderIds.has(guildOrFolder.id) || expandedFolderIds.has(guildOrFolder.parentId))
|
|
|
|
|
);
|
|
|
|
|
const newTree = new GuildsTree();
|
|
|
|
|
// Children is every folder and guild which is not in a folder, this filters out only the expanded folders
|
|
|
|
|
newTree.root.children = originalTree.root.children.filter(guildOrFolder => expandedFolderIds.has(guildOrFolder.id));
|
|
|
|
|
// Nodes is every folder and guild, even if it's in a folder, this filters out only the expanded folders and guilds inside them
|
|
|
|
|
newTree.nodes = Object.fromEntries(
|
|
|
|
|
Object.entries(originalTree.nodes)
|
|
|
|
|
.filter(([_, guildOrFolder]: any[]) => expandedFolderIds.has(guildOrFolder.id) || expandedFolderIds.has(guildOrFolder.parentId))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return newTree;
|
|
|
|
|
return newTree;
|
|
|
|
|
}, [isBetterFolders, originalTree, expandedFolderIds]);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
makeGuildsBarGuildListFilter(isBetterFolders: boolean) {
|
|
|
|
|