new logic in lottery and toss route
This commit is contained in:
parent
f68e76c4b4
commit
7b5db124da
15
api/index.ts
15
api/index.ts
|
|
@ -1,12 +1,9 @@
|
||||||
"use server";
|
"use server";
|
||||||
import baseUrl from "@/baseUrl";
|
import baseUrl from "@/baseUrl";
|
||||||
import routes from "@/routes";
|
import routes from "@/routes";
|
||||||
import { cookies } from "next/headers";
|
import { revalidateTag } from "next/cache";
|
||||||
|
|
||||||
export async function authenticateLottery(
|
export async function authenticateLottery(phone: string, code: string) {
|
||||||
phone: string,
|
|
||||||
code: string,
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${baseUrl.QUIZ_SRC}${routes.lotteryActive}`, {
|
const res = await fetch(`${baseUrl.QUIZ_SRC}${routes.lotteryActive}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
@ -17,6 +14,10 @@ export async function authenticateLottery(
|
||||||
phone: phone,
|
phone: phone,
|
||||||
key: code,
|
key: code,
|
||||||
}),
|
}),
|
||||||
|
next: {
|
||||||
|
revalidate: 300,
|
||||||
|
tags: ["lotteryData"],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
|
@ -32,3 +33,7 @@ export async function authenticateLottery(
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const revalidateTagName = (tag: string) => {
|
||||||
|
revalidateTag(tag);
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,7 @@ import ReactConfetti from "react-confetti";
|
||||||
import { useWindowSize } from "react-use";
|
import { useWindowSize } from "react-use";
|
||||||
import { useMediaQuery } from "usehooks-ts";
|
import { useMediaQuery } from "usehooks-ts";
|
||||||
|
|
||||||
const Confetti = ({
|
const Confetti = () => {
|
||||||
numberOfPieces = 200,
|
|
||||||
showConfetti,
|
|
||||||
}: {
|
|
||||||
numberOfPieces?: number;
|
|
||||||
showConfetti: boolean;
|
|
||||||
}) => {
|
|
||||||
const [recycle, setRecycle] = useState<boolean>(true);
|
const [recycle, setRecycle] = useState<boolean>(true);
|
||||||
const { width, height } = useWindowSize();
|
const { width, height } = useWindowSize();
|
||||||
const colors = [
|
const colors = [
|
||||||
|
|
@ -26,7 +20,7 @@ const Confetti = ({
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => setRecycle(false), 30000);
|
setTimeout(() => setRecycle(false), 30000);
|
||||||
}, []);
|
}, [recycle]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed top-0 left-0 z-50">
|
<div className="fixed top-0 left-0 z-50">
|
||||||
|
|
@ -34,7 +28,7 @@ const Confetti = ({
|
||||||
width={width}
|
width={width}
|
||||||
height={height}
|
height={height}
|
||||||
recycle={recycle}
|
recycle={recycle}
|
||||||
numberOfPieces={mobile ? 200 / 3 : 200}
|
numberOfPieces={mobile ? 300 / 3 : 300}
|
||||||
tweenDuration={500}
|
tweenDuration={500}
|
||||||
colors={colors}
|
colors={colors}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import AnimatedText from "@/components/common/AnimatedText";
|
||||||
import { useWebsocketLottery } from "@/hooks/useWebSocketLottery";
|
import { useWebsocketLottery } from "@/hooks/useWebSocketLottery";
|
||||||
import Confetti from "../common/Confetti";
|
import Confetti from "../common/Confetti";
|
||||||
import { AnimatePresence, motion } from "framer-motion";
|
import { AnimatePresence, motion } from "framer-motion";
|
||||||
|
import { revalidateTagName } from "@/api";
|
||||||
|
|
||||||
const WEBSOCKET_URL = "wss://sms.turkmentv.gov.tm/ws/lottery?dst=";
|
const WEBSOCKET_URL = "wss://sms.turkmentv.gov.tm/ws/lottery?dst=";
|
||||||
const SLOT_COUNTER_DURATION = 30000;
|
const SLOT_COUNTER_DURATION = 30000;
|
||||||
|
|
@ -112,6 +113,7 @@ const LotteryWinnersSection = ({ data }: { data: any }) => {
|
||||||
setWinnerSelectingStatus("selected");
|
setWinnerSelectingStatus("selected");
|
||||||
setIsConfettiActive(true);
|
setIsConfettiActive(true);
|
||||||
|
|
||||||
|
revalidateTagName("lotteryData");
|
||||||
// Add the winner to the list
|
// Add the winner to the list
|
||||||
setWinners((prevWinners) => [...prevWinners, winner]);
|
setWinners((prevWinners) => [...prevWinners, winner]);
|
||||||
// Wait for the animation duration
|
// Wait for the animation duration
|
||||||
|
|
@ -125,7 +127,7 @@ const LotteryWinnersSection = ({ data }: { data: any }) => {
|
||||||
Websocket connection error.
|
Websocket connection error.
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<Confetti showConfetti={isConfettiActive} numberOfPieces={300} />
|
{isConfettiActive && <Confetti />}
|
||||||
|
|
||||||
<div className="container">
|
<div className="container">
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue