Skip to content

Commit

Permalink
updated this branch to resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
zenithexe committed Sep 3, 2024
2 parents ff19b43 + 202b636 commit ab4cad0
Show file tree
Hide file tree
Showing 9 changed files with 485 additions and 82 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"bcrypt": "^5.1.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"cms": "file:",
"date-fns": "^3.6.0",
"dayjs": "^1.11.10",
"discord-oauth2": "^2.11.0",
Expand Down
43 changes: 21 additions & 22 deletions src/app/(main)/(pages)/question/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { getDisabledFeature, getUpdatedUrl, paginationData } from '@/lib/utils';
import db from '@/db';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import PostCard from '@/components/posts/PostCard';
import Pagination from '@/components/Pagination';
import { redirect } from 'next/navigation';
import QuestionHeader from '@/components/questions/QuestionPost';

type QuestionsResponse = {
data: ExtendedQuestion[] | null;
Expand All @@ -48,6 +48,7 @@ const getQuestionsWithQuery = async (
upvotes: true,
downvotes: true,
totalanswers: true,
content: true,
tags: true,
slug: true,
createdAt: true,
Expand Down Expand Up @@ -141,28 +142,37 @@ export default async function QuestionsPage({
<>
<div className="flex h-screen flex-col">
{/* Header */}
<div className="flex items-center justify-between p-5">
<div className="flex items-center gap-4 p-5">
<h1 className="bg-background/6 top-0 flex items-center text-3xl backdrop-blur-lg">
Questions
</h1>

<Search />
<Link
className="mb-2 me-2 rounded-lg bg-gradient-to-r from-blue-500 via-blue-600 to-blue-700 px-5 py-2.5 text-center text-sm font-medium text-white hover:bg-gradient-to-br"
href={getUpdatedUrl('/question', searchParams, {
newPost:
searchParams.newPost === 'close' || !searchParams.newPost
? 'open'
: 'close',
})}
>
New Question
</Link>
{/* Next question button */}
<NewPostDialog />
</div>

{/* Content Area */}
<div className="flex-1 overflow-y-auto pb-20">
{/* Next question button */}
<NewPostDialog />

<div className="mx-auto md:p-10 xl:mx-[15%]">
<div className="flex-col items-center justify-center p-4 dark:text-white">
<div className="flex items-center justify-between">
<div className="px-16">
<div className="mb-3 flex items-center justify-between">
<div className="flex gap-2">
<Search />
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button className="shrink-0" variant="outline">
<ArrowUpDownIcon className="mr-2 h-4 w-4" />
Sort by
<span className="hidden md:inline">Sort By</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-[200px]">
Expand Down Expand Up @@ -209,24 +219,13 @@ export default async function QuestionsPage({
</DropdownMenuContent>
</DropdownMenu>
</div>
<Link
className="mb-2 me-2 rounded-lg bg-gradient-to-r from-blue-500 via-blue-600 to-blue-700 px-5 py-2.5 text-center text-sm font-medium text-white hover:bg-gradient-to-br"
href={getUpdatedUrl('/question', searchParams, {
newPost:
searchParams.newPost === 'close' || !searchParams.newPost
? 'open'
: 'close',
})}
>
New Question
</Link>
</div>

{/* Chat */}
<div className="m-auto w-full">
<div className="w-full space-y-4">
{response?.data?.map((post) => (
<PostCard
<QuestionHeader
post={post}
sessionUser={session?.user}
key={post.id}
Expand Down
119 changes: 70 additions & 49 deletions src/app/questions/[slug]/@answers/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { getUpdatedUrl, paginationData } from '@/lib/utils';
import db from '@/db';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import PostCard from '@/components/posts/PostCard';
import Pagination from '@/components/Pagination';
import AnswerPost from '@/components/questions/AnswerPost';

const organizeAnswers = (
answers: Answer[],
Expand Down Expand Up @@ -105,58 +105,79 @@ const SingleAnswerPage = async ({
return (
<div className="pb-14 pt-14 md:mx-[15%]">
<div className="px-3">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button className="shrink-0" variant="outline">
<ArrowUpDownIcon className="mr-2 h-4 w-4" />
Sort by
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-[200px]">
<DropdownMenuRadioGroup value={tabType}>
<Link
href={getUpdatedUrl(`/questions/${params.slug}`, searchParams, {
tabtype: TabType.mu,
})}
>
<DropdownMenuRadioItem value={TabType.mu}>
Most Voted
</DropdownMenuRadioItem>
</Link>
<Link
href={getUpdatedUrl(`/questions/${params.slug}`, searchParams, {
tabtype: TabType.md,
})}
>
<DropdownMenuRadioItem value={TabType.md}>
Most Down Voted
</DropdownMenuRadioItem>
</Link>
<Link
href={getUpdatedUrl(`/questions/${params.slug}`, searchParams, {
tabtype: TabType.mr,
})}
>
<DropdownMenuRadioItem value={TabType.mr}>
Most Recent
</DropdownMenuRadioItem>
</Link>
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
{answers.length > 0 && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button className="shrink-0" variant="outline">
<ArrowUpDownIcon className="mr-2 h-4 w-4" />
Sort by
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-[200px]">
<DropdownMenuRadioGroup value={tabType}>
<Link
href={getUpdatedUrl(
`/questions/${params.slug}`,
searchParams,
{
tabtype: TabType.mu,
},
)}
>
<DropdownMenuRadioItem value={TabType.mu}>
Most Voted
</DropdownMenuRadioItem>
</Link>
<Link
href={getUpdatedUrl(
`/questions/${params.slug}`,
searchParams,
{
tabtype: TabType.md,
},
)}
>
<DropdownMenuRadioItem value={TabType.md}>
Most Down Voted
</DropdownMenuRadioItem>
</Link>
<Link
href={getUpdatedUrl(
`/questions/${params.slug}`,
searchParams,
{
tabtype: TabType.mr,
},
)}
>
<DropdownMenuRadioItem value={TabType.mr}>
Most Recent
</DropdownMenuRadioItem>
</Link>
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
)}
</div>
<div className="my-3 flex flex-col items-center justify-center gap-2 px-3">
<div className="flex flex-col gap-3">
{answers.map((post: any) => (
<PostCard
key={post.id}
questionId={post.questionId}
post={post}
sessionUser={session?.user}
reply={true}
/>
<div key={post.id} className="rounded-2xl px-8 pt-2">
<AnswerPost
key={post.id}
questionId={post.questionId}
post={post}
sessionUser={session?.user}
reply={true}
/>
</div>
))}
</div>
<Pagination dataLength={answers.length} />
{answers.length > 0 && <Pagination dataLength={answers.length} />}
{answers.length === 0 && (
<div className="text-2xl font-bold">
<h1>No Answers</h1>
</div>
)}
</div>
);
};
Expand Down
13 changes: 7 additions & 6 deletions src/app/questions/[slug]/@question/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import React from 'react';
import db from '@/db';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import PostCard from '@/components/posts/PostCard';
import Link from 'next/link';
import QuestionPost from '@/components/questions/QuestionPost';

const SingleQuestionPage = async ({
params,
Expand Down Expand Up @@ -50,18 +50,19 @@ const SingleQuestionPage = async ({

return (
<div className="mt-5 md:mx-[15%]">
<Link href="/questions" className="p-4">
<Link href="/question" className="p-4">
Go Back
</Link>
<div className="mt-3 items-center justify-center px-3">
{question && (
<PostCard
<QuestionPost
post={question}
sessionUser={session?.user}
reply={true}
questionId={question.id}
key={question.id}
isAnswer={false}
enableLink={false}
questionId={question.id}
enableLink={true}
reply={true}
/>
)}
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/app/questions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { getDisabledFeature, getUpdatedUrl, paginationData } from '@/lib/utils';
import db from '@/db';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import PostCard from '@/components/posts/PostCard';
import Pagination from '@/components/Pagination';
import { redirect } from 'next/navigation';
import QuestionPost from '@/components/questions/QuestionPost';

type QuestionsResponse = {
data: ExtendedQuestion[] | null;
Expand All @@ -47,6 +47,7 @@ const getQuestionsWithQuery = async (
title: true,
upvotes: true,
downvotes: true,
content: true,
totalanswers: true,
tags: true,
slug: true,
Expand Down Expand Up @@ -218,7 +219,7 @@ export default async function Home({
<div className="m-auto h-[500px] w-full overflow-y-scroll">
<div className="w-full space-y-4">
{response?.data?.map((post) => (
<PostCard
<QuestionPost
post={post}
sessionUser={session?.user}
key={post.id}
Expand Down
2 changes: 1 addition & 1 deletion src/components/posts/form/form-delete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const DeleteQAForm: React.FC<IVoteFormProps> = ({ questionId, answerId }) => {
onSuccess: (data) => {
toast.success(`${data.message}`);
if (questionId) {
router.push('/questions');
router.push('/question');
}
},
onError: (error) => {
Expand Down
Loading

0 comments on commit ab4cad0

Please sign in to comment.