import { ChannelType, MemberRole } from "@prisma/client";
import { redirect } from "next/navigation";
import { Hash, Mic, ShieldAlert, ShieldCheck, Video } from "lucide-react";
import { currentProfile } from "@/lib/current-profile";
import { db } from "@/lib/db";
import { ScrollArea } from "@/components/ui/scroll-area";
import { SeverHeader } from "./server-header";
import { ServerSearch } from "./server-search";
interface ServerSidebarProps {
serverId: string;
}
const iconMap = {
[ChannelType.TEXT]: ,
[ChannelType.AUDIO]: ,
[ChannelType.VIDEO]:
}
const roleIconMap = {
[MemberRole.GUEST]: null,
[MemberRole.MODERATOR]: ,
[MemberRole.ADMIN]:
}
export const ServerSidebar = async ({
serverId
}: ServerSidebarProps) => {
const profile = await currentProfile();
if (!profile) {
return redirect("/");
}
const server = await db.server.findUnique({
where: {
id: serverId,
},
include: {
channels: {
orderBy: {
createdAt: "asc",
},
},
members: {
include: {
profile: true,
},
orderBy: {
role: "asc",
}
},
}
});
const textChannels = server?.channels.filter((channel) => channel.type === ChannelType.TEXT)
const audioChannels = server?.channels.filter((channel) => channel.type === ChannelType.AUDIO)
const videoChannels = server?.channels.filter((channel) => channel.type === ChannelType.VIDEO)
const members = server?.members.filter((member) => member.profileId !== profile.id)
if (!server) {
return redirect("/");
}
const role = server.members.find((member) => member.profileId === profile.id)?.role;
return (
({
id: channel.id,
name: channel.name,
icon: iconMap[channel.type],
}))
},
{
label: "Voice Channels",
type: "channel",
data: audioChannels?.map((channel) => ({
id: channel.id,
name: channel.name,
icon: iconMap[channel.type],
}))
},
{
label: "Video Channels",
type: "channel",
data: videoChannels?.map((channel) => ({
id: channel.id,
name: channel.name,
icon: iconMap[channel.type],
}))
},
{
label: "Members",
type: "member",
data: members?.map((member) => ({
id: member.id,
name: member.profile.name,
icon: roleIconMap[member.role],
}))
},
]}
/>
)
}