Skip to content

Commit

Permalink
Merge pull request #18 from siinghd/revert-17-dev
Browse files Browse the repository at this point in the history
Revert "Show the status of current user vote."
  • Loading branch information
siinghd authored Dec 26, 2023
2 parents b46d953 + 935f3af commit 75bdee6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 62 deletions.
3 changes: 0 additions & 3 deletions .prettierrc

This file was deleted.

10 changes: 0 additions & 10 deletions actions/question/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ export interface QuestionQuery {
image: boolean;
};
};
votes: {
where: {
userId: string | undefined,
},
select: {
userId: boolean,
value: boolean
},
}
// Add other fields as needed
};
where?: {
Expand Down Expand Up @@ -83,5 +74,4 @@ export interface ExtendedQuestion {
tags: string[];
updatedAt: Date;
author: Author;
votes: any[]
}
15 changes: 2 additions & 13 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default async function Home({
searchParams: QueryParams;
}) {
const session = await auth();
const sessionId = session?.user.id;

const getQuestionsWithQuery = async (
additionalQuery: Partial<QuestionQuery>
Expand All @@ -53,6 +52,7 @@ export default async function Home({
take: paginationData(searchParams).pageSize,
skip: paginationData(searchParams).skip,
};

const searchQuery = searchParams.search
? {
where: {
Expand All @@ -75,15 +75,6 @@ export default async function Home({
slug: true,
createdAt: true,
updatedAt: true,
votes: {
where: {
userId: sessionId,
},
select: {
userId: true,
value: true,
},
},
author: {
select: {
id: true,
Expand All @@ -99,7 +90,6 @@ export default async function Home({
...searchQuery,
...additionalQuery,
});

return { data, error: null };
} catch (error) {
const errorMessage =
Expand All @@ -120,7 +110,7 @@ export default async function Home({
response = await getQuestionsWithQuery({ orderBy: { createdAt: 'desc' } });
} else {
response = await getQuestionsWithQuery({
where: { authorId: sessionId },
where: { authorId: session?.user.id },
});
}

Expand Down Expand Up @@ -211,7 +201,6 @@ export default async function Home({
questionId={post.id}
enableLink={true}
reply={false}
votes={post.votes}
/>
))}
</div>
Expand Down
5 changes: 1 addition & 4 deletions components/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ interface IProps {
enableLink?: boolean;
isAnswer?: boolean;
questionId: string;
votes?: any[];
}
const isExtendedQuestion = (
post: ExtendedQuestion | Answer
Expand All @@ -46,7 +45,6 @@ const PostCard: React.FC<IProps> = ({
reply = false,
enableLink = false,
isAnswer = true,
votes,
}) => {
const [markDownValue, setMarkDownValue] = useState('');
const [enableReply, setEnableReply] = useState(false);
Expand Down Expand Up @@ -79,7 +77,7 @@ const PostCard: React.FC<IProps> = ({

const internalDetails = () => {
return (
<div className="w-full">
<div className='w-full'>
<div className="flex items-center justify-start gap-3 my-2">
<Avatar className="cursor-pointer">
<AvatarImage
Expand Down Expand Up @@ -171,7 +169,6 @@ const PostCard: React.FC<IProps> = ({
questionId={isAnswer ? undefined : post.id}
answerId={isAnswer ? post.id : undefined}
key={post.id}
votesArr={votes || []}
/>

<div className="flex flex-1 flex-row items-start justify-between w-full">
Expand Down
36 changes: 4 additions & 32 deletions components/form/form-vote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ import { updateVote } from '@/actions/vote';
import { toast } from 'sonner';
import { VoteBlock, VoteScore } from '../voteScore';
import { Minus, Plus } from 'lucide-react';
import clsx from 'clsx';
interface IVoteFormProps {
questionId: string | undefined;
answerId: string | undefined;
votes: number;
votesArr: any[];
}

const VoteForm: React.FC<IVoteFormProps> = ({
questionId,
answerId,
votes = 0,
votesArr,
}) => {
const { execute, fieldErrors, setFieldErrors } = useAction(updateVote, {
onSuccess: (data) => {
Expand All @@ -35,27 +32,12 @@ const VoteForm: React.FC<IVoteFormProps> = ({
const handleUpVote = () => {
execute({ value: 1, questionId, answerId });
};
const userVoted = Boolean(votesArr.length);
const userVoteVal = votesArr[0];

return (
<VoteScore className="w-[100px]">
<form id="vote-up" action={handleUpVote} className="w-full">
<VoteBlock
className={clsx(
`rounded-t-xl cursor-pointer bg-[#F3F4F6] duration-300 ease-in-out dark:bg-gray-900`,
userVoted && userVoteVal.value === 1
? 'opacity-20 cursor-not-allowed'
: 'hover:bg-gray-200 dark:hover:bg-gray-950'
)}
>
<button
className={clsx(
userVoted && userVoteVal.value === 1 ? 'cursor-not-allowed' : ''
)}
disabled={userVoted && userVoteVal.value === 1}
type="submit"
>
<VoteBlock className=" rounded-t-xl cursor-pointer bg-[#F3F4F6] hover:bg-gray-200 duration-300 ease-in-out dark:bg-gray-900 dark:hover:bg-gray-950">
<button type="submit">
<Plus size={20} />
</button>
</VoteBlock>
Expand All @@ -64,18 +46,8 @@ const VoteForm: React.FC<IVoteFormProps> = ({
{votes}
</VoteBlock>
<form id="vote-down" action={handleDownVote} className="w-full">
<VoteBlock
className={clsx(
'rounded-b-xl cursor-pointer bg-[#F3F4F6 duration-300 dark:bg-gray-900 ease-in-out',
userVoted && userVoteVal.value === -1
? 'opacity-20 cursor-not-allowed'
: 'hover:bg-gray-200 dark:hover:bg-gray-950'
)}
>
<button
disabled={userVoted && userVoteVal.value === -1}
type="submit"
>
<VoteBlock className="rounded-b-xl cursor-pointer bg-[#F3F4F6] hover:bg-gray-100 duration-300 dark:bg-gray-900 ease-in-out dark:hover:bg-gray-950">
<button type="submit">
<Minus size={20} />
</button>
</VoteBlock>
Expand Down

0 comments on commit 75bdee6

Please sign in to comment.