refactor autoShowQuizTime quiz widget param

This commit is contained in:
nflnkr 2024-05-09 14:39:36 +03:00
parent 92d727b2e9
commit b8313765d3
3 changed files with 13 additions and 13 deletions

@ -14,9 +14,9 @@ interface Props {
fixedSide?: "left" | "right"; fixedSide?: "left" | "right";
dimensions?: { width: string; height: string; }; dimensions?: { width: string; height: string; };
/** /**
* Открыть квиз через X секунд * Открыть квиз через X секунд, 0 - сразу
*/ */
autoShowQuizTime?: number; autoShowQuizTime?: number | null;
hideOnMobile?: boolean; hideOnMobile?: boolean;
openOnLeaveAttempt?: boolean; openOnLeaveAttempt?: boolean;
buttonFlash?: boolean; buttonFlash?: boolean;
@ -30,7 +30,7 @@ interface Props {
export default function OpenQuizButton({ export default function OpenQuizButton({
quizId, quizId,
fixedSide, fixedSide,
autoShowQuizTime = 0, autoShowQuizTime = null,
dimensions, dimensions,
hideOnMobile, hideOnMobile,
openOnLeaveAttempt, openOnLeaveAttempt,
@ -49,7 +49,7 @@ export default function OpenQuizButton({
const preventOpenOnLeaveAttemptRef = useRef<boolean>(false); const preventOpenOnLeaveAttemptRef = useRef<boolean>(false);
useEffect(function setAutoShowQuizTimer() { useEffect(function setAutoShowQuizTimer() {
if (!autoShowQuizTime || openOnLeaveAttempt) return; if (autoShowQuizTime === null || openOnLeaveAttempt) return;
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
setIsQuizShown(true); setIsQuizShown(true);

@ -11,9 +11,9 @@ interface Props {
quizId: string; quizId: string;
dimensions?: { width: string; height: string; }; dimensions?: { width: string; height: string; };
/** /**
* Открыть квиз через X секунд * Открыть квиз через X секунд, 0 - сразу
*/ */
autoShowQuizTime?: number; autoShowQuizTime?: number | null;
hideOnMobile?: boolean; hideOnMobile?: boolean;
openOnLeaveAttempt?: boolean; openOnLeaveAttempt?: boolean;
} }
@ -21,11 +21,11 @@ interface Props {
export default function QuizPopup({ export default function QuizPopup({
quizId, quizId,
dimensions, dimensions,
autoShowQuizTime = 0, autoShowQuizTime = null,
hideOnMobile = false, hideOnMobile = false,
openOnLeaveAttempt = false, openOnLeaveAttempt = false,
}: Props) { }: Props) {
const initialIsQuizShown = (autoShowQuizTime || openOnLeaveAttempt) ? false : true; const initialIsQuizShown = (autoShowQuizTime !== null || openOnLeaveAttempt) ? false : true;
const [isQuizShown, setIsQuizShown] = useState<boolean>(initialIsQuizShown); const [isQuizShown, setIsQuizShown] = useState<boolean>(initialIsQuizShown);
const isQuizCompleted = useQuizCompletionStatus(quizId); const isQuizCompleted = useQuizCompletionStatus(quizId);
@ -33,7 +33,7 @@ export default function QuizPopup({
const preventOpenOnLeaveAttemptRef = useRef<boolean>(false); const preventOpenOnLeaveAttemptRef = useRef<boolean>(false);
useEffect(function setAutoShowQuizTimer() { useEffect(function setAutoShowQuizTimer() {
if (!autoShowQuizTime || openOnLeaveAttempt) return; if (autoShowQuizTime === null || openOnLeaveAttempt) return;
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
setIsQuizShown(true); setIsQuizShown(true);

@ -25,9 +25,9 @@ interface Props {
*/ */
autoOpenTime?: number; autoOpenTime?: number;
/** /**
* Открыть квиз через X секунд * Открыть квиз через X секунд, 0 - сразу
*/ */
autoShowQuizTime?: number; autoShowQuizTime?: number | null;
hideOnMobile?: boolean; hideOnMobile?: boolean;
} }
@ -40,7 +40,7 @@ export default function QuizSideButton({
fullScreen = false, fullScreen = false,
buttonFlash = false, buttonFlash = false,
autoOpenTime = 0, autoOpenTime = 0,
autoShowQuizTime = 0, autoShowQuizTime = null,
hideOnMobile = false, hideOnMobile = false,
}: Props) { }: Props) {
const [isQuizShown, setIsQuizShown] = useState<boolean>(false); const [isQuizShown, setIsQuizShown] = useState<boolean>(false);
@ -51,7 +51,7 @@ export default function QuizSideButton({
const preventQuizAutoShowRef = useRef<boolean>(false); const preventQuizAutoShowRef = useRef<boolean>(false);
useEffect(function setAutoShowQuizTimer() { useEffect(function setAutoShowQuizTimer() {
if (!autoShowQuizTime) return; if (autoShowQuizTime === null) return;
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
if (!preventQuizAutoShowRef.current) setIsQuizShown(true); if (!preventQuizAutoShowRef.current) setIsQuizShown(true);