From 28ff0321600e4cad0e7860b8e23e368824e24074 Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Wed, 14 Oct 2026 14:29:20 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=95=B1=20=EC=8B=9C=ED=8A=B8=C2=B7?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=83=81=ED=83=9C=C2=B7=EC=A7=80?= =?UTF-8?q?=EC=97=AD=20=EC=A0=80=EC=9E=A5=20=ED=8B=80,=20=EA=B3=B5?= =?UTF-8?q?=ED=86=B5=20UI(Avatar=C2=B7Chips=C2=B7Rows=C2=B7Credit)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mobile/src/app/_layout.tsx | 12 +++- mobile/src/components/sheets/index.tsx | 9 +++ mobile/src/components/today/hero.tsx | 10 +++- mobile/src/components/today/rails.tsx | 16 +++-- mobile/src/components/ui.tsx | 83 +++++++++++++++++++++++++- mobile/src/lib/auth.tsx | 37 ++++++++++++ mobile/src/lib/region.tsx | 27 ++++++++- mobile/src/lib/sheet.ts | 23 +++++++ 8 files changed, 202 insertions(+), 15 deletions(-) create mode 100644 mobile/src/components/sheets/index.tsx create mode 100644 mobile/src/lib/auth.tsx create mode 100644 mobile/src/lib/sheet.ts diff --git a/mobile/src/app/_layout.tsx b/mobile/src/app/_layout.tsx index ce2a4ce..6a9a347 100644 --- a/mobile/src/app/_layout.tsx +++ b/mobile/src/app/_layout.tsx @@ -11,7 +11,9 @@ import { View } from 'react-native'; import '@/global.css'; import { SkyBg } from '@/components/sky-bg'; import { TabBar } from '@/components/tab-bar'; +import { SheetProvider } from '@/components/sheets'; import { TopBar } from '@/components/top-bar'; +import { AuthProvider } from '@/lib/auth'; import { queryClient } from '@/lib/query-client'; import { RegionProvider } from '@/lib/region'; import { SkyProvider, useSky } from '@/lib/sky'; @@ -45,9 +47,13 @@ export default function RootLayout() { return ( - - - + + + + + + + ); diff --git a/mobile/src/components/sheets/index.tsx b/mobile/src/components/sheets/index.tsx new file mode 100644 index 0000000..aadc333 --- /dev/null +++ b/mobile/src/components/sheets/index.tsx @@ -0,0 +1,9 @@ +import { useMemo, useState, type ReactNode } from 'react'; + +import { SheetContext, type SheetState } from '@/lib/sheet'; + +export function SheetProvider({ children }: { children: ReactNode }) { + const [, setState] = useState(null); + const api = useMemo(() => ({ open: (s: Exclude) => setState(s), close: () => setState(null) }), []); + return {children}; +} diff --git a/mobile/src/components/today/hero.tsx b/mobile/src/components/today/hero.tsx index 5bf8294..2d9d641 100644 --- a/mobile/src/components/today/hero.tsx +++ b/mobile/src/components/today/hero.tsx @@ -8,6 +8,7 @@ import { LinearGradient } from 'expo-linear-gradient'; import Svg, { Defs, Path, RadialGradient, Rect, Stop } from 'react-native-svg'; import { Ic, Skel } from '@/components/ui'; +import { useSheet } from '@/lib/sheet'; import { useSky } from '@/lib/sky'; type Mode = 'now' | TimeKind; @@ -48,6 +49,7 @@ function heroVal(load: Load, v: ReactNode, skel: string) { type Props = { hero?: HeroData | null; today?: ResWeatherToday; ranked: TopIndex[]; feedLoad: Load; todayLoad: Load }; export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) { + const { open } = useSheet(); const { preview, setServerKind, setPreview } = useSky(); const mode: Mode = preview ?? 'now'; const t = kst(useNow()); @@ -112,7 +114,13 @@ export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) { - {bubble ? {bubble} : } + {bubble ? ( + top1 && open({ type: 'gak', indexId: top1.index_id })} accessibilityLabel={top1 ? `${bubble} 1위 ${top1.name} ${top1.score}점, 계산 근거 보기` : undefined}> + {bubble} + + ) : ( + + )} {top1?.summary ? {top1.summary} : feedLoad === 'loading' ? : null} {/* 상태 한 줄: 습도·불쾌지수·자외선·미세먼지 단계 이름. 조심할 것만 색 */} {status.length > 0 && ( diff --git a/mobile/src/components/today/rails.tsx b/mobile/src/components/today/rails.tsx index 92dd8aa..9ad048a 100644 --- a/mobile/src/components/today/rails.tsx +++ b/mobile/src/components/today/rails.tsx @@ -7,16 +7,18 @@ import { Pressable, Text, View } from 'react-native'; import { Ic, Rail, Sec, Skel, Thumb } from '@/components/ui'; import { CARD_BG, BAND_BG } from '@/lib/colors'; +import { useSheet } from '@/lib/sheet'; import { useSky } from '@/lib/sky'; const CARD = 'overflow-hidden rounded-[22px] border-b-[5px] border-shade bg-card'; /** 오늘의 각 순위: 동그라미 + 이름 + 점수. 지금 시간대가 아닌 각은 흐리게 */ export function Stories({ items }: { items: TopIndex[] }) { + const { open } = useSheet(); return ( {items.map((g, i) => ( - + open({ type: 'gak', indexId: g.index_id })} accessibilityLabel={g.active ? `${g.rank}위 ${g.name} ${g.score}점` : `${g.name}, 지금 시간대 아님`} className={`w-[72px] items-center gap-1 ${g.active ? '' : 'opacity-55'}`}> {!g.active || g.score < 50 ? ( @@ -32,7 +34,7 @@ export function Stories({ items }: { items: TopIndex[] }) { {g.name} {g.active ? {g.score} : 지금 아님} - + ))} ); @@ -96,17 +98,18 @@ export function EventsBand({ events }: { events: BandEvent[] }) { } export function TopBand({ items, sub }: { items: TopIndex[]; sub: string }) { + const { open } = useSheet(); return ( {items.slice(0, 5).map((g, i) => ( - + open({ type: 'gak', indexId: g.index_id })} className="w-[138px] gap-1 rounded-[22px] border-b-[5px] border-shade bg-card p-3"> {i < 3 ? : {i + 1}위} {g.name} {g.score} {g.summary && {g.summary}} - + ))} @@ -115,11 +118,12 @@ export function TopBand({ items, sub }: { items: TopIndex[]; sub: string }) { export function SeasonBand({ news }: { news: BandArticle[] }) { const bg = useCardBg(); + const { open } = useSheet(); return ( {news.map((a) => ( - + open({ type: 'article', articleId: a.article_id })} className={`w-[200px] ${CARD}`}> @@ -127,7 +131,7 @@ export function SeasonBand({ news }: { news: BandArticle[] }) { {a.title} {a.meta} - + ))} diff --git a/mobile/src/components/ui.tsx b/mobile/src/components/ui.tsx index 5587a48..86736fa 100644 --- a/mobile/src/components/ui.tsx +++ b/mobile/src/components/ui.tsx @@ -1,9 +1,9 @@ -import type { Load } from '@nalssigak/shared/lib'; +import { AVATAR_COLORS, moodEmoji, naverMap, type Load } from '@nalssigak/shared/lib'; import { Image, type ImageStyle } from 'expo-image'; import { LinearGradient } from 'expo-linear-gradient'; import { Link, type Href } from 'expo-router'; import { useState, type ReactNode } from 'react'; -import { Pressable, ScrollView, Text, View, type StyleProp, type ViewStyle } from 'react-native'; +import { Linking, Pressable, ScrollView, Text, View, type StyleProp, type ViewStyle } from 'react-native'; import { ICONS } from '@/lib/icons'; import { imageUri } from '@/lib/site'; @@ -84,3 +84,82 @@ export function StateBox({ load, onRetry, empty }: { load: Load; onRetry?: () => ); } + +/** 사진 출처 표기 (공공누리 조건). 위치는 className 으로 */ +export function Credit({ text, className = 'right-1 bottom-1' }: { text: string; className?: string }) { + return ( + + + {text} + + + ); +} + +/** 프로필 동그라미: 고른 배경색 위에 캐릭터, 오른쪽 위에 오늘 기분 */ +export function Avatar({ character, color, mood, size = 34 }: { character: string; color?: string | null; mood?: string | null; size?: number }) { + const emoji = moodEmoji(mood); + return ( + + + {emoji && ( + + {emoji} + + )} + + ); +} + +type ChipsProps = { items: readonly (readonly [K, string])[]; value: K; onChange: (k: K) => void; disabled?: boolean }; + +/** 가로로 넘기는 고르기 칩 */ +export function Chips({ items, value, onChange, disabled }: ChipsProps) { + return ( + + {items.map(([k, l]) => ( + onChange(k)} className={`rounded-full px-3.5 py-[7px] ${value === k ? 'bg-ink-btn' : 'border-b-[3px] border-shade bg-chip'}`}> + {l} + + ))} + + ); +} + +/** 장소 이름. 누르면 네이버 지도가 열린다 */ +export function MapLink({ place, children }: { place: string; children: ReactNode }) { + return ( + Linking.openURL(naverMap(place))} accessibilityRole="link" accessibilityLabel={`${place}, 네이버 지도에서 보기`} className="underline"> + {children} + + ); +} + +/** 자외선 단계(1 낮음 ~ 5 위험) 칩 색 */ +const LEVEL_CHIP = [ + ['#1f9d62', '#fff'], + ['#ffc21a', '#3a2a00'], + ['#f0700a', '#fff'], + ['#e03131', '#fff'], + ['#8e3bc4', '#fff'], +] as const; + +/** 줄 목록 (라벨 · 값) */ +export function Rows({ rows, dark = false }: { rows: { label: string; value: string; place?: string | null; level?: number | null }[]; dark?: boolean }) { + return ( + + {rows.map((r, i) => ( + + {r.label} + {r.level ? ( + + {r.value} + + ) : ( + {r.place ? {r.value} : r.value} + )} + + ))} + + ); +} diff --git a/mobile/src/lib/auth.tsx b/mobile/src/lib/auth.tsx new file mode 100644 index 0000000..bbaf6b9 --- /dev/null +++ b/mobile/src/lib/auth.tsx @@ -0,0 +1,37 @@ +import { clearTokens, getAccessToken, subscribeAuth } from '@nalssigak/shared/api/auth'; +import { meOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'; +import { logout as logoutOnServer } from '@nalssigak/shared/api/client/sdk.gen'; +import type { Me } from '@nalssigak/shared/api/client/types.gen'; +import { useQuery, useQueryClient } from '@tanstack/react-query'; +import { createContext, use, useEffect, useMemo, useSyncExternalStore, type ReactNode } from 'react'; + +/** mePending: 토큰은 있고 내 정보를 받는 중 (아바타 자리를 비워 두지 않으려고) */ +export type AuthApi = { loggedIn: boolean; me: Me | null; mePending: boolean; logout: () => void }; + +const AuthContext = createContext(null); + +export function useAuth() { + const ctx = use(AuthContext); + if (!ctx) throw new Error('useAuth must be used inside AuthProvider'); + return ctx; +} + +const subscribe = (cb: () => void) => subscribeAuth((reason) => reason === 'change' && cb()); + +/** 서버에서 이 계정의 토큰을 모두 무효로 만들고(실패해도) 기기 토큰을 지운다 */ +const logout = () => { + void logoutOnServer({ throwOnError: false }).finally(clearTokens); +}; + +export function AuthProvider({ children }: { children: ReactNode }) { + const token = useSyncExternalStore(subscribe, getAccessToken); + const queryClient = useQueryClient(); + const me = useQuery({ ...meOptions(), enabled: !!token }); + + // 로그인·로그아웃하면 좋아요 여부가 달라지니 받아 둔 데이터를 다시 받는다 + useEffect(() => subscribeAuth((reason) => reason === 'change' && queryClient.invalidateQueries()), [queryClient]); + + const mePending = !!token && me.isPending; + const api = useMemo(() => ({ loggedIn: !!token, me: (token && me.data?.me) || null, mePending, logout }), [token, me.data, mePending]); + return {children}; +} diff --git a/mobile/src/lib/region.tsx b/mobile/src/lib/region.tsx index a6bb587..7f55b67 100644 --- a/mobile/src/lib/region.tsx +++ b/mobile/src/lib/region.tsx @@ -1,6 +1,9 @@ import type { RegionData } from '@nalssigak/shared/api/client/types.gen'; import { DEFAULT_REGION } from '@nalssigak/shared/lib'; -import { createContext, use, useMemo, useState, type ReactNode } from 'react'; +import * as SecureStore from 'expo-secure-store'; +import { createContext, use, useCallback, useMemo, useState, type ReactNode } from 'react'; + +const KEY = 'nalssigak.region'; export type RegionApi = { region: RegionData; setRegion: (r: RegionData) => void }; @@ -12,8 +15,26 @@ export function useRegion() { return ctx; } +function readStored(): RegionData | null { + try { + const raw = SecureStore.getItem(KEY); + return raw ? (JSON.parse(raw) as RegionData) : null; + } catch (e) { + console.warn('저장한 지역을 읽지 못함', e); + return null; + } +} + export function RegionProvider({ children }: { children: ReactNode }) { - const [region, setRegion] = useState(DEFAULT_REGION); - const api = useMemo(() => ({ region, setRegion }), [region]); + const [region, setRegionState] = useState(() => readStored() ?? DEFAULT_REGION); + const setRegion = useCallback((r: RegionData) => { + setRegionState(r); + try { + SecureStore.setItem(KEY, JSON.stringify(r)); + } catch (e) { + console.warn('지역을 저장하지 못함', e); + } + }, []); + const api = useMemo(() => ({ region, setRegion }), [region, setRegion]); return {children}; } diff --git a/mobile/src/lib/sheet.ts b/mobile/src/lib/sheet.ts new file mode 100644 index 0000000..915669a --- /dev/null +++ b/mobile/src/lib/sheet.ts @@ -0,0 +1,23 @@ +import { createContext, use } from 'react'; + +type CommentsState = { type: 'comments'; postId: number; draft?: string }; + +export type SheetState = + | { type: 'gak'; indexId: number } + | { type: 'article'; articleId: number } + | CommentsState + | { type: 'seasonWeek' } + | { type: 'login'; then?: CommentsState } + | { type: 'me' } + | { type: 'region' } + | null; + +export type SheetApi = { open: (s: Exclude) => void; close: () => void }; + +export const SheetContext = createContext(null); + +export function useSheet() { + const ctx = use(SheetContext); + if (!ctx) throw new Error('useSheet must be used inside SheetProvider'); + return ctx; +}