From 542c0482c57792025a0beb63f1d404c2d3f2e5cf Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Fri, 4 Mar 2022 16:45:44 +0000 Subject: [PATCH] fix: improve handling of inactive channels (closes #432) --- .../navigation/left/HomeSidebar.tsx | 19 ++++---- .../navigation/left/ServerListSidebar.tsx | 2 +- src/pages/channels/Channel.tsx | 44 +++++++++++-------- src/pages/friends/Friends.tsx | 1 + 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/components/navigation/left/HomeSidebar.tsx b/src/components/navigation/left/HomeSidebar.tsx index 7c1055e9..c391079d 100644 --- a/src/components/navigation/left/HomeSidebar.tsx +++ b/src/components/navigation/left/HomeSidebar.tsx @@ -5,7 +5,7 @@ import { Notepad, } from "@styled-icons/boxicons-solid"; import { observer } from "mobx-react-lite"; -import { Link, useLocation, useParams } from "react-router-dom"; +import { Link, Redirect, useLocation, useParams } from "react-router-dom"; import { RelationshipStatus } from "revolt-api/types/Users"; import styled, { css } from "styled-components/macro"; @@ -47,14 +47,16 @@ export default observer(() => { const { pathname } = useLocation(); const client = useContext(AppContext); const state = useApplicationState(); - const { channel: currentChannel } = useParams<{ channel: string }>(); + const { channel: channel_id } = useParams<{ channel: string }>(); const { openScreen } = useIntermediate(); const channels = [...client.channels.values()].filter( - (x) => x.channel_type === "DirectMessage" || x.channel_type === "Group", + (x) => + (x.channel_type === "DirectMessage" && x.active) || + x.channel_type === "Group", ); - const obj = client.channels.get(currentChannel); + const channel = client.channels.get(channel_id); // ! FIXME: move this globally // Track what page the user was last on (in home page). @@ -104,9 +106,10 @@ export default observer(() => { )} - + @@ -152,7 +155,7 @@ export default observer(() => { return ( { : undefined } alertCount={mentionCount} - active={channel._id === currentChannel} + active={channel._id === channel_id} /> ); diff --git a/src/components/navigation/left/ServerListSidebar.tsx b/src/components/navigation/left/ServerListSidebar.tsx index 7acbe3a9..ad742e0e 100644 --- a/src/components/navigation/left/ServerListSidebar.tsx +++ b/src/components/navigation/left/ServerListSidebar.tsx @@ -290,7 +290,7 @@ export default observer(() => { {channels .filter( (x) => - (x.channel_type === "DirectMessage" || + ((x.channel_type === "DirectMessage" && x.active) || x.channel_type === "Group") && x.unread, ) diff --git a/src/pages/channels/Channel.tsx b/src/pages/channels/Channel.tsx index cd550257..bba4d824 100644 --- a/src/pages/channels/Channel.tsx +++ b/src/pages/channels/Channel.tsx @@ -97,29 +97,35 @@ const PlaceholderBase = styled.div` } `; -export function Channel({ id, server_id }: { id: string; server_id: string }) { - const client = useClient(); - const channel = client.channels.get(id); +export const Channel = observer( + ({ id, server_id }: { id: string; server_id: string }) => { + const client = useClient(); - if (server_id && !channel) { - const server = client.servers.get(server_id); - if (server && server.channel_ids.length > 0) { - return ( - - ); + if (!client.channels.exists(id)) { + if (server_id) { + const server = client.servers.get(server_id); + if (server && server.channel_ids.length > 0) { + return ( + + ); + } + } else { + return ; + } + + return ; } - } - if (!channel) return ; + const channel = client.channels.get(id)!; + if (channel.channel_type === "VoiceChannel") { + return ; + } - if (channel.channel_type === "VoiceChannel") { - return ; - } - - return ; -} + return ; + }, +); const TextChannel = observer(({ channel }: { channel: ChannelI }) => { const layout = useApplicationState().layout; diff --git a/src/pages/friends/Friends.tsx b/src/pages/friends/Friends.tsx index 75c4a551..46215cdb 100644 --- a/src/pages/friends/Friends.tsx +++ b/src/pages/friends/Friends.tsx @@ -34,6 +34,7 @@ export default observer(() => { const friends = users.filter( (x) => x.relationship === RelationshipStatus.Friend, ); + const lists = [ [ "",