feat: 구로 나뉜 13개 시의 구마다 자기 주소(/today/gyeonggi/seongnam/bundang, 39장), 구를 고르면 구 주소로
This commit is contained in:
1 parent
0a16c5329d
commit
96cbd19c61
9 files changed
+595
-15
No files matched your search
@@ -25,7 +25,7 @@ import { track } from '../lib/analytics'
|
||||
import { cx } from '../lib/utils'
|
||||
import { useAuth } from './authContext'
|
||||
import { ago, ARTICLE_CAT, articleMeta, AVATAR_COLORS, cardBg, CHARACTERS, dateRange, loadOf, MOODS, shortDay } from './lib'
|
||||
import { useRegion } from './regionContext'
|
||||
import { ownPage, useRegion } from './regionContext'
|
||||
import { useSky } from './skyContext'
|
||||
import { SHARE_SIZES, shareImage, type ShareSize } from './storyImage'
|
||||
import { SheetContext, useSheet, type SharePayload, type SheetState } from './sheetContext'
|
||||
@@ -989,9 +989,9 @@ function MeSheet({ onDone }: { onDone: () => void }) {
|
||||
/* ---------- 지역 ---------- */
|
||||
const LOCATE_TEXT = { idle: '', locating: '위치를 찾는 중이에요…', denied: '위치 권한이 꺼져 있어요. 아래 목록에서 골라 주세요.', error: '위치를 찾지 못했어요. 아래 목록에서 골라 주세요.' } as const
|
||||
|
||||
/** 구 코드 → 그 구가 속한 지역 페이지 주소 */
|
||||
/** 구 코드 → 그 구의 지역 페이지 주소 */
|
||||
const pageHref = (code: string) => {
|
||||
const p = regionPages.find((g) => g.regions.some((r) => r.code === code))
|
||||
const p = ownPage(code)
|
||||
return p ? `/today/${p.path}` : '/'
|
||||
}
|
||||
|
||||
|
||||
@@ -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])
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createContext, use } from 'react'
|
||||
import regionPages from '../../seo/region.json'
|
||||
import type { RegionData } from '../api/client/types.gen'
|
||||
|
||||
export type LocateStatus = 'idle' | 'locating' | 'denied' | 'error'
|
||||
@@ -7,6 +8,9 @@ export type RegionApi = { region: RegionData; setRegion: (r: RegionData) => void
|
||||
|
||||
export const DEFAULT_REGION: RegionData = { code: '1144000000', name: '서울 마포구', short_name: '마포구', lat: 37.56071, lon: 126.91053 }
|
||||
|
||||
/** 구 하나만 보여 주는 지역 페이지: 일반 시군구, 또는 구로 나뉜 시의 구 페이지 */
|
||||
export const ownPage = (code: string) => regionPages.find((p) => p.regions.length === 1 && p.regions[0].code === code)
|
||||
|
||||
export const RegionContext = createContext<RegionApi | null>(null)
|
||||
|
||||
export function useRegion() {
|
||||
|
||||
Reference in new issue
Block a user