diff --git a/src/features/lockers/LockersCellSelectScreen.tsx b/src/features/lockers/LockersCellSelectScreen.tsx index 00e3c70c..d67cf5b8 100644 --- a/src/features/lockers/LockersCellSelectScreen.tsx +++ b/src/features/lockers/LockersCellSelectScreen.tsx @@ -31,6 +31,7 @@ import LockersSelectedLockerBar from "@/features/lockers/components/LockersSelec import { LOCKER_ASSIGNMENT_PATH } from "@/features/lockers/constants/lockers"; import { LOCKERS_APPLY_SUBMITTING_TEXT } from "@/features/lockers/constants/lockersApplySubmit"; import { useLockersApplySubmit } from "@/features/lockers/hooks/useLockersApplySubmit"; +import { useLockersRefresh } from "@/features/lockers/hooks/useLockersRefresh"; import { lockersKeys } from "@/shared/entities/lockers/lockersKeys"; import { hasLockerInPeriod, @@ -137,6 +138,12 @@ function SectionLockerSelect({ setIsUnavailableToastOpen(true); }; + const { fadeClassName, isRefreshing, refresh } = useLockersRefresh(() => + queryClient.refetchQueries({ + queryKey: lockersKeys.sectionDetail(lockerPeriodId, detail.sectionId), + }), + ); + useScreenHeader( - queryClient.refetchQueries({ - queryKey: lockersKeys.sectionDetail( - lockerPeriodId, - detail.sectionId, - ), - }) - } + onClick={refresh} variant="icon" > @@ -209,7 +209,12 @@ function SectionLockerSelect({ return (
- } map={map} /> +
+ } map={map} /> +
+ queryClient.refetchQueries({ + queryKey: lockersKeys.sections(), + type: "active", + }), + ); useScreenHeader( - queryClient.refetchQueries({ - queryKey: lockersKeys.sections(), - type: "active", - }) - } + onClick={refresh} variant="icon" > @@ -60,6 +62,7 @@ function LockersSectionSelectScreen() { void; onConfirm: (sectionId: number) => void; + isRefreshing?: boolean; + mapClassName?: string; } // 평면도 + 선택 완료 버튼. 새로고침으로 고른 구역이 마감되면 선택을 풀어 버튼을 잠근다. @@ -28,6 +30,8 @@ export function LockersSectionSelectBody({ selectedSectionId, onSelect, onConfirm, + isRefreshing = false, + mapClassName = "", }: LockersSectionSelectBodyProps) { const selectedSection = [...(sections?.values() ?? [])].find( (section) => @@ -36,7 +40,10 @@ export function LockersSectionSelectBody({ return ( <> -
+
Promise) { + const [isRefreshing, setIsRefreshing] = useState(false); + const isRefreshingRef = useRef(false); + + const refresh = async () => { + if (isRefreshingRef.current) { + return; + } + isRefreshingRef.current = true; + setIsRefreshing(true); + await Promise.all([ + refetch(), + new Promise((resolve) => setTimeout(resolve, MIN_HIDDEN_MS)), + ]); + isRefreshingRef.current = false; + setIsRefreshing(false); + }; + + const fadeClassName = isRefreshing + ? "opacity-0" + : "opacity-100 transition-opacity duration-200 ease-out"; + + return { fadeClassName, isRefreshing, refresh }; +}