-
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.
Merge pull request #42 from vishalkondle45/feature/forum
feat: saved in forums
- Loading branch information
Showing
9 changed files
with
127 additions
and
38 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
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,36 @@ | ||
'use client'; | ||
|
||
import { Button, Group, Stack, Title } from '@mantine/core'; | ||
import { useDisclosure, useMediaQuery } from '@mantine/hooks'; | ||
import { ForumItem, AskQuestion } from '@/components/Forum'; | ||
import useFetchData from '@/hooks/useFetchData'; | ||
import { ForumType } from '@/components/Forum/Forum.types'; | ||
import Skelton from '@/components/Skelton/Skelton'; | ||
|
||
const ForumPage = () => { | ||
const { data: forums, loading } = useFetchData('/api/forums/saved'); | ||
const [opened, { open, close }] = useDisclosure(false); | ||
const isMobile = useMediaQuery('(max-width: 768px)'); | ||
|
||
return ( | ||
<> | ||
<Group mb="md" justify="space-between"> | ||
<Title>Saved</Title> | ||
<Button onClick={open}>Ask Question</Button> | ||
</Group> | ||
<Stack> | ||
{loading ? ( | ||
<Skelton items={6} height={90} /> | ||
) : ( | ||
Array.isArray(forums) && | ||
forums?.map((forum: ForumType) => ( | ||
<ForumItem key={String(forum._id)} forum={forum} isMobile={isMobile} /> | ||
)) | ||
)} | ||
</Stack> | ||
<AskQuestion opened={opened} close={close} /> | ||
</> | ||
); | ||
}; | ||
|
||
export default ForumPage; |
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,31 @@ | ||
import { getServerSession } from 'next-auth'; | ||
import { NextResponse } from 'next/server'; | ||
import startDb from '@/lib/db'; | ||
import Forum from '@/models/Forum'; | ||
import { authOptions } from '../../auth/[...nextauth]/authOptions'; | ||
import { UserDataTypes } from '../../auth/[...nextauth]/next-auth.interfaces'; | ||
|
||
export const maxDuration = 60; | ||
export const dynamic = 'force-dynamic'; | ||
|
||
export async function GET() { | ||
try { | ||
const session: UserDataTypes | null = await getServerSession(authOptions); | ||
if (!session?.user) { | ||
return NextResponse.json({ error: 'You are not authorized' }, { status: 401 }); | ||
} | ||
await startDb(); | ||
|
||
const forums = await Forum.find({ | ||
question: { $exists: true }, | ||
description: { $exists: true }, | ||
saved: session?.user._id, | ||
}) | ||
.populate({ path: 'user', select: 'name' }) | ||
.sort('-updatedAt'); | ||
|
||
return NextResponse.json(forums, { status: 200 }); | ||
} catch (error: any) { | ||
return NextResponse.json({ error: error?.message }, { status: 500 }); | ||
} | ||
} |
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