From ed56967e10ea998239b67fd6bced4ebf0e20bd4d Mon Sep 17 00:00:00 2001 From: brecert Date: Tue, 7 Sep 2021 10:51:46 -0400 Subject: [PATCH] Add the ability to hide the channel sidebar (the left one) --- src/components/navigation/LeftSidebar.tsx | 12 +++++--- src/pages/channels/Channel.tsx | 20 ++++++++++++ src/pages/channels/ChannelHeader.tsx | 14 +++++++-- src/pages/home/Home.tsx | 37 ++++++++++++++++++++++- 4 files changed, 76 insertions(+), 7 deletions(-) diff --git a/src/components/navigation/LeftSidebar.tsx b/src/components/navigation/LeftSidebar.tsx index 4561e5a5..d9787a2e 100644 --- a/src/components/navigation/LeftSidebar.tsx +++ b/src/components/navigation/LeftSidebar.tsx @@ -4,27 +4,31 @@ import SidebarBase from "./SidebarBase"; import HomeSidebar from "./left/HomeSidebar"; import ServerListSidebar from "./left/ServerListSidebar"; import ServerSidebar from "./left/ServerSidebar"; +import { useSelector } from "react-redux"; +import { State } from "../../redux"; export default function LeftSidebar() { + const isOpen = useSelector((state: State) => state.sectionToggle['sidebar_channels'] ?? true) + return ( - + {isOpen && } - + {isOpen && } - + {isOpen && } - + {isOpen && } diff --git a/src/pages/channels/Channel.tsx b/src/pages/channels/Channel.tsx index 0559cc4d..fd7ab919 100644 --- a/src/pages/channels/Channel.tsx +++ b/src/pages/channels/Channel.tsx @@ -49,10 +49,14 @@ export function Channel({ id }: { id: string }) { } const MEMBERS_SIDEBAR_KEY = "sidebar_members"; +const CHANNELS_SIDEBAR_KEY = "sidebar_channels"; const TextChannel = observer(({ channel }: { channel: ChannelI }) => { const [showMembers, setMembers] = useState( getState().sectionToggle[MEMBERS_SIDEBAR_KEY] ?? true, ); + const [showChannels, setChannels] = useState( + getState().sectionToggle[CHANNELS_SIDEBAR_KEY] ?? true, + ); const id = channel._id; return ( @@ -84,6 +88,22 @@ const TextChannel = observer(({ channel }: { channel: ChannelI }) => { }); } }} + toggleChannelSidebar={() => { + setChannels(!showChannels); + + if (showChannels) { + dispatch({ + type: "SECTION_TOGGLE_SET", + id: CHANNELS_SIDEBAR_KEY, + state: false, + }); + } else { + dispatch({ + type: "SECTION_TOGGLE_UNSET", + id: CHANNELS_SIDEBAR_KEY, + }); + } + }} /> diff --git a/src/pages/channels/ChannelHeader.tsx b/src/pages/channels/ChannelHeader.tsx index c69cbb5b..7ed07340 100644 --- a/src/pages/channels/ChannelHeader.tsx +++ b/src/pages/channels/ChannelHeader.tsx @@ -20,6 +20,7 @@ import HeaderActions from "./actions/HeaderActions"; export interface ChannelHeaderProps { channel: Channel; toggleSidebar?: () => void; + toggleChannelSidebar?: () => void; } const Info = styled.div` @@ -64,7 +65,16 @@ const Info = styled.div` } `; -export default observer(({ channel, toggleSidebar }: ChannelHeaderProps) => { +const IconConainer = styled.div` + cursor: pointer; + color: var(--secondary-foreground); + + &:hover { + color: var(--foreground); + } +` + +export default observer(({ channel, toggleSidebar, toggleChannelSidebar }: ChannelHeaderProps) => { const { openScreen } = useIntermediate(); const name = getChannelName(channel); @@ -88,7 +98,7 @@ export default observer(({ channel, toggleSidebar }: ChannelHeaderProps) => { return (
- {icon} + {icon} {name} {isTouchscreenDevice && diff --git a/src/pages/home/Home.tsx b/src/pages/home/Home.tsx index 73972e3d..bc961495 100644 --- a/src/pages/home/Home.tsx +++ b/src/pages/home/Home.tsx @@ -9,12 +9,47 @@ import Emoji from "../../components/common/Emoji"; import Tooltip from "../../components/common/Tooltip"; import Header from "../../components/ui/Header"; import CategoryButton from "../../components/ui/fluent/CategoryButton"; +import { dispatch, getState } from "../../redux"; +import { useState } from "preact/hooks"; +import styled from "styled-components"; + +const CHANNELS_SIDEBAR_KEY = "sidebar_channels"; + +const IconConainer = styled.div` + cursor: pointer; + color: var(--secondary-foreground); + + &:hover { + color: var(--foreground); + } +` export default function Home() { + const [showChannels, setChannels] = useState( + getState().sectionToggle[CHANNELS_SIDEBAR_KEY] ?? true, + ); + + const toggleChannelSidebar = () => { + setChannels(!showChannels); + + if (showChannels) { + dispatch({ + type: "SECTION_TOGGLE_SET", + id: CHANNELS_SIDEBAR_KEY, + state: false, + }); + } else { + dispatch({ + type: "SECTION_TOGGLE_UNSET", + id: CHANNELS_SIDEBAR_KEY, + }); + } + } + return (
- +