fix: handle invalid channels even when sidebar is closed

This commit is contained in:
Paul
2021-12-25 13:20:20 +00:00
parent 59c993fefb
commit 22d5522e98
2 changed files with 18 additions and 13 deletions

View File

@@ -2,7 +2,7 @@ import { Hash } from "@styled-icons/boxicons-regular";
import { Ghost } from "@styled-icons/boxicons-solid";
import { reaction } from "mobx";
import { observer } from "mobx-react-lite";
import { useParams } from "react-router-dom";
import { Redirect, useParams } from "react-router-dom";
import { Channel as ChannelI } from "revolt.js/dist/maps/Channels";
import styled from "styled-components";
@@ -93,9 +93,21 @@ const PlaceholderBase = styled.div`
}
`;
export function Channel({ id }: { id: string }) {
export function Channel({ id, server_id }: { id: string; server_id: string }) {
const client = useClient();
const channel = client.channels.get(id);
if (server_id && !channel) {
const server = client.servers.get(server_id);
if (server && server.channel_ids.length > 0) {
return (
<Redirect
to={`/server/${server_id}/channel/${server.channel_ids[0]}`}
/>
);
}
}
if (!channel) return <ChannelPlaceholder />;
if (channel.channel_type === "VoiceChannel") {
@@ -198,6 +210,8 @@ function ChannelPlaceholder() {
}
export default function ChannelComponent() {
const { channel } = useParams<{ channel: string }>();
return <Channel id={channel} key={channel} />;
const { channel, server } =
useParams<{ channel: string; server: string }>();
return <Channel id={channel} server_id={server} key={channel} />;
}