Skip to content

Commit

Permalink
prevent navigating to non-text channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Puyodead1 committed Jun 1, 2023
1 parent dd81402 commit eb962bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/components/ChannelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ function ChannelList() {
key={channel.id}
isCategory={isCategory}
onClick={() =>
navigate(`/channels/${guild.id}/${channel.id}`)
{
// prevent navigating to non-text channels
if (!channel.isTextChannel) return;

navigate(`/channels/${guild.id}/${channel.id}`)
}
}
>
<FirstWrapper isCategory={isCategory} active={active}>
Expand Down
18 changes: 17 additions & 1 deletion src/stores/objects/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
Snowflake as SnowflakeType,
} from "@spacebarchat/spacebar-api-types/v9";
import { ChannelType, Routes } from "@spacebarchat/spacebar-api-types/v9";
import { action, makeObservable, observable } from "mobx";
import { action, computed, makeObservable, observable } from "mobx";
import AppStore from "../AppStore";
import MessageStore from "../MessageStore";
import { APIError } from "../../utils/interfaces/api";
Expand Down Expand Up @@ -208,4 +208,20 @@ export default class Channel {

return true;
}

@computed
get isTextChannel() {
return (
this.type === ChannelType.GuildText ||
this.type === ChannelType.GuildStore ||
this.type === ChannelType.GuildForum ||
this.type === ChannelType.AnnouncementThread ||
this.type === ChannelType.Encrypted ||
this.type === ChannelType.EncryptedThread ||
this.type === ChannelType.PrivateThread ||
this.type === ChannelType.PublicThread ||
this.type === ChannelType.GroupDM ||
this.type === ChannelType.DM
);
}
}

0 comments on commit eb962bd

Please sign in to comment.