Skip to content

Commit

Permalink
Merge pull request #30 from thatbeautifuldream/main
Browse files Browse the repository at this point in the history
[FEAT] : Add Promise toasts to upvote and downvote
  • Loading branch information
siinghd authored Jan 5, 2024
2 parents f267cef + c7c4554 commit 728e881
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 0 additions & 2 deletions frontend/actions/message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ const rateLimit = (userId: string): boolean => {

const userLimiter = userRateLimits.get(userId) ?? { timestamps: [] };


userLimiter.timestamps = userLimiter.timestamps.filter(
timestamp => now.getTime() - timestamp.getTime() < interval
);

if (userLimiter.timestamps.length >= limit) {

return false;
}

Expand Down
3 changes: 1 addition & 2 deletions frontend/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export default function RootLayout({
<body className={inter.className}>
<Providers>
<NavBar />
<Toaster position="top-right" richColors />

<Toaster position="top-center" />
{children}
</Providers>
</body>
Expand Down
16 changes: 11 additions & 5 deletions frontend/components/form/form-vote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,25 @@ const VoteForm: React.FC<IVoteFormProps> = ({
}) => {
const { execute, fieldErrors, setFieldErrors } = useAction(updateVote, {
onSuccess: (data) => {
toast.success(
`Question has "${data?.upVotes}" up votes and "${data?.downVotes}" down votes Now`,
);
// toast(JSON.stringify(data));
},
onError: (error) => {
toast.error(error);
},
});
const handleDownVote = () => {
execute({ value: -1, questionId, answerId });
toast.promise(execute({ value: -1, questionId, answerId }), {
loading: 'Downvoting...',
success: 'Question has been downvoted.',
error: 'Error',
});
};
const handleUpVote = () => {
execute({ value: 1, questionId, answerId });
toast.promise(execute({ value: 1, questionId, answerId }), {
loading: 'Upvoting...',
success: 'Question has been upvoted.',
error: 'Error',
});
};

const userVoted = Boolean(votesArr.length);
Expand Down

0 comments on commit 728e881

Please sign in to comment.