fix: improve handling of inactive channels

(closes #432)
This commit is contained in:
Paul Makles 2022-03-04 16:45:44 +00:00
parent 041c039827
commit 542c0482c5
4 changed files with 38 additions and 28 deletions

View file

@ -5,7 +5,7 @@ import {
Notepad, Notepad,
} from "@styled-icons/boxicons-solid"; } from "@styled-icons/boxicons-solid";
import { observer } from "mobx-react-lite"; 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 { RelationshipStatus } from "revolt-api/types/Users";
import styled, { css } from "styled-components/macro"; import styled, { css } from "styled-components/macro";
@ -47,14 +47,16 @@ export default observer(() => {
const { pathname } = useLocation(); const { pathname } = useLocation();
const client = useContext(AppContext); const client = useContext(AppContext);
const state = useApplicationState(); const state = useApplicationState();
const { channel: currentChannel } = useParams<{ channel: string }>(); const { channel: channel_id } = useParams<{ channel: string }>();
const { openScreen } = useIntermediate(); const { openScreen } = useIntermediate();
const channels = [...client.channels.values()].filter( 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 // ! FIXME: move this globally
// Track what page the user was last on (in home page). // Track what page the user was last on (in home page).
@ -104,9 +106,10 @@ export default observer(() => {
</> </>
)} )}
<ConditionalLink <ConditionalLink
active={obj?.channel_type === "SavedMessages"} active={channel?.channel_type === "SavedMessages"}
to="/open/saved"> to="/open/saved">
<ButtonItem active={obj?.channel_type === "SavedMessages"}> <ButtonItem
active={channel?.channel_type === "SavedMessages"}>
<Notepad size={20} /> <Notepad size={20} />
<span> <span>
<Text id="app.navigation.tabs.saved" /> <Text id="app.navigation.tabs.saved" />
@ -152,7 +155,7 @@ export default observer(() => {
return ( return (
<ConditionalLink <ConditionalLink
key={channel._id} key={channel._id}
active={channel._id === currentChannel} active={channel._id === channel_id}
to={`/channel/${channel._id}`}> to={`/channel/${channel._id}`}>
<ChannelButton <ChannelButton
user={user} user={user}
@ -165,7 +168,7 @@ export default observer(() => {
: undefined : undefined
} }
alertCount={mentionCount} alertCount={mentionCount}
active={channel._id === currentChannel} active={channel._id === channel_id}
/> />
</ConditionalLink> </ConditionalLink>
); );

View file

@ -290,7 +290,7 @@ export default observer(() => {
{channels {channels
.filter( .filter(
(x) => (x) =>
(x.channel_type === "DirectMessage" || ((x.channel_type === "DirectMessage" && x.active) ||
x.channel_type === "Group") && x.channel_type === "Group") &&
x.unread, x.unread,
) )

View file

@ -97,29 +97,35 @@ const PlaceholderBase = styled.div`
} }
`; `;
export function Channel({ id, server_id }: { id: string; server_id: string }) { export const Channel = observer(
const client = useClient(); ({ id, server_id }: { id: string; server_id: string }) => {
const channel = client.channels.get(id); const client = useClient();
if (server_id && !channel) { if (!client.channels.exists(id)) {
const server = client.servers.get(server_id); if (server_id) {
if (server && server.channel_ids.length > 0) { const server = client.servers.get(server_id);
return ( if (server && server.channel_ids.length > 0) {
<Redirect return (
to={`/server/${server_id}/channel/${server.channel_ids[0]}`} <Redirect
/> to={`/server/${server_id}/channel/${server.channel_ids[0]}`}
); />
);
}
} else {
return <Redirect to="/" />;
}
return <ChannelPlaceholder />;
} }
}
if (!channel) return <ChannelPlaceholder />; const channel = client.channels.get(id)!;
if (channel.channel_type === "VoiceChannel") {
return <VoiceChannel channel={channel} />;
}
if (channel.channel_type === "VoiceChannel") { return <TextChannel channel={channel} />;
return <VoiceChannel channel={channel} />; },
} );
return <TextChannel channel={channel} />;
}
const TextChannel = observer(({ channel }: { channel: ChannelI }) => { const TextChannel = observer(({ channel }: { channel: ChannelI }) => {
const layout = useApplicationState().layout; const layout = useApplicationState().layout;

View file

@ -34,6 +34,7 @@ export default observer(() => {
const friends = users.filter( const friends = users.filter(
(x) => x.relationship === RelationshipStatus.Friend, (x) => x.relationship === RelationshipStatus.Friend,
); );
const lists = [ const lists = [
[ [
"", "",