fix: 토스판은 지역을 고른 적 있어도 위치 권한이 있으면 들어올 때마다 지금 위치로

This commit is contained in:
minaChoi committed 2026-10-13 17:07:29 +09:00
1 parent 7dcb40df78
commit e180d9651c
1 file changed
+8 -5
+8 -5
View File
@@ -30,7 +30,7 @@ export function RegionProvider({ children }: { children: ReactNode }) {
const [stored] = useState(readStored)
const [region, setRegionState] = useState<RegionData>(stored ?? DEFAULT_REGION)
const canLocate = IS_TOSS || (typeof navigator !== 'undefined' && 'geolocation' in navigator)
const [locateStatus, setLocateStatus] = useState<LocateStatus>(!stored && canLocate ? 'locating' : 'idle')
const [locateStatus, setLocateStatus] = useState<LocateStatus>((!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])