mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-06 17:11:55 +00:00
fix: handle invalid channels even when sidebar is closed
This commit is contained in:
@@ -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} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user