|
@ -17,18 +17,15 @@ const RecitersModal: React.FC<ModalProps> = ({ className = "" }) => { |
|
|
const modalRef = useRef<HTMLDivElement>(null); |
|
|
const modalRef = useRef<HTMLDivElement>(null); |
|
|
const closeButtonRef = useRef<HTMLButtonElement>(null); |
|
|
const closeButtonRef = useRef<HTMLButtonElement>(null); |
|
|
const previouslyFocusedElement = useRef<HTMLElement | null>(null); |
|
|
const previouslyFocusedElement = useRef<HTMLElement | null>(null); |
|
|
const [windowWidth, setWindowWidth] = useState(window.innerWidth); |
|
|
|
|
|
|
|
|
const [windowWidth, setWindowWidth] = useState(typeof window !== "undefined" ? window.innerWidth : 0); |
|
|
const [reciters, setReciters] = useState([]); |
|
|
const [reciters, setReciters] = useState([]); |
|
|
const params = useParams(); |
|
|
const params = useParams(); |
|
|
const slug = params?.slug as string; |
|
|
const slug = params?.slug as string; |
|
|
const id = slug.split("-").pop(); |
|
|
const id = slug.split("-").pop(); |
|
|
const modalClasses = windowWidth < 1024 ? "" : "max-w-96 bottom-20 right-0"; |
|
|
const modalClasses = windowWidth < 1024 ? "" : "max-w-96 bottom-20 right-0"; |
|
|
|
|
|
|
|
|
console.log(windowWidth); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
http.get(`web/mafatih/${id}/reciters/`).then((res) => { |
|
|
http.get(`web/mafatih/${id}/reciters/`).then((res) => { |
|
|
console.log("fdasfdasfads", res); |
|
|
|
|
|
setReciters(res.data.results); |
|
|
setReciters(res.data.results); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -38,18 +35,14 @@ const RecitersModal: React.FC<ModalProps> = ({ className = "" }) => { |
|
|
|
|
|
|
|
|
window.addEventListener("resize", handleResize); |
|
|
window.addEventListener("resize", handleResize); |
|
|
|
|
|
|
|
|
// Cleanup the event listener on component unmount
|
|
|
|
|
|
return () => { |
|
|
return () => { |
|
|
window.removeEventListener("resize", handleResize); |
|
|
window.removeEventListener("resize", handleResize); |
|
|
}; |
|
|
}; |
|
|
}, [id]); |
|
|
}, [id]); |
|
|
// Handle modal visibility and accessibility
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
const handleOutsideClick = (event: MouseEvent) => { |
|
|
const handleOutsideClick = (event: MouseEvent) => { |
|
|
if ( |
|
|
|
|
|
modalRef.current && |
|
|
|
|
|
!modalRef.current.contains(event.target as Node) |
|
|
|
|
|
) { |
|
|
|
|
|
|
|
|
if (modalRef.current && !modalRef.current.contains(event.target as Node)) { |
|
|
closeModal(); |
|
|
closeModal(); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
@ -60,32 +53,24 @@ const RecitersModal: React.FC<ModalProps> = ({ className = "" }) => { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if (displaySetting) { |
|
|
|
|
|
previouslyFocusedElement.current = document.activeElement as HTMLElement; |
|
|
|
|
|
document.addEventListener("mousedown", handleOutsideClick); |
|
|
document.addEventListener("mousedown", handleOutsideClick); |
|
|
document.addEventListener("keydown", handleKeyDown); |
|
|
document.addEventListener("keydown", handleKeyDown); |
|
|
// Prevent background scrolling
|
|
|
|
|
|
document.body.style.overflow = "hidden"; |
|
|
|
|
|
// Shift focus to close button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save the previously focused element and set modal focus
|
|
|
|
|
|
if (displaySetting) { |
|
|
|
|
|
previouslyFocusedElement.current = document.activeElement as HTMLElement; |
|
|
|
|
|
document.body.style.overflow = "hidden"; // Prevent background scrolling
|
|
|
closeButtonRef.current?.focus(); |
|
|
closeButtonRef.current?.focus(); |
|
|
} else { |
|
|
|
|
|
document.removeEventListener("mousedown", handleOutsideClick); |
|
|
|
|
|
document.removeEventListener("keydown", handleKeyDown); |
|
|
|
|
|
document.body.style.overflow = "auto"; |
|
|
|
|
|
// Return focus to previously focused element
|
|
|
|
|
|
previouslyFocusedElement.current?.focus(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return () => { |
|
|
return () => { |
|
|
document.removeEventListener("mousedown", handleOutsideClick); |
|
|
document.removeEventListener("mousedown", handleOutsideClick); |
|
|
document.removeEventListener("keydown", handleKeyDown); |
|
|
document.removeEventListener("keydown", handleKeyDown); |
|
|
document.body.style.overflow = "auto"; |
|
|
|
|
|
|
|
|
document.body.style.overflow = "auto"; // Restore scrolling
|
|
|
|
|
|
previouslyFocusedElement.current?.focus(); // Restore focus
|
|
|
}; |
|
|
}; |
|
|
}, []); |
|
|
|
|
|
console.log(reciters); |
|
|
|
|
|
reciters.map((item) => { |
|
|
|
|
|
console.log(item); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
}, [displaySetting]); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<div |
|
|
<div |
|
|
ref={modalRef} |
|
|
ref={modalRef} |
|
@ -95,8 +80,11 @@ const RecitersModal: React.FC<ModalProps> = ({ className = "" }) => { |
|
|
> |
|
|
> |
|
|
<div className="flex justify-between items-center p-6"> |
|
|
<div className="flex justify-between items-center p-6"> |
|
|
<div className="text-[#8B8B8B] text-sm font-bold">Reciter</div> |
|
|
<div className="text-[#8B8B8B] text-sm font-bold">Reciter</div> |
|
|
<div></div> |
|
|
|
|
|
<button onClick={closeModal}> |
|
|
|
|
|
|
|
|
<button |
|
|
|
|
|
ref={closeButtonRef} |
|
|
|
|
|
onClick={closeModal} |
|
|
|
|
|
aria-label="Close modal" |
|
|
|
|
|
> |
|
|
<IoMdClose size={18} /> |
|
|
<IoMdClose size={18} /> |
|
|
</button> |
|
|
</button> |
|
|
</div> |
|
|
</div> |
|
|