mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-28 04:33:42 +08:00
[resumes][refactor] redirect user to signin on vote (#443)
Co-authored-by: Terence Ho <>
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
ArrowDownCircleIcon,
|
ArrowDownCircleIcon,
|
||||||
@ -21,6 +22,7 @@ export default function ResumeCommentVoteButtons({
|
|||||||
const [downvoteAnimation, setDownvoteAnimation] = useState(false);
|
const [downvoteAnimation, setDownvoteAnimation] = useState(false);
|
||||||
|
|
||||||
const trpcContext = trpc.useContext();
|
const trpcContext = trpc.useContext();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
// COMMENT VOTES
|
// COMMENT VOTES
|
||||||
const commentVotesQuery = trpc.useQuery([
|
const commentVotesQuery = trpc.useQuery([
|
||||||
@ -47,6 +49,11 @@ export default function ResumeCommentVoteButtons({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const onVote = async (value: Vote, setAnimation: (_: boolean) => void) => {
|
const onVote = async (value: Vote, setAnimation: (_: boolean) => void) => {
|
||||||
|
if (!userId) {
|
||||||
|
router.push('/api/auth/signin');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setAnimation(true);
|
setAnimation(true);
|
||||||
|
|
||||||
if (commentVotesQuery.data?.userVote?.value === value) {
|
if (commentVotesQuery.data?.userVote?.value === value) {
|
||||||
@ -74,7 +81,6 @@ export default function ResumeCommentVoteButtons({
|
|||||||
<>
|
<>
|
||||||
<button
|
<button
|
||||||
disabled={
|
disabled={
|
||||||
!userId ||
|
|
||||||
commentVotesQuery.isLoading ||
|
commentVotesQuery.isLoading ||
|
||||||
commentVotesUpsertMutation.isLoading ||
|
commentVotesUpsertMutation.isLoading ||
|
||||||
commentVotesDeleteMutation.isLoading
|
commentVotesDeleteMutation.isLoading
|
||||||
@ -103,7 +109,6 @@ export default function ResumeCommentVoteButtons({
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
disabled={
|
disabled={
|
||||||
!userId ||
|
|
||||||
commentVotesQuery.isLoading ||
|
commentVotesQuery.isLoading ||
|
||||||
commentVotesUpsertMutation.isLoading ||
|
commentVotesUpsertMutation.isLoading ||
|
||||||
commentVotesDeleteMutation.isLoading
|
commentVotesDeleteMutation.isLoading
|
||||||
|
Reference in New Issue
Block a user