-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
14 changed files
with
328 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"typescript.enablePromptUseWorkspaceTsdk": true | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import prisma from '@/app/libs/prismadb' | ||
|
||
import getSession from './getSession' | ||
|
||
const getCurrentUser = async () => { | ||
try { | ||
const session = await getSession() | ||
|
||
if (!session?.user?.email) { | ||
return null | ||
} | ||
const currentUser = await prisma.user.findUnique({ | ||
where: { | ||
email: session.user.email as string, | ||
}, | ||
}) | ||
|
||
if (!currentUser) { | ||
return null | ||
} | ||
return currentUser | ||
} catch (error: any) { | ||
return null | ||
} | ||
} | ||
|
||
export default getCurrentUser |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { getServerSession } from 'next-auth' | ||
import { authOptions } from '../api/auth/[...nextauth]/route' | ||
|
||
export default async function getSession() { | ||
return await getServerSession(authOptions) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import prisma from '@/app/libs/prismadb' | ||
|
||
import getSession from './getSession' | ||
|
||
const getUsers = async () => { | ||
const session = await getSession() | ||
|
||
if (!session?.user?.email) { | ||
return [] | ||
} | ||
|
||
try { | ||
const users = await prisma.user.findMany({ | ||
orderBy: { | ||
createdAt: 'desc', | ||
}, | ||
where: { | ||
NOT: { | ||
email: session.user.email, | ||
}, | ||
}, | ||
}) | ||
|
||
return users | ||
} catch (error: any) { | ||
return [] | ||
} | ||
} | ||
|
||
export default getUsers |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use client' | ||
|
||
import { User } from '@prisma/client' | ||
import Image from 'next/image' | ||
|
||
interface AvatarProps { | ||
user?: User | ||
} | ||
|
||
const Avatar: React.FC<AvatarProps> = ({ user }) => { | ||
return ( | ||
<div className="relative"> | ||
<div className="relative inline-block rounded-full overflow-hidden h-9 w-9 md:h-11 md:w-11"> | ||
<Image | ||
alt="Avatar" | ||
src={user?.image || '/images/placeholder.jpeg'} | ||
fill | ||
/> | ||
</div> | ||
<span className="absolute block rounded-full bg-green-500 ring-2 ring-white top-0 right-0 h-2 w-2 md:h-3 md:w-3" /> | ||
</div> | ||
) | ||
} | ||
|
||
export default Avatar |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use client' | ||
|
||
import Avatar from '@/app/components/Avatar' | ||
import { User } from '@prisma/client' | ||
import axios from 'axios' | ||
import { useRouter } from 'next/navigation' | ||
import { useCallback, useState } from 'react' | ||
|
||
interface UserBoxProps { | ||
data: User | ||
} | ||
|
||
const UserBox: React.FC<UserBoxProps> = ({ data }) => { | ||
const router = useRouter() | ||
const [isLoading, setIsLoading] = useState(false) | ||
|
||
const handleClick = useCallback(() => { | ||
setIsLoading(true) | ||
|
||
axios | ||
.post('/api/conversations', { | ||
userId: data.id, | ||
}) | ||
.then((data) => router.push(`/conversations/${data.data.id}`)) | ||
.finally(() => setIsLoading(false)) | ||
}, [data, router]) | ||
return ( | ||
<div | ||
onClick={handleClick} | ||
className="w-full relative flex items-center space-x-3 bg-white p-3 hover:bg-neutral-100 rounded-lg transition cursor-pointer" | ||
> | ||
<Avatar user={data} /> | ||
<div className="min-w-0 flex-1"> | ||
<div className="focus:outline-none"> | ||
<div className="flex justify-between items-center mb-1"> | ||
<p className="font-medium text-gray-900">{data.name}</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default UserBox |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use client' | ||
|
||
import { User } from '@prisma/client' | ||
import UserBox from './UserBox' | ||
|
||
interface UserListProps { | ||
items: User[] | ||
} | ||
|
||
const UserList: React.FC<UserListProps> = ({ items }) => { | ||
return ( | ||
<aside className="fixed inset-y-0 pb-20 lg:pb-0 lg:left-20 lg:w-80 lg:block overflow-y-auto border-r border-gray-200 block w-full left-0"> | ||
<div className="px-5"> | ||
<div className="flex-col"> | ||
<div className="text-2xl font-bold text-neutral-800 py-4">People</div> | ||
</div> | ||
{items.map((item) => ( | ||
<UserBox key={item.id} data={item} /> | ||
))} | ||
</div> | ||
</aside> | ||
) | ||
} | ||
|
||
export default UserList |
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,14 +1,20 @@ | ||
import getUsers from '../actions/getUsers' | ||
import Sidebar from '../components/sidebar/Sidebar' | ||
import UserList from './components/UserList' | ||
|
||
export default async function UserLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
const users = await getUsers() | ||
return ( | ||
// @ts-expect-error Server Component | ||
<Sidebar> | ||
<div className="h-full">{children}</div> | ||
<div className="h-full"> | ||
<UserList items={users} /> | ||
{children} | ||
</div> | ||
</Sidebar> | ||
) | ||
} |
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,4 +1,12 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {} | ||
const nextConfig = { | ||
experimental: { | ||
appDir: true, | ||
swcPlugins: [['next-superjson-plugin', {}]], | ||
}, | ||
images: { | ||
domains: ['res.cloudinary.com', 'lh3.googleusercontent.com'], | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |
Oops, something went wrong.