/* * Vencord, a modification for Discord's desktop app * Copyright (c) 2023 Vendicated and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import ErrorBoundary from "@components/ErrorBoundary"; import { findComponentByCodeLazy } from "@webpack"; import { Animations, ChannelRTCStore, useStateFromStores } from "@webpack/common"; import type { CSSProperties } from "react"; import { ExpandedGuildFolderStore, settings, SortedGuildStore } from "."; const GuildsBar = findComponentByCodeLazy('("guildsnav")'); function getExpandedFolderIds() { const expandedFolders = ExpandedGuildFolderStore.getExpandedFolders(); const folders = SortedGuildStore.getGuildFolders(); const expandedFolderIds = new Set(); for (const folder of folders) { if (expandedFolders.has(folder.folderId) && folder.guildIds?.length) { expandedFolderIds.add(folder.folderId); } } return expandedFolderIds; } export default ErrorBoundary.wrap(guildsBarProps => { const expandedFolderIds = useStateFromStores([ExpandedGuildFolderStore, SortedGuildStore], () => getExpandedFolderIds()); const isFullscreen = useStateFromStores([ChannelRTCStore], () => ChannelRTCStore.isFullscreenInContext()); const Sidebar = ( ); const visible = !!expandedFolderIds.size; const guilds = document.querySelector(guildsBarProps.className.split(" ").map(c => `.${c}`).join("")); // We need to display none if we are in fullscreen. Yes this seems horrible doing with css, but it's literally how Discord does it. // Also display flex otherwise to fix scrolling. const sidebarStyle = { display: isFullscreen ? "none" : "flex" } satisfies CSSProperties; if (!guilds || !settings.store.sidebarAnim) { return visible ?
{Sidebar}
: null; } return ( {(animationStyle: any, show: any) => show && ( {Sidebar} ) } ); }, { noop: true });