кнопка старта дисаблится по истечении времени
This commit is contained in:
parent
6fa808884f
commit
59d03a9a64
@ -1,24 +1,21 @@
|
|||||||
import { Box, Typography, useTheme } from "@mui/material";
|
import { Box, Typography, useTheme } from "@mui/material";
|
||||||
import { useQuizStore } from "@stores/useQuizStore";
|
import { useQuizStore } from "@stores/useQuizStore";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
import React from "react";
|
||||||
// Глобальная переменная для принудительного обновления
|
|
||||||
let forceUpdateCounter = 0;
|
|
||||||
|
|
||||||
// Запускаем глобальный таймер
|
|
||||||
if (typeof window !== "undefined" && !(window as any).overtimeTimerStarted) {
|
|
||||||
(window as any).overtimeTimerStarted = true;
|
|
||||||
setInterval(() => {
|
|
||||||
forceUpdateCounter++;
|
|
||||||
// Принудительно обновляем все компоненты OverTime
|
|
||||||
const event = new CustomEvent("overtime-tick", { detail: forceUpdateCounter });
|
|
||||||
window.dispatchEvent(event);
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const OverTime = () => {
|
export const OverTime = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { settings } = useQuizStore();
|
const { settings } = useQuizStore();
|
||||||
|
const [currentTime, setCurrentTime] = React.useState(moment());
|
||||||
|
|
||||||
|
// Реактивный таймер с useEffect
|
||||||
|
React.useEffect(() => {
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
setCurrentTime(moment());
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Проверяем, включен ли overTime
|
// Проверяем, включен ли overTime
|
||||||
const overTimeConfig = settings?.cfg?.overTime;
|
const overTimeConfig = settings?.cfg?.overTime;
|
||||||
@ -30,9 +27,7 @@ export const OverTime = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Функция для расчета времени до окончания
|
// Функция для расчета времени до окончания
|
||||||
const calculateTimeLeft = () => {
|
const calculateTimeLeft = (now: moment.Moment) => {
|
||||||
const now = moment(); // текущее время
|
|
||||||
|
|
||||||
// Для тестирования: добавляем 2 часа к текущему времени
|
// Для тестирования: добавляем 2 часа к текущему времени
|
||||||
const testEndsAt = moment().add(2, "hours");
|
const testEndsAt = moment().add(2, "hours");
|
||||||
const endsAt = overTimeConfig?.endsAt ? moment(overTimeConfig.endsAt) : testEndsAt;
|
const endsAt = overTimeConfig?.endsAt ? moment(overTimeConfig.endsAt) : testEndsAt;
|
||||||
@ -51,20 +46,7 @@ export const OverTime = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const { days, hours, minutes, seconds } = calculateTimeLeft();
|
const { days, hours, minutes, seconds } = calculateTimeLeft(currentTime);
|
||||||
|
|
||||||
// Отладочная информация (используем глобальный счетчик для обновления)
|
|
||||||
const now = moment();
|
|
||||||
const endsAt = overTimeConfig?.endsAt ? moment(overTimeConfig.endsAt) : moment().add(2, "hours");
|
|
||||||
|
|
||||||
console.log("OverTime Debug:", {
|
|
||||||
currentTime: now.format("YYYY-MM-DD HH:mm:ss"),
|
|
||||||
endsAt: endsAt.format("YYYY-MM-DD HH:mm:ss"),
|
|
||||||
timeLeft: { days, hours, minutes, seconds },
|
|
||||||
rawEndsAt: overTimeConfig?.endsAt,
|
|
||||||
duration: moment.duration(endsAt.diff(now)).humanize(),
|
|
||||||
updateCounter: forceUpdateCounter,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
import { Box, Button, ButtonBase, Link, Paper, Typography, useTheme } from "@mui/material";
|
import { Box, Button, ButtonBase, Link, Paper, Typography, useTheme } from "@mui/material";
|
||||||
|
import moment from "moment";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
import { QuizPreviewLayoutByType } from "./QuizPreviewLayoutByType";
|
import { QuizPreviewLayoutByType } from "./QuizPreviewLayoutByType";
|
||||||
import { OverTime } from "./OverTime";
|
import { OverTime } from "./OverTime";
|
||||||
@ -25,6 +27,16 @@ export const StartPageViewPublication = () => {
|
|||||||
const { settings, show_badge, quizId, questions } = useQuizStore();
|
const { settings, show_badge, quizId, questions } = useQuizStore();
|
||||||
const { isMobileDevice } = useUADevice();
|
const { isMobileDevice } = useUADevice();
|
||||||
const setCurrentQuizStep = useQuizViewStore((state) => state.setCurrentQuizStep);
|
const setCurrentQuizStep = useQuizViewStore((state) => state.setCurrentQuizStep);
|
||||||
|
const [currentTime, setCurrentTime] = React.useState(moment());
|
||||||
|
|
||||||
|
// Реактивный таймер для обновления времени
|
||||||
|
React.useEffect(() => {
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
setCurrentTime(moment());
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const size = useRootContainerSize();
|
const size = useRootContainerSize();
|
||||||
const isMobile = size < 700;
|
const isMobile = size < 700;
|
||||||
@ -40,15 +52,6 @@ export const StartPageViewPublication = () => {
|
|||||||
yandexMetrics.phoneNumberOpened();
|
yandexMetrics.phoneNumberOpened();
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("------------------------------------------------");
|
|
||||||
console.log("Background type:", settings.cfg.startpage.background.type);
|
|
||||||
console.log("Is image type:", settings.cfg.startpage.background.type === "image");
|
|
||||||
console.log("Is video type:", settings.cfg.startpage.background.type === "video");
|
|
||||||
console.log("Video URL:", settings.cfg.startpage.background.video);
|
|
||||||
console.log("Desktop background:", settings.cfg.startpage.background.desktop);
|
|
||||||
console.log("Startpage type:", settings.cfg.startpageType);
|
|
||||||
console.log("------------------------------------------------");
|
|
||||||
|
|
||||||
const background =
|
const background =
|
||||||
settings.cfg.startpage.background.type === "image" ? (
|
settings.cfg.startpage.background.type === "image" ? (
|
||||||
<img
|
<img
|
||||||
@ -67,7 +70,6 @@ export const StartPageViewPublication = () => {
|
|||||||
) : settings.cfg.startpage.background.type === "video" ? (
|
) : settings.cfg.startpage.background.type === "video" ? (
|
||||||
settings.cfg.startpage.background.video ? (
|
settings.cfg.startpage.background.video ? (
|
||||||
(() => {
|
(() => {
|
||||||
console.log("Rendering QuizVideo with URL:", settings.cfg.startpage.background.video);
|
|
||||||
return (
|
return (
|
||||||
<QuizVideo
|
<QuizVideo
|
||||||
videoUrl={settings.cfg.startpage.background.video}
|
videoUrl={settings.cfg.startpage.background.video}
|
||||||
@ -184,6 +186,14 @@ export const StartPageViewPublication = () => {
|
|||||||
(question) => question.type !== null && question.type !== "result"
|
(question) => question.type !== null && question.type !== "result"
|
||||||
).length;
|
).length;
|
||||||
|
|
||||||
|
// Проверяем, истекло ли время для overTime
|
||||||
|
const overTimeConfig = settings?.cfg?.overTime;
|
||||||
|
const isOverTimeEnabled = overTimeConfig?.enabled;
|
||||||
|
const isTimeExpired =
|
||||||
|
isOverTimeEnabled && overTimeConfig?.endsAt
|
||||||
|
? currentTime.isAfter(moment(overTimeConfig.endsAt)) || currentTime.isSame(moment(overTimeConfig.endsAt))
|
||||||
|
: false;
|
||||||
|
|
||||||
const onQuizStart = () => {
|
const onQuizStart = () => {
|
||||||
setCurrentQuizStep("question");
|
setCurrentQuizStep("question");
|
||||||
|
|
||||||
@ -291,7 +301,7 @@ export const StartPageViewPublication = () => {
|
|||||||
<Box width={settings.cfg.startpageType === "standard" ? "100%" : "auto"}>
|
<Box width={settings.cfg.startpageType === "standard" ? "100%" : "auto"}>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
disabled={realQuestionsCount === 0}
|
disabled={realQuestionsCount === 0 || isTimeExpired}
|
||||||
sx={{
|
sx={{
|
||||||
fontSize: "18px",
|
fontSize: "18px",
|
||||||
padding: "10px 20px",
|
padding: "10px 20px",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user