-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e63d04c
commit 291edd4
Showing
8 changed files
with
281 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,19 @@ | ||
import { redirectToSignIn } from '@clerk/nextjs/server'; | ||
import { redirect } from 'next/navigation'; | ||
import { NextPage } from 'next'; | ||
|
||
import { currentProfile } from '@/common/libs/current-profile'; | ||
import { db } from '@/common/libs/db'; | ||
import Servers from '@/modules/Servers'; | ||
|
||
interface ServerIdPageProps { | ||
params: { | ||
serverId: string; | ||
}; | ||
} | ||
|
||
const ServerIdPage = async ({ params }: ServerIdPageProps) => { | ||
const profile = await currentProfile(); | ||
|
||
if (!profile) { | ||
return redirectToSignIn(); | ||
} | ||
|
||
const server = await db.server.findUnique({ | ||
where: { | ||
id: params.serverId, | ||
members: { | ||
some: { | ||
profileId: profile.id, | ||
}, | ||
}, | ||
}, | ||
include: { | ||
channels: { | ||
where: { | ||
name: '一般频道', | ||
}, | ||
orderBy: { | ||
createdAt: 'asc', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const initialChannel = server?.channels[0]; | ||
|
||
if (initialChannel?.name !== '一般频道') { | ||
return null; | ||
} | ||
|
||
return redirect(`/servers/${params.serverId}/channels/${initialChannel?.id}`); | ||
const Page: NextPage<ServerIdPageProps> = ({ params }) => { | ||
return ( | ||
<> | ||
<Servers serverId={params.serverId} /> | ||
</> | ||
); | ||
}; | ||
|
||
export default ServerIdPage; | ||
export default Page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,19 @@ | ||
import { redirect } from 'next/navigation'; | ||
import { NextPage } from 'next'; | ||
|
||
import { InitialModal } from '@/common/components/modals/initial-modal'; | ||
import { db } from '@/common/libs/db'; | ||
import { initialProfile } from '@/common/libs/initial-profile'; | ||
import SetUp from '@/modules/SetUp'; | ||
|
||
const SetupPage = async () => { | ||
const profile = await initialProfile(); | ||
interface InviteCodePageProps { | ||
params: { | ||
inviteCode: string; | ||
}; | ||
} | ||
|
||
const server = await db.server.findFirst({ | ||
where: { | ||
members: { | ||
some: { | ||
profileId: profile.id, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
if (server) { | ||
return redirect(`/servers/${server.id}`); | ||
} | ||
|
||
return <InitialModal />; | ||
const Page: NextPage<InviteCodePageProps> = ({ params }) => { | ||
return ( | ||
<> | ||
<SetUp /> | ||
</> | ||
); | ||
}; | ||
|
||
export default SetupPage; | ||
export default Page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,85 @@ | ||
import { SignIn as ClerkSignIn } from '@clerk/nextjs'; | ||
import { redirectToSignIn } from '@clerk/nextjs/server'; | ||
import { ChannelType } from '@prisma/client'; | ||
import { redirect } from 'next/navigation'; | ||
|
||
const Channels: React.FC = () => { | ||
return <ClerkSignIn />; | ||
import { ChatHeader } from '@/common/components/chat/chat-header'; | ||
import { ChatInput } from '@/common/components/chat/chat-input'; | ||
import { ChatMessages } from '@/common/components/chat/chat-messages'; | ||
import { MediaRoom } from '@/common/components/elements/media-room'; | ||
import { currentProfile } from '@/common/libs/current-profile'; | ||
import { db } from '@/common/libs/db'; | ||
|
||
interface ChannelProps { | ||
serverId: string; | ||
channelId: string; | ||
} | ||
|
||
const Channels: React.FC<ChannelProps> = async ({ serverId, channelId }) => { | ||
const profile = await currentProfile(); | ||
|
||
if (!profile) { | ||
return redirectToSignIn(); | ||
} | ||
|
||
const channel = await db.channel.findUnique({ | ||
where: { | ||
id: channelId, | ||
}, | ||
}); | ||
|
||
const member = await db.member.findFirst({ | ||
where: { | ||
serverId: serverId, | ||
profileId: profile.id, | ||
}, | ||
}); | ||
|
||
if (!channel || !member) { | ||
redirect('/'); | ||
} | ||
|
||
return ( | ||
<div className="flex h-full flex-col bg-white dark:bg-[#313338]"> | ||
<ChatHeader | ||
name={channel.name} | ||
serverId={channel.serverId} | ||
type="channel" | ||
/> | ||
{channel.type === ChannelType.TEXT && ( | ||
<> | ||
<ChatMessages | ||
member={member} | ||
name={channel.name} | ||
chatId={channel.id} | ||
type="channel" | ||
apiUrl="/api/messages" | ||
socketUrl="/api/socket/messages" | ||
socketQuery={{ | ||
channelId: channel.id, | ||
serverId: channel.serverId, | ||
}} | ||
paramKey="channelId" | ||
paramValue={channel.id} | ||
/> | ||
<ChatInput | ||
name={channel.name} | ||
type="channel" | ||
apiUrl="/api/socket/messages" | ||
query={{ | ||
channelId: channel.id, | ||
serverId: channel.serverId, | ||
}} | ||
/> | ||
</> | ||
)} | ||
{channel.type === ChannelType.AUDIO && ( | ||
<MediaRoom chatId={channel.id} video={false} audio={true} /> | ||
)} | ||
{channel.type === ChannelType.VIDEO && ( | ||
<MediaRoom chatId={channel.id} video={true} audio={true} /> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Channels; |
Oops, something went wrong.