You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/web/src/routes/Main/Content/Group/Sidebar.tsx

62 lines
1.7 KiB
TypeScript

import React from 'react';
import {
GroupPanel,
GroupPanelType,
isValidStr,
useGroupInfo,
} from 'tailchat-shared';
import { useParams } from 'react-router';
import { GroupHeader } from './GroupHeader';
import { GroupSection } from '@/components/GroupSection';
import { GroupPanelItem } from '@/components/GroupPanelItem';
import { GroupTextPanelItem } from './TextPanelItem';
interface GroupParams {
groupId: string;
}
/**
*
*/
export const Sidebar: React.FC = React.memo(() => {
const { groupId } = useParams<GroupParams>();
const groupInfo = useGroupInfo(groupId);
const groupPanels = groupInfo?.panels ?? [];
const renderItem = (panel: GroupPanel) =>
panel.type === GroupPanelType.TEXT ? (
<GroupTextPanelItem groupId={groupId} panel={panel} />
) : (
<GroupPanelItem
name={panel.name}
icon={<div>#</div>}
to={`/main/group/${groupId}/${panel.id}`}
/>
);
return (
<div data-tc-role="sidebar-group">
<GroupHeader groupId={groupId} />
<div className="p-2 space-y-1">
{groupPanels
.filter((panel) => !isValidStr(panel.parentId))
.map((panel) =>
panel.type === GroupPanelType.GROUP ? (
<GroupSection key={panel.id} header={panel.name}>
{groupPanels
.filter((sub) => sub.parentId === panel.id)
.map((sub) => (
<div key={sub.id}>{renderItem(sub)}</div>
))}
</GroupSection>
) : (
<div key={panel.id}>{renderItem(panel)}</div>
)
)}
</div>
</div>
);
});
Sidebar.displayName = 'Sidebar';