diff --git a/frontend/src/b/region.tsx b/frontend/src/b/region.tsx index b829793..8e4a9fd 100644 --- a/frontend/src/b/region.tsx +++ b/frontend/src/b/region.tsx @@ -30,7 +30,7 @@ export function RegionProvider({ children }: { children: ReactNode }) { const [stored] = useState(readStored) const [region, setRegionState] = useState(stored ?? DEFAULT_REGION) const canLocate = IS_TOSS || (typeof navigator !== 'undefined' && 'geolocation' in navigator) - const [locateStatus, setLocateStatus] = useState(!stored && canLocate ? 'locating' : 'idle') + const [locateStatus, setLocateStatus] = useState((!stored || IS_TOSS) && canLocate ? 'locating' : 'idle') const setRegion = useCallback((r: RegionData) => { setRegionState(r) @@ -49,9 +49,10 @@ export function RegionProvider({ children }: { children: ReactNode }) { .catch(() => setLocateStatus('error')) }, [setRegion]) - const findNearest = useCallback((onFound?: () => void) => { + // ask=false 면 토스에서 권한 창 없이, 이미 허용한 사람만 위치로 맞춘다 + const findNearest = useCallback((onFound?: () => void, ask = true) => { if (IS_TOSS) { - tossLocation(true).then( + tossLocation(ask).then( (loc) => { if (loc === null) setLocateStatus('idle') else if (loc === 'denied') setLocateStatus('denied') @@ -80,9 +81,11 @@ export function RegionProvider({ children }: { children: ReactNode }) { findNearest(onFound) }, [canLocate, findNearest]) - // 처음 온 사람만 위치 권한을 물어 가장 가까운 구로 맞춘다 + // 처음 온 사람은 위치 권한을 물어 가장 가까운 구로 맞춘다. 토스판은 지역을 고른 적 있어도 권한이 있으면 들어올 때마다 지금 위치로 useEffect(() => { - if (!stored && canLocate) findNearest() + if (!canLocate) return + if (!stored) findNearest() + else if (IS_TOSS) findNearest(undefined, false) }, [stored, canLocate, findNearest]) const api = useMemo(() => ({ region, setRegion, locate, locateStatus }), [region, setRegion, locate, locateStatus])