Skip to content

Commit

Permalink
re-add useCallback on channel list render (but without crashes)
Browse files Browse the repository at this point in the history
  • Loading branch information
Puyodead1 committed Sep 1, 2023
1 parent 2e07591 commit e685d93
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/components/ChannelList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ChannelType } from "@spacebarchat/spacebar-api-types/v9";
import { observer } from "mobx-react-lite";
import React from "react";
import styled from "styled-components";
import { useAppStore } from "../stores/AppStore";
import Channel from "../stores/objects/Channel";
import Guild from "../stores/objects/Guild";
import { Permissions } from "../utils/Permissions";
import ChannelListItem from "./ChannelListItem";
Expand All @@ -27,26 +29,27 @@ function ChannelList({ channelId, guild }: Props) {
const app = useAppStore();
if (!guild) return <EmptyChannelList />;

return (
<List>
{guild.channels.mapped.map((channel) => {
const permission = Permissions.getPermission(app.account!.id, guild, channel);
if (!permission.has("VIEW_CHANNEL")) return null;

const active = channelId === channel.id;
const isCategory = channel.type === ChannelType.GuildCategory;
return (
<ChannelListItem
key={channel.id}
guild={guild}
channel={channel}
isCategory={isCategory}
active={active}
/>
);
})}
</List>
const renderChannelListItem = React.useCallback(
(channel: Channel) => {
const permission = Permissions.getPermission(app.account!.id, guild, channel);
if (!permission.has("VIEW_CHANNEL")) return null;

const active = channelId === channel.id;
const isCategory = channel.type === ChannelType.GuildCategory;
return (
<ChannelListItem
key={channel.id}
guild={guild}
channel={channel}
isCategory={isCategory}
active={active}
/>
);
},
[app.account, channelId, guild],
);

return <List>{guild.channels.mapped.map((channel) => renderChannelListItem(channel))}</List>;
}

export default observer(ChannelList);

0 comments on commit e685d93

Please sign in to comment.