mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-27 05:36:28 -05:00
Plus upvote/downvote from constant
This commit is contained in:
@@ -6,3 +6,6 @@ export const PlUS_SUGGESTION_FIRST_COMMENT_MAX_LENGTH = 500;
|
||||
export const PlUS_SUGGESTION_COMMENT_MAX_LENGTH = TWEET_LENGTH_MAX_LENGTH;
|
||||
|
||||
export const PLUS_TIERS = [1, 2, 3];
|
||||
|
||||
export const PLUS_UPVOTE = 1;
|
||||
export const PLUS_DOWNVOTE = -1;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as React from "react";
|
||||
import invariant from "tiny-invariant";
|
||||
import { PLUS_DOWNVOTE, PLUS_UPVOTE } from "~/constants";
|
||||
import type { UsersForVoting } from "~/db/models/plusVotes.server";
|
||||
import type { PlusVoteFromFE } from "./types";
|
||||
import { upcomingVoting } from "./voting-time";
|
||||
@@ -25,7 +26,7 @@ export function usePlusVoting(usersForVotingFromServer: UsersForVoting) {
|
||||
|
||||
const newVotes = [
|
||||
...votes,
|
||||
{ votedId, score: type === "upvote" ? 1 : -1 },
|
||||
{ votedId, score: type === "upvote" ? PLUS_UPVOTE : PLUS_DOWNVOTE },
|
||||
];
|
||||
|
||||
votesToLocalStorage({ usersForVoting, votes: newVotes });
|
||||
|
||||
@@ -198,12 +198,3 @@ function hasUserSuggestedThisMonth({
|
||||
suggestions[0] && suggestions[0].author.id === user?.id
|
||||
);
|
||||
}
|
||||
|
||||
export function canVoteFE() {
|
||||
return allTruthy([isVotingActive(), !alreadyVoted()]);
|
||||
}
|
||||
|
||||
// xxx: implement alreadyVoted()
|
||||
function alreadyVoted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { z } from "zod";
|
||||
import { Avatar } from "~/components/Avatar";
|
||||
import { Button } from "~/components/Button";
|
||||
import { RelativeTime } from "~/components/RelativeTime";
|
||||
import { PLUS_DOWNVOTE, PLUS_UPVOTE } from "~/constants";
|
||||
import { db } from "~/db";
|
||||
import type { UsersForVoting } from "~/db/models/plusVotes.server";
|
||||
import { getUser, requireUser } from "~/modules/auth";
|
||||
@@ -25,7 +26,7 @@ import { PlusSuggestionComments } from "../suggestions";
|
||||
|
||||
const voteSchema = z.object({
|
||||
votedId: z.number(),
|
||||
score: z.number().refine((val) => [-1, 1].includes(val)),
|
||||
score: z.number().refine((val) => [PLUS_DOWNVOTE, PLUS_UPVOTE].includes(val)),
|
||||
});
|
||||
|
||||
assertType<z.infer<typeof voteSchema>, PlusVoteFromFE>();
|
||||
@@ -48,7 +49,10 @@ export const action: ActionFunction = async ({ request }) => {
|
||||
validateVotes({ votes: data.votes, usersForVoting });
|
||||
|
||||
// freebie +1 for yourself if you vote
|
||||
const votesForDb = [...data.votes].concat({ votedId: user.id, score: 1 });
|
||||
const votesForDb = [...data.votes].concat({
|
||||
votedId: user.id,
|
||||
score: PLUS_UPVOTE,
|
||||
});
|
||||
|
||||
const { month, year } = upcomingVoting(new Date());
|
||||
const { endDate } = monthsVotingRange({ month, year });
|
||||
|
||||
Reference in New Issue
Block a user