Skip to content

Commit

Permalink
[fix] 모달 닫힌 뒤 스크롤이 안 내려가는 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
lybell-art committed Aug 12, 2024
1 parent f8d0b27 commit 2bfc8e8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/common/modal/modal.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createContext, useCallback, useEffect, useState, useRef } from "react";
import useModalStore, { closeModal } from "./store.js";
import { delay } from "@common/utils.js";

export const ModalCloseContext = createContext(() => {
console.log("모달이 닫힙니다.");
Expand All @@ -9,10 +10,12 @@ function Modal({ layer }) {
const timeoutRef = useRef(null);
const child = useModalStore(layer);
const [opacity, setOpacity] = useState(0);
const close = useCallback(() => {
const close = useCallback(async () => {
setOpacity(0);
if (timeoutRef.current === null)
timeoutRef.current = setTimeout(() => closeModal(layer), 150);
if (timeoutRef.current === null) {
await delay(150);
closeModal(layer);
}
}, [layer]);

useEffect(() => {
Expand Down
4 changes: 4 additions & 0 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ export function convertSecondsToString(time) {

return `${days > 0 ? days + " : " : ""}${[hours, minutes, seconds].map(padNumber).join(" : ")}`;
}

export function delay(ms) {
return new Promise( resolve=>setTimeout(resolve, ms) );
}
4 changes: 2 additions & 2 deletions src/mainPage/features/comment/modals/CommentNoUserModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { INTERACTION_SECTION } from "@main/scroll/constants.js";
function CommentNoUserModal() {
const close = useContext(ModalCloseContext);

function toMoveInteraction() {
close();
async function toMoveInteraction() {
await close();
scrollTo(INTERACTION_SECTION);
}

Expand Down
4 changes: 2 additions & 2 deletions src/mainPage/features/fcfs/modals/FcfsLoseModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ function FcfsLoseModal() {
const close = useContext(ModalCloseContext);
const shouldInteraction = false; // 향후 통합 예정

function toMoveInteraction() {
close();
async function toMoveInteraction() {
await close();
scrollTo(INTERACTION_SECTION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export default function InteractionAnswer({
setIsJoined(false);
}, []);

function onClickWrite() {
close();
async function onClickWrite() {
await close();
scrollTo(COMMENT_SECTION);
}

Expand Down

0 comments on commit 2bfc8e8

Please sign in to comment.