|
|
@ -1,7 +1,6 @@ |
|
|
"use client"; |
|
|
"use client"; |
|
|
|
|
|
|
|
|
import { useRouter } from "next/navigation"; |
|
|
import { useRouter } from "next/navigation"; |
|
|
import type { TouchEvent } from "react"; |
|
|
|
|
|
import { useEffect, useState } from "react"; |
|
|
import { useEffect, useState } from "react"; |
|
|
import { useQueryClient } from "@tanstack/react-query"; |
|
|
import { useQueryClient } from "@tanstack/react-query"; |
|
|
import { useUpdateMarriageProfileBasicMutation } from "@/hooks/marriage/use-profile-basic"; |
|
|
import { useUpdateMarriageProfileBasicMutation } from "@/hooks/marriage/use-profile-basic"; |
|
|
@ -21,7 +20,6 @@ import { SliderSlideThree } from "./slider-slide-three"; |
|
|
import { SliderSlideTwo } from "./slider-slide-two"; |
|
|
import { SliderSlideTwo } from "./slider-slide-two"; |
|
|
|
|
|
|
|
|
const FINAL_SLIDE_COUNT = 5; |
|
|
const FINAL_SLIDE_COUNT = 5; |
|
|
const SWIPE_THRESHOLD = 40; |
|
|
|
|
|
const SLIDER_ANSWERS_STORAGE_KEY = "marriage-slider-answers"; |
|
|
const SLIDER_ANSWERS_STORAGE_KEY = "marriage-slider-answers"; |
|
|
|
|
|
|
|
|
export type SliderPageProps = { |
|
|
export type SliderPageProps = { |
|
|
@ -36,8 +34,6 @@ export default function SliderPage({ onClose }: SliderPageProps = {}) { |
|
|
const [selectedRegistration, setSelectedRegistration] = |
|
|
const [selectedRegistration, setSelectedRegistration] = |
|
|
useState<RegistrationAnswer>("self"); |
|
|
useState<RegistrationAnswer>("self"); |
|
|
const [hasReadRules, setHasReadRules] = useState(false); |
|
|
const [hasReadRules, setHasReadRules] = useState(false); |
|
|
const [touchStartX, setTouchStartX] = useState<number | null>(null); |
|
|
|
|
|
const [touchStartY, setTouchStartY] = useState<number | null>(null); |
|
|
|
|
|
const updateProfileBasicMutation = useUpdateMarriageProfileBasicMutation(); |
|
|
const updateProfileBasicMutation = useUpdateMarriageProfileBasicMutation(); |
|
|
const queryClient = useQueryClient(); |
|
|
const queryClient = useQueryClient(); |
|
|
const [submitError, setSubmitError] = useState<string | null>(null); |
|
|
const [submitError, setSubmitError] = useState<string | null>(null); |
|
|
@ -125,41 +121,6 @@ export default function SliderPage({ onClose }: SliderPageProps = {}) { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const handleTouchStart = (event: TouchEvent<HTMLDivElement>) => { |
|
|
|
|
|
setTouchStartX(event.touches[0]?.clientX ?? null); |
|
|
|
|
|
setTouchStartY(event.touches[0]?.clientY ?? null); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handleTouchEnd = (event: TouchEvent<HTMLDivElement>) => { |
|
|
|
|
|
if (touchStartX === null || touchStartY === null) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const touchEndX = event.changedTouches[0]?.clientX ?? touchStartX; |
|
|
|
|
|
const touchEndY = event.changedTouches[0]?.clientY ?? touchStartY; |
|
|
|
|
|
const deltaX = touchStartX - touchEndX; |
|
|
|
|
|
const deltaY = touchStartY - touchEndY; |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
Math.abs(deltaX) >= SWIPE_THRESHOLD && |
|
|
|
|
|
Math.abs(deltaX) > Math.abs(deltaY) * 1.5 |
|
|
|
|
|
) { |
|
|
|
|
|
if (deltaX > 0) { |
|
|
|
|
|
if (activeSlide === 0 && !hasReadRules) { |
|
|
|
|
|
setTouchStartX(null); |
|
|
|
|
|
setTouchStartY(null); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
goToNextSlide(); |
|
|
|
|
|
} else { |
|
|
|
|
|
goToPreviousSlide(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setTouchStartX(null); |
|
|
|
|
|
setTouchStartY(null); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<div className="relative flex h-[100dvh] max-h-[100dvh] flex-col overflow-hidden"> |
|
|
<div className="relative flex h-[100dvh] max-h-[100dvh] flex-col overflow-hidden"> |
|
|
<header className="relative -mx-[17px] rounded-b-[32px] px-[17px] pt-[max(12px,calc(var(--safe-top)+4px))] pb-3"> |
|
|
<header className="relative -mx-[17px] rounded-b-[32px] px-[17px] pt-[max(12px,calc(var(--safe-top)+4px))] pb-3"> |
|
|
@ -168,6 +129,10 @@ export default function SliderPage({ onClose }: SliderPageProps = {}) { |
|
|
icon="back" |
|
|
icon="back" |
|
|
iconLabel="Close slider" |
|
|
iconLabel="Close slider" |
|
|
onClick={() => { |
|
|
onClick={() => { |
|
|
|
|
|
if (activeSlide > 0) { |
|
|
|
|
|
goToPreviousSlide(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
if (typeof window !== "undefined") { |
|
|
if (typeof window !== "undefined") { |
|
|
try { |
|
|
try { |
|
|
window.sessionStorage.setItem("skip_intro_redirect", "true"); |
|
|
window.sessionStorage.setItem("skip_intro_redirect", "true"); |
|
|
@ -210,11 +175,7 @@ export default function SliderPage({ onClose }: SliderPageProps = {}) { |
|
|
</div> |
|
|
</div> |
|
|
</header> |
|
|
</header> |
|
|
|
|
|
|
|
|
<main |
|
|
|
|
|
className="flex min-h-0 flex-1 touch-pan-y overflow-hidden pt-6" |
|
|
|
|
|
onTouchEnd={handleTouchEnd} |
|
|
|
|
|
onTouchStart={handleTouchStart} |
|
|
|
|
|
> |
|
|
|
|
|
|
|
|
<main className="flex min-h-0 flex-1 overflow-hidden pt-6"> |
|
|
<div |
|
|
<div |
|
|
className="flex h-full w-full transition-transform duration-300 ease-out" |
|
|
className="flex h-full w-full transition-transform duration-300 ease-out" |
|
|
style={{ transform: `translateX(-${activeSlide * 100}%)` }} |
|
|
style={{ transform: `translateX(-${activeSlide * 100}%)` }} |
|
|
|