Skip to content

Commit

Permalink
Added Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanmittal1163 committed Jun 26, 2024
0 parents commit d38fe92
Show file tree
Hide file tree
Showing 116 changed files with 15,767 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local
.env

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
4 changes: 4 additions & 0 deletions app/(auth)/(routes)/sign-in/[[...sign-in]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { SignIn } from '@clerk/nextjs';
export default function Page() {
return <SignIn />;
}
4 changes: 4 additions & 0 deletions app/(auth)/(routes)/sign-up/[[...sign-up]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { SignUp } from '@clerk/nextjs';
export default function Page() {
return <SignUp />;
}
9 changes: 9 additions & 0 deletions app/(auth)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function authLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<div className="flex items-center justify-center h-full">{children}</div>
);
}
47 changes: 47 additions & 0 deletions app/(invite)/(routes)/invite/[inviteCode]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { currentProfile } from '@/lib/currentProfile';
import { db } from '@/lib/db';
import { redirect } from 'next/navigation';

export default async function InviteCodePage({
params,
}: {
params: { inviteCode: string };
}) {
const profile = await currentProfile();
if (!profile) {
return redirect(`${process.env.NEXT_PUBLIC_APP_URL}/sign-in`);
}

if (!params.inviteCode) return redirect('/');

const existingUser = await db.server.findFirst({
where: {
inviteCode: params.inviteCode,
members: {
some: {
profileId: profile.id,
},
},
},
});

if (existingUser) return redirect(`/servers/${existingUser.id}`);

const server = await db.server.update({
where: {
inviteCode: params.inviteCode,
},
data: {
members: {
create: [
{
profileId: profile.id,
},
],
},
},
});

if (server) return redirect(`/servers/${server.id}`);
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { redirectToSignIn } from '@clerk/nextjs';
import { redirect } from 'next/navigation';
import { ChannelType } from '@prisma/client';

import { db } from '@/lib/db';
import { currentProfile } from '@/lib/currentProfile';
import ChatHeader from '@/components/chat/chat-header';
import { ChatInput } from '@/components/chat/chat-input';
import { ChatMessages } from '@/components/chat/chat-messages';
import { MediaRoom } from '@/components/media-room';

interface ChannelIdPageProps {
params: {
serverId: string;
channelId: string;
};
}

const ChannelIdPage = async ({ params }: ChannelIdPageProps) => {
const profile = await currentProfile();

if (!profile) {
return redirectToSignIn();
}

const channel = await db.channel.findUnique({
where: {
id: params.channelId,
},
});

const member = await db.member.findFirst({
where: {
serverId: params.serverId,
profileId: profile.id,
},
});

if (!channel || !member) {
redirect('/');
}

return (
<div className="bg-white dark:bg-[#313338] flex flex-col h-full">
<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 ChannelIdPage;
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { redirectToSignIn } from '@clerk/nextjs';
import { redirect } from 'next/navigation';

import { db } from '@/lib/db';
import { getOrCreateConversation } from '@/lib/conversation';
import { ChatMessages } from '@/components/chat/chat-messages';
import { ChatInput } from '@/components/chat/chat-input';
import { currentProfile } from '@/lib/currentProfile';
import ChatHeader from '@/components/chat/chat-header';
import { MediaRoom } from '@/components/media-room';

interface MemberIdPageProps {
params: {
memberId: string;
serverId: string;
};
searchParams: {
video?: boolean;
};
}

const MemberIdPage = async ({ params, searchParams }: MemberIdPageProps) => {
const profile = await currentProfile();

if (!profile) {
return redirectToSignIn();
}

const currentMember = await db.member.findFirst({
where: {
serverId: params.serverId,
profileId: profile.id,
},
include: {
profile: true,
},
});

if (!currentMember) {
return redirect('/');
}

const conversation = await getOrCreateConversation(
currentMember.id,
params.memberId
);

if (!conversation) {
return redirect(`/servers/${params.serverId}`);
}

const { memberOne, memberTwo } = conversation;

const otherMember =
memberOne.profileId === profile.id ? memberTwo : memberOne;

return (
<div className="bg-white dark:bg-[#313338] flex flex-col h-full">
<ChatHeader
imageUrl={otherMember.profile.imageUrl}
name={otherMember.profile.name}
serverId={params.serverId}
type="conversation"
/>

{searchParams.video && (
<MediaRoom chatId={conversation.id} video={true} audio={true} />
)}

{!searchParams.video && (
<>
<ChatMessages
member={currentMember}
name={otherMember.profile.name}
chatId={conversation.id}
type="conversation"
apiUrl="/api/direct-messages"
paramKey="conversationId"
paramValue={conversation.id}
socketUrl="/api/socket/direct-messages"
socketQuery={{
conversationId: conversation.id,
}}
/>
<ChatInput
name={otherMember.profile.name}
type="conversation"
apiUrl="/api/socket/direct-messages"
query={{
conversationId: conversation.id,
}}
/>
</>
)}
</div>
);
};

export default MemberIdPage;
35 changes: 35 additions & 0 deletions app/(main)/(routes)/servers/[serverId]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import ServerSidebar from '@/components/server/serverSidebar';
import { currentProfile } from '@/lib/currentProfile';
import { db } from '@/lib/db';
import { redirectToSignIn } from '@clerk/nextjs';
import { redirect } from 'next/navigation';

export default async function MainLayout({
children,
params,
}: {
children: React.ReactNode;
params: { serverId: string };
}) {
const profile = await currentProfile();
if (!profile) return redirectToSignIn();
const server = await db.server.findUnique({
where: {
id: params.serverId,
members: {
some: {
profileId: profile.id,
},
},
},
});
if (!server) redirect('/');
return (
<div className="h-full ">
<div className="hidden md:flex h-full w-60 z-20 flex-col fixed inset-y-0">
<ServerSidebar serverId={server.id} />
</div>
<main className="h-full md:pl-60">{children}</main>
</div>
);
}
Loading

0 comments on commit d38fe92

Please sign in to comment.