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..265fe824 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,26 @@ const TextChannel = observer(({ channel }: { channel: ChannelI }) => { }); } }} + toggleChannelSidebar={() => { + if (isTouchscreenDevice) { + return + } + + 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..84f188af 100644 --- a/src/pages/channels/ChannelHeader.tsx +++ b/src/pages/channels/ChannelHeader.tsx @@ -3,7 +3,7 @@ import { Notepad, Group } from "@styled-icons/boxicons-solid"; import { observer } from "mobx-react-lite"; import { Channel } from "revolt.js/dist/maps/Channels"; import { User } from "revolt.js/dist/maps/Users"; -import styled from "styled-components"; +import styled, { css } from "styled-components"; import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice"; @@ -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,18 @@ const Info = styled.div` } `; -export default observer(({ channel, toggleSidebar }: ChannelHeaderProps) => { +const IconConainer = styled.div` + cursor: pointer; + color: var(--secondary-foreground); + + ${!isTouchscreenDevice && css` + &:hover { + color: var(--foreground); + } + `} +` + +export default observer(({ channel, toggleSidebar, toggleChannelSidebar }: ChannelHeaderProps) => { const { openScreen } = useIntermediate(); const name = getChannelName(channel); @@ -88,7 +100,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..9d54c541 100644 --- a/src/pages/home/Home.tsx +++ b/src/pages/home/Home.tsx @@ -9,12 +9,54 @@ 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, { css } from "styled-components"; +import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice"; + +const CHANNELS_SIDEBAR_KEY = "sidebar_channels"; + +const IconConainer = styled.div` + cursor: pointer; + color: var(--secondary-foreground); + + ${!isTouchscreenDevice && css` + &:hover { + color: var(--foreground); + } + `} +` export default function Home() { + const [showChannels, setChannels] = useState( + getState().sectionToggle[CHANNELS_SIDEBAR_KEY] ?? true, + ); + + const toggleChannelSidebar = () => { + if (isTouchscreenDevice) { + return + } + + 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 (
- +