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

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

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