fix: 토스판은 지역을 고른 적 있어도 위치 권한이 있으면 들어올 때마다 지금 위치로
This commit is contained in:
1 parent
7dcb40df78
commit
e180d9651c
1 file changed
+8
-5
@@ -30,7 +30,7 @@ export function RegionProvider({ children }: { children: ReactNode }) {
|
|||||||
const [stored] = useState(readStored)
|
const [stored] = useState(readStored)
|
||||||
const [region, setRegionState] = useState<RegionData>(stored ?? DEFAULT_REGION)
|
const [region, setRegionState] = useState<RegionData>(stored ?? DEFAULT_REGION)
|
||||||
const canLocate = IS_TOSS || (typeof navigator !== 'undefined' && 'geolocation' in navigator)
|
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) => {
|
const setRegion = useCallback((r: RegionData) => {
|
||||||
setRegionState(r)
|
setRegionState(r)
|
||||||
@@ -49,9 +49,10 @@ export function RegionProvider({ children }: { children: ReactNode }) {
|
|||||||
.catch(() => setLocateStatus('error'))
|
.catch(() => setLocateStatus('error'))
|
||||||
}, [setRegion])
|
}, [setRegion])
|
||||||
|
|
||||||
const findNearest = useCallback((onFound?: () => void) => {
|
// ask=false 면 토스에서 권한 창 없이, 이미 허용한 사람만 위치로 맞춘다
|
||||||
|
const findNearest = useCallback((onFound?: () => void, ask = true) => {
|
||||||
if (IS_TOSS) {
|
if (IS_TOSS) {
|
||||||
tossLocation(true).then(
|
tossLocation(ask).then(
|
||||||
(loc) => {
|
(loc) => {
|
||||||
if (loc === null) setLocateStatus('idle')
|
if (loc === null) setLocateStatus('idle')
|
||||||
else if (loc === 'denied') setLocateStatus('denied')
|
else if (loc === 'denied') setLocateStatus('denied')
|
||||||
@@ -80,9 +81,11 @@ export function RegionProvider({ children }: { children: ReactNode }) {
|
|||||||
findNearest(onFound)
|
findNearest(onFound)
|
||||||
}, [canLocate, findNearest])
|
}, [canLocate, findNearest])
|
||||||
|
|
||||||
// 처음 온 사람만 위치 권한을 물어 가장 가까운 구로 맞춘다
|
// 처음 온 사람은 위치 권한을 물어 가장 가까운 구로 맞춘다. 토스판은 지역을 고른 적 있어도 권한이 있으면 들어올 때마다 지금 위치로
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!stored && canLocate) findNearest()
|
if (!canLocate) return
|
||||||
|
if (!stored) findNearest()
|
||||||
|
else if (IS_TOSS) findNearest(undefined, false)
|
||||||
}, [stored, canLocate, findNearest])
|
}, [stored, canLocate, findNearest])
|
||||||
|
|
||||||
const api = useMemo(() => ({ region, setRegion, locate, locateStatus }), [region, setRegion, locate, locateStatus])
|
const api = useMemo(() => ({ region, setRegion, locate, locateStatus }), [region, setRegion, locate, locateStatus])
|
||||||
|
|||||||
Reference in new issue
Block a user