mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-26 00:50:56 -05:00
fix: handle invalid channels even when sidebar is closed
This commit is contained in:
parent
d7f52fb6f4
commit
56126fa303
2 changed files with 18 additions and 13 deletions
|
@ -59,15 +59,6 @@ export default observer(() => {
|
||||||
|
|
||||||
const channel = channel_id ? client.channels.get(channel_id) : undefined;
|
const channel = channel_id ? client.channels.get(channel_id) : undefined;
|
||||||
|
|
||||||
// The user selected no channel, let's see if there's a channel available
|
|
||||||
if (!channel && server.channel_ids.length > 0)
|
|
||||||
return (
|
|
||||||
<Redirect
|
|
||||||
to={`/server/${server_id}/channel/${server.channel_ids[0]}`}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
if (channel_id && !channel) return <Redirect to={`/server/${server_id}`} />;
|
|
||||||
|
|
||||||
// ! FIXME: move this globally
|
// ! FIXME: move this globally
|
||||||
// Track which channel the user was last on.
|
// Track which channel the user was last on.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Hash } from "@styled-icons/boxicons-regular";
|
||||||
import { Ghost } from "@styled-icons/boxicons-solid";
|
import { Ghost } from "@styled-icons/boxicons-solid";
|
||||||
import { reaction } from "mobx";
|
import { reaction } from "mobx";
|
||||||
import { observer } from "mobx-react-lite";
|
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 { Channel as ChannelI } from "revolt.js/dist/maps/Channels";
|
||||||
import styled from "styled-components";
|
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 client = useClient();
|
||||||
const channel = client.channels.get(id);
|
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) return <ChannelPlaceholder />;
|
||||||
|
|
||||||
if (channel.channel_type === "VoiceChannel") {
|
if (channel.channel_type === "VoiceChannel") {
|
||||||
|
@ -198,6 +210,8 @@ function ChannelPlaceholder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ChannelComponent() {
|
export default function ChannelComponent() {
|
||||||
const { channel } = useParams<{ channel: string }>();
|
const { channel, server } =
|
||||||
return <Channel id={channel} key={channel} />;
|
useParams<{ channel: string; server: string }>();
|
||||||
|
|
||||||
|
return <Channel id={channel} server_id={server} key={channel} />;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue