feat: 구로 나뉜 13개 시의 구마다 자기 주소(/today/gyeonggi/seongnam/bundang, 39장), 구를 고르면 구 주소로

This commit is contained in:
minaChoi committed 2026-10-20 09:35:16 +09:00
1 parent 0a16c5329d
commit 96cbd19c61
9 files changed
+595 -15

No files matched your search

+6 -6
View File
@@ -1,19 +1,19 @@
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
import { matchPath, useLocation, useNavigate } from 'react-router'
import { useLocation, useNavigate } from 'react-router'
import regionPages from '../../seo/region.json'
import { nearestRegion } from '../api/client/sdk.gen'
import type { RegionData } from '../api/client/types.gen'
import { track } from '../lib/analytics'
import { DEFAULT_REGION, RegionContext, type LocateStatus } from './regionContext'
import { DEFAULT_REGION, ownPage, RegionContext, type LocateStatus } from './regionContext'
const KEY = 'nalssigak.b.region'
type RegionPage = (typeof regionPages)[number]
/** /today/gyeonggi/seongnam 같은 지역 페이지 주소면 그 페이지 */
/** /today/gyeonggi/seongnam, /today/gyeonggi/seongnam/bundang 같은 지역 페이지 주소면 그 페이지 */
function pageOf(pathname: string): RegionPage | undefined {
const m = matchPath('/today/:sido/:place', pathname)
return m ? regionPages.find((p) => p.path === `${m.params.sido}/${m.params.place}`) : undefined
const path = pathname.match(/^\/today\/([a-z]+\/[a-z]+(?:\/[a-z]+)?)\/?$/)?.[1]
return path ? regionPages.find((p) => p.path === path) : undefined
}
/** 지역 페이지 안의 구: 구로 나뉜 시는 r 이 그 시 안이면 r, 아니면 시청이 있는 구 */
@@ -60,7 +60,7 @@ export function RegionProvider({ children }: { children: ReactNode }) {
const setRegion = useCallback((r: RegionData) => {
setRegionState(r)
writeStored(r)
const next = regionPages.find((p) => p.regions.some((g) => g.code === r.code))
const next = ownPage(r.code)
if (pageRef.current && next && next !== pageRef.current) navigate(`/today/${next.path}`)
}, [navigate])