diff --git a/TODO.md b/TODO.md index 7d0f921..eada69b 100644 --- a/TODO.md +++ b/TODO.md @@ -158,3 +158,21 @@ | [ ] | **[결정 필요]** 각 순위가 점수 순이 아니라 보임 — 순위가 점수 × 중요도라 환기각 92점(하)이 5위, 골프각 89점이 3위, 빨래각 83점이 2위. 각 탭 받침대·스토리에서 높은 점수가 뒤에 있어 어색함. 점수를 순위대로 보여줄지, 중요도 가중을 줄일지 | 화면 직접 확인 중 발견 (10/12) | `backend/services/calc/index_calc.py` (`PRIORITY_WEIGHT`), `frontend/src/b/GakPage.tsx` | | [x] | 노을 점수 29점(잿빛)인데 결론 '나가 볼 만해요' — 결론이 구름 분포만 보고 공기 보정(가시거리·습도)을 안 봤음 → 공기 보정 0.7배 미만이면 결론 한 단계 낮추고 이유에 공기 표시, '해 질 무렵(N시) 예보 기준' 표시. 운영 DB에 `sky_score.air` 칸 추가 필요(배포 때 `init.sql`의 ALTER) | 사용자 지적 (10/12, 분당구) | `backend/services/sky_service.py` (`day_verdict`, `build_plan`), `backend/services/calc/sky_score.py` (`air_note`) | | [x] | 노을 탭 다시 짜기 → 시안 A(사용자 선택): 히어로 '오늘은 애매해요 / 18:10쯤 가장 붉어요 / 쉬운 이유', 내일 안내 바로 아래, 숫자는 '자세히', 시간표에 가장 붉을 때 — 처음 보면 '그래서 가?'에서 멈춤: 히어로 18:00이 무슨 시각인지 없음, 결론 카드가 좋은 말·나쁜 말을 섞음, 구름 %·예보 모델 수 같은 전문 용어, '가장 붉을 때'가 시간표에 없음, '내일이 더 나아요'가 맨 아래. 시안 먼저 보고 결정 | 사용자 지적 (10/12) | `frontend/src/b/SkyPage.tsx`, `backend/services/calc/sky_score.py` (`reason`) | + +## 앱(React Native) 마이그레이션 + +| 상태 | 할 일 | 이유 | 관련 파일 | +|---|---|---|---| +| [x] | 1단계: 웹·앱 공통 코드 `shared/`(`@nalssigak/shared`) 분리, 루트 npm workspaces, 웹 Docker 빌드 대상을 루트로 | 앱과 API 클라이언트·로직 공유 | `package.json`, `shared/`, `frontend/Dockerfile`, `compose.yaml`, `.dockerignore` | +| [x] | 2단계: 앱에 react-query·Uniwind 설정 + Metro가 `react`를 `mobile/node_modules`(19.2.3) 것만 쓰게 설정 — 루트에는 웹용 react 19.3.0이 있고 RN 렌더러는 19.2.3에서만 돌아감 | 앱 시작 준비 | `mobile/metro.config.js`, `mobile/src/app/_layout.tsx`, `mobile/src/lib/query-client.ts` | +| [x] | 앱 토큰 저장소 `expo-secure-store`로 `configureApi` 연결, API 주소는 `EXPO_PUBLIC_API_BASE_URL` | 웹은 localStorage | `mobile/src/lib/api.ts`, `mobile/.env.example` | +| [ ] | 시뮬레이터·실기기에서 앱 띄워 API 호출·로그인 확인 (번들 빌드까지만 확인함) | | `mobile/` | +| [x] | 3단계-1: 탭 5개 구조·위 막대·하늘 배경·밤 테마(Uniwind dark), Today 히어로·각 순위·행사/TOP5/계절 띠 | | `mobile/src/app/`, `mobile/src/components/` | +| [ ] | Today 게시물 카드(`Post.tsx` 459줄, 슬라이드 넘기기·좋아요) 옮기기 — 지금은 띠만 이어서 보임 | 3단계-1 범위 밖 | `frontend/src/b/Post.tsx` | +| [ ] | 시트(각 근거·지역 고르기·로그인·내 정보, `Sheets.tsx` 1045줄) → `@gorhom/bottom-sheet`. 지금 앱은 눌러도 반응 없음, 위 막대에 로그인 버튼 없음 | 3단계-1 범위 밖 | `frontend/src/b/Sheets.tsx` | +| [ ] | 지역: 위치로 찾기(`expo-location`)·고른 지역 저장 — 지금은 마포구 고정 | | `mobile/src/lib/region.tsx` | +| [ ] | 움직임: 해·구름 떨어지기/둥둥, 비·눈 줄기, 구름, 스켈레톤 깜빡임, 첫 로딩 덮개 (reanimated) | 3단계-1은 정지 화면만 | `frontend/src/b/b.css` | +| [ ] | 나머지 탭(각·노을·주말·행사·계절·상식) 옮기기 — 지금은 '옮기는 중' 안내 | | `frontend/src/b/*Page.tsx` | +| [ ] | **[결정 필요]** `mobile/` 템플릿 부속물(`.claude`, `AGENTS.md`, `.vscode`, `LICENSE`, 예제 화면) 둘지 지울지 | create-expo-app 기본 템플릿 | `mobile/` | +| [ ] | `frontend-dev` 개발 컨테이너 실제로 띄워 확인 (이미지 빌드만 확인, 5173이 사용 중이라 실행은 못 함) | 볼륨 경로 바뀜 | `compose.yaml` | +| [ ] | 운영 서버가 git pull 뒤 루트 `package-lock.json`으로 빌드되는지 배포 때 확인 | 빌드 대상이 `./frontend` → `.` | `deploy.sh`, `compose.yaml` | diff --git a/mobile/.claude/settings.json b/mobile/.claude/settings.json new file mode 100644 index 0000000..176e6a5 --- /dev/null +++ b/mobile/.claude/settings.json @@ -0,0 +1,5 @@ +{ + "enabledPlugins": { + "expo@claude-plugins-official": true + } +} diff --git a/mobile/.env.example b/mobile/.env.example new file mode 100644 index 0000000..bc07cf6 --- /dev/null +++ b/mobile/.env.example @@ -0,0 +1,4 @@ +# 앱이 부를 API 주소. 실기기에서는 localhost 대신 PC의 내부 IP (예: http://192.168.0.10:9810) +EXPO_PUBLIC_API_BASE_URL=http://localhost:9810 +# 사진 경로(/season/..)를 붙일 사이트 주소 +EXPO_PUBLIC_SITE_URL=https://weather.o2o.kr diff --git a/mobile/.gitignore b/mobile/.gitignore new file mode 100644 index 0000000..4b00baf --- /dev/null +++ b/mobile/.gitignore @@ -0,0 +1,43 @@ +# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files + +# dependencies +node_modules/ + +# Expo +.expo/ +dist/ +web-build/ +expo-env.d.ts + +# Native +.kotlin/ +*.orig.* +*.jks +*.p8 +*.p12 +*.key +*.mobileprovision + +# Metro +.metro-health-check* + +# debug +npm-debug.* +yarn-debug.* +yarn-error.* + +# macOS +.DS_Store +*.pem + +# local env files +.env*.local + +# typescript +*.tsbuildinfo + +example + +# generated native folders +/ios +/android diff --git a/mobile/AGENTS.md b/mobile/AGENTS.md new file mode 100644 index 0000000..be05e77 --- /dev/null +++ b/mobile/AGENTS.md @@ -0,0 +1,41 @@ +This is an Expo/React Native mobile application. Prioritize mobile-first patterns, performance, and cross-platform compatibility. + +## Expo has changed — do not trust your training data + +Expo ships breaking changes every SDK release. APIs you remember are likely renamed, moved, or removed. Before writing any code that touches an Expo, EAS, or React Native API: + +1. Read the major version of the `expo` package in `package.json`. +2. Fetch the matching versioned docs: `https://docs.expo.dev/versions/v.0.0/` +3. For anything else, fetch https://docs.expo.dev/llms.txt — an index of all Expo docs with corrections to common LLM misconceptions. Follow its links to the specific page you need; never answer from memory. + +## Commands + +Use `bunx` instead of `npx` if the project uses bun (`bun.lock` present). + +```bash +npx expo install # ALWAYS use instead of npm/yarn/pnpm/bun add — resolves SDK-compatible versions +npx expo start # start the dev server +npx expo lint # lint +npx tsc --noEmit # typecheck +npx expo-doctor # diagnose dependency and config issues +npx expo install --fix # fix incompatible package versions +``` + +Run lint and typecheck before declaring any task done. + +## Navigation & Routing + +- Use **Expo Router** for all navigation. Routes live in `src/app/` — every file there is a screen, `_layout.tsx` files define navigators. Keep non-route code (components, hooks, utils) outside `src/app/`. +- Import `Link`, `router`, and `useLocalSearchParams` from `expo-router`. +- Docs: https://docs.expo.dev/router/introduction.md + +## Building with EAS + +Use EAS to build, sign, and submit the app in the cloud (`eas build`, `eas submit`) and to ship over-the-air updates (`eas update`) — no local Xcode or Android Studio required. Run EAS CLI as `bunx eas-cli ` in Bun projects, or `npx eas-cli@latest ` otherwise; substitute that for bare `eas` in docs examples. +Docs: https://docs.expo.dev/eas/index.md + +## Rules + +- If `ios/` and `android/` directories do not exist, they are generated (Continuous Native Generation). Never create or edit them by hand — configure native behavior in `app.json` and config plugins. +- Expo Go only includes its bundled native modules. After adding a library with native code, the app needs a development build: `npx expo run:ios|android` locally, or `eas build --profile development`. +- Prefer recommended Expo modules over third-party libraries, and check your available skills before adding dependencies. Docs: https://docs.expo.dev/versions/latest/index.md diff --git a/mobile/app.json b/mobile/app.json new file mode 100644 index 0000000..ad8d618 --- /dev/null +++ b/mobile/app.json @@ -0,0 +1,43 @@ +{ + "expo": { + "name": "mobile", + "slug": "mobile", + "version": "1.0.0", + "orientation": "portrait", + "icon": "./assets/images/icon.png", + "scheme": "mobile", + "userInterfaceStyle": "automatic", + "ios": { + "icon": "./assets/expo.icon" + }, + "android": { + "adaptiveIcon": { + "backgroundColor": "#E6F4FE", + "foregroundImage": "./assets/images/android-icon-foreground.png", + "backgroundImage": "./assets/images/android-icon-background.png", + "monochromeImage": "./assets/images/android-icon-monochrome.png" + }, + "predictiveBackGestureEnabled": false + }, + "web": { + "output": "static", + "favicon": "./assets/images/favicon.png" + }, + "plugins": [ + "expo-router", + [ + "expo-splash-screen", + { + "backgroundColor": "#208AEF", + "image": "./assets/images/splash-icon.png", + "imageWidth": 76 + } + ], + "expo-secure-store" + ], + "experiments": { + "typedRoutes": true, + "reactCompiler": true + } + } +} diff --git a/mobile/assets/expo.icon/Assets/expo-symbol 2.svg b/mobile/assets/expo.icon/Assets/expo-symbol 2.svg new file mode 100644 index 0000000..51d3676 --- /dev/null +++ b/mobile/assets/expo.icon/Assets/expo-symbol 2.svg @@ -0,0 +1,3 @@ + + + diff --git a/mobile/assets/expo.icon/Assets/grid.png b/mobile/assets/expo.icon/Assets/grid.png new file mode 100644 index 0000000..eefea24 Binary files /dev/null and b/mobile/assets/expo.icon/Assets/grid.png differ diff --git a/mobile/assets/expo.icon/icon.json b/mobile/assets/expo.icon/icon.json new file mode 100644 index 0000000..7a2c33c --- /dev/null +++ b/mobile/assets/expo.icon/icon.json @@ -0,0 +1,40 @@ +{ + "fill" : { + "automatic-gradient" : "extended-srgb:0.00000,0.47843,1.00000,1.00000" + }, + "groups" : [ + { + "layers" : [ + { + "image-name" : "expo-symbol 2.svg", + "name" : "expo-symbol 2", + "position" : { + "scale" : 1, + "translation-in-points" : [ + 1.1008400065293245e-05, + -16.046875 + ] + } + }, + { + "image-name" : "grid.png", + "name" : "grid" + } + ], + "shadow" : { + "kind" : "neutral", + "opacity" : 0.5 + }, + "translucency" : { + "enabled" : true, + "value" : 0.5 + } + } + ], + "supported-platforms" : { + "circles" : [ + "watchOS" + ], + "squares" : "shared" + } +} \ No newline at end of file diff --git a/mobile/assets/images/android-icon-background.png b/mobile/assets/images/android-icon-background.png new file mode 100644 index 0000000..5ffefc5 Binary files /dev/null and b/mobile/assets/images/android-icon-background.png differ diff --git a/mobile/assets/images/android-icon-foreground.png b/mobile/assets/images/android-icon-foreground.png new file mode 100644 index 0000000..3a9e501 Binary files /dev/null and b/mobile/assets/images/android-icon-foreground.png differ diff --git a/mobile/assets/images/android-icon-monochrome.png b/mobile/assets/images/android-icon-monochrome.png new file mode 100644 index 0000000..77484eb Binary files /dev/null and b/mobile/assets/images/android-icon-monochrome.png differ diff --git a/mobile/assets/images/expo-badge-white.png b/mobile/assets/images/expo-badge-white.png new file mode 100644 index 0000000..2863067 Binary files /dev/null and b/mobile/assets/images/expo-badge-white.png differ diff --git a/mobile/assets/images/expo-badge.png b/mobile/assets/images/expo-badge.png new file mode 100644 index 0000000..5d5c5bb Binary files /dev/null and b/mobile/assets/images/expo-badge.png differ diff --git a/mobile/assets/images/expo-logo.png b/mobile/assets/images/expo-logo.png new file mode 100644 index 0000000..6b1642a Binary files /dev/null and b/mobile/assets/images/expo-logo.png differ diff --git a/mobile/assets/images/favicon.png b/mobile/assets/images/favicon.png new file mode 100644 index 0000000..408bd74 Binary files /dev/null and b/mobile/assets/images/favicon.png differ diff --git a/mobile/assets/images/icon.png b/mobile/assets/images/icon.png new file mode 100644 index 0000000..67c777a Binary files /dev/null and b/mobile/assets/images/icon.png differ diff --git a/mobile/assets/images/logo-glow.png b/mobile/assets/images/logo-glow.png new file mode 100644 index 0000000..edc99be Binary files /dev/null and b/mobile/assets/images/logo-glow.png differ diff --git a/mobile/assets/images/react-logo.png b/mobile/assets/images/react-logo.png new file mode 100644 index 0000000..9d72a9f Binary files /dev/null and b/mobile/assets/images/react-logo.png differ diff --git a/mobile/assets/images/react-logo@2x.png b/mobile/assets/images/react-logo@2x.png new file mode 100644 index 0000000..2229b13 Binary files /dev/null and b/mobile/assets/images/react-logo@2x.png differ diff --git a/mobile/assets/images/react-logo@3x.png b/mobile/assets/images/react-logo@3x.png new file mode 100644 index 0000000..a99b203 Binary files /dev/null and b/mobile/assets/images/react-logo@3x.png differ diff --git a/mobile/assets/images/splash-icon.png b/mobile/assets/images/splash-icon.png new file mode 100644 index 0000000..6b1642a Binary files /dev/null and b/mobile/assets/images/splash-icon.png differ diff --git a/mobile/assets/images/tabIcons/explore.png b/mobile/assets/images/tabIcons/explore.png new file mode 100644 index 0000000..73d8258 Binary files /dev/null and b/mobile/assets/images/tabIcons/explore.png differ diff --git a/mobile/assets/images/tabIcons/explore@2x.png b/mobile/assets/images/tabIcons/explore@2x.png new file mode 100644 index 0000000..21b9bd2 Binary files /dev/null and b/mobile/assets/images/tabIcons/explore@2x.png differ diff --git a/mobile/assets/images/tabIcons/explore@3x.png b/mobile/assets/images/tabIcons/explore@3x.png new file mode 100644 index 0000000..422202d Binary files /dev/null and b/mobile/assets/images/tabIcons/explore@3x.png differ diff --git a/mobile/assets/images/tabIcons/home.png b/mobile/assets/images/tabIcons/home.png new file mode 100644 index 0000000..ad5699c Binary files /dev/null and b/mobile/assets/images/tabIcons/home.png differ diff --git a/mobile/assets/images/tabIcons/home@2x.png b/mobile/assets/images/tabIcons/home@2x.png new file mode 100644 index 0000000..22a1f2c Binary files /dev/null and b/mobile/assets/images/tabIcons/home@2x.png differ diff --git a/mobile/assets/images/tabIcons/home@3x.png b/mobile/assets/images/tabIcons/home@3x.png new file mode 100644 index 0000000..f5d1f9a Binary files /dev/null and b/mobile/assets/images/tabIcons/home@3x.png differ diff --git a/mobile/assets/images/tutorial-web.png b/mobile/assets/images/tutorial-web.png new file mode 100644 index 0000000..e4a8c58 Binary files /dev/null and b/mobile/assets/images/tutorial-web.png differ diff --git a/mobile/eslint.config.js b/mobile/eslint.config.js new file mode 100644 index 0000000..ba708ed --- /dev/null +++ b/mobile/eslint.config.js @@ -0,0 +1,10 @@ +// https://docs.expo.dev/guides/using-eslint/ +const { defineConfig } = require('eslint/config'); +const expoConfig = require("eslint-config-expo/flat"); + +module.exports = defineConfig([ + expoConfig, + { + ignores: ["dist/*"], + } +]); diff --git a/mobile/metro.config.js b/mobile/metro.config.js new file mode 100644 index 0000000..e36e93d --- /dev/null +++ b/mobile/metro.config.js @@ -0,0 +1,19 @@ +const path = require('path'); +const { getDefaultConfig } = require('expo/metro-config'); +const { withUniwindConfig } = require('uniwind/metro'); + +const config = getDefaultConfig(__dirname); + +// 루트 node_modules 에는 웹용 react 가 따로 있어, RN 렌더러와 맞는 앱의 react 만 쓰게 고정한다 +const PINNED = ['react', 'react-dom']; +const resolveRequest = config.resolver.resolveRequest; +config.resolver.resolveRequest = (context, moduleName, platform) => { + const pinned = PINNED.find((name) => moduleName === name || moduleName.startsWith(`${name}/`)); + const next = pinned ? { ...context, originModulePath: path.join(__dirname, 'package.json') } : context; + return (resolveRequest ?? context.resolveRequest)(next, moduleName, platform); +}; + +module.exports = withUniwindConfig(config, { + cssEntryFile: './src/global.css', + dtsFile: './src/uniwind-types.d.ts', +}); diff --git a/mobile/package.json b/mobile/package.json new file mode 100644 index 0000000..e3103cd --- /dev/null +++ b/mobile/package.json @@ -0,0 +1,53 @@ +{ + "name": "mobile", + "main": "expo-router/entry", + "version": "1.0.0", + "dependencies": { + "@expo-google-fonts/bagel-fat-one": "^0.4.0", + "@expo-google-fonts/jua": "^0.4.1", + "@expo/ui": "~57.0.23", + "@nalssigak/shared": "*", + "@tanstack/react-query": "^5.104.2", + "expo": "~57.0.28", + "expo-constants": "~57.0.21", + "expo-device": "~57.0.2", + "expo-font": "~57.0.4", + "expo-glass-effect": "~57.0.4", + "expo-image": "~57.0.5", + "expo-linear-gradient": "~57.0.2", + "expo-linking": "~57.0.12", + "expo-router": "~57.0.26", + "expo-secure-store": "~57.0.4", + "expo-splash-screen": "~57.0.10", + "expo-status-bar": "~57.0.1", + "expo-symbols": "~57.0.3", + "expo-system-ui": "~57.0.4", + "expo-web-browser": "~57.0.3", + "react": "19.2.3", + "react-dom": "19.2.3", + "react-native": "0.86.3", + "react-native-gesture-handler": "~2.32.0", + "react-native-reanimated": "4.5.1", + "react-native-safe-area-context": "~5.7.0", + "react-native-screens": "~4.26.0", + "react-native-svg": "15.15.4", + "react-native-web": "~0.21.0", + "react-native-worklets": "0.10.1", + "tailwindcss": "^4.3.3", + "uniwind": "^1.12.2" + }, + "devDependencies": { + "@types/react": "~19.2.2", + "eslint": "^9.0.0", + "eslint-config-expo": "~57.0.2", + "typescript": "~6.0.3" + }, + "scripts": { + "start": "expo start", + "android": "expo start --android", + "ios": "expo start --ios", + "web": "expo start --web", + "lint": "expo lint" + }, + "private": true +} diff --git a/mobile/src/app/_layout.tsx b/mobile/src/app/_layout.tsx new file mode 100644 index 0000000..ce2a4ce --- /dev/null +++ b/mobile/src/app/_layout.tsx @@ -0,0 +1,54 @@ +import '@/lib/api'; +import { BagelFatOne_400Regular } from '@expo-google-fonts/bagel-fat-one'; +import { Jua_400Regular, useFonts } from '@expo-google-fonts/jua'; +import { QueryClientProvider } from '@tanstack/react-query'; +import { Tabs } from 'expo-router/tabs'; +import * as SplashScreen from 'expo-splash-screen'; +import { StatusBar } from 'expo-status-bar'; +import { useEffect } from 'react'; +import { View } from 'react-native'; + +import '@/global.css'; +import { SkyBg } from '@/components/sky-bg'; +import { TabBar } from '@/components/tab-bar'; +import { TopBar } from '@/components/top-bar'; +import { queryClient } from '@/lib/query-client'; +import { RegionProvider } from '@/lib/region'; +import { SkyProvider, useSky } from '@/lib/sky'; + +SplashScreen.preventAutoHideAsync(); + +function Shell() { + const { kind } = useSky(); + return ( + + + + } screenOptions={{ header: () => , sceneStyle: { backgroundColor: 'transparent' } }}> + {/* 메인인 오늘 탭을 가운데에 */} + + + + + + + + ); +} + +export default function RootLayout() { + const [loaded, error] = useFonts({ Jua_400Regular, BagelFatOne_400Regular }); + useEffect(() => { + if (loaded || error) SplashScreen.hideAsync(); + }, [loaded, error]); + if (!loaded && !error) return null; + return ( + + + + + + + + ); +} diff --git a/mobile/src/app/gak.tsx b/mobile/src/app/gak.tsx new file mode 100644 index 0000000..72e02f6 --- /dev/null +++ b/mobile/src/app/gak.tsx @@ -0,0 +1,5 @@ +import { ComingSoon } from '@/components/coming-soon'; + +export default function Screen() { + return ; +} diff --git a/mobile/src/app/index.tsx b/mobile/src/app/index.tsx new file mode 100644 index 0000000..d5a356f --- /dev/null +++ b/mobile/src/app/index.tsx @@ -0,0 +1,36 @@ +import { getFeedOptions, getWeatherTodayOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'; +import { kst, loadOf } from '@nalssigak/shared/lib'; +import { atSlot, PREVIEW } from '@nalssigak/shared/lib/today'; +import { useQuery } from '@tanstack/react-query'; +import { RefreshControl, ScrollView } from 'react-native'; + +import { Hero } from '@/components/today/hero'; +import { EventsBand, SeasonBand, Stories, StoriesSkel, TopBand } from '@/components/today/rails'; +import { Sec, StateBox } from '@/components/ui'; +import { useRegion } from '@/lib/region'; +import { useSky } from '@/lib/sky'; + +export default function TodayScreen() { + const { region } = useRegion(); + const feed = useQuery(getFeedOptions({ query: { region: region.code } })); + const today = useQuery(getWeatherTodayOptions({ query: { region: region.code } })); + const { preview } = useSky(); + const f = feed.data; + const stories = atSlot(f?.stories ?? [], preview); + const sloted = preview != null && stories !== f?.stories; + const bands = f?.bands; + const nowAt = f?.hero?.now_at; + const load = loadOf(feed); + const refresh = () => Promise.all([feed.refetch(), today.refetch()]); + + return ( + } style={{ opacity: feed.isPlaceholderData ? 0.6 : 1 }}> + + + {stories.length ? : load === 'loading' ? : feed.refetch()} empty="오늘 계산된 각이 없어요." />} + {!!bands?.events?.length && } + {!!bands?.top5?.length && g.active) : bands.top5} sub={sloted ? `${PREVIEW[preview].label} 기준` : nowAt ? `${kst(nowAt).h}시 기준` : '오늘 기준'} />} + {!!bands?.season?.length && } + + ); +} diff --git a/mobile/src/app/season.tsx b/mobile/src/app/season.tsx new file mode 100644 index 0000000..f5630c6 --- /dev/null +++ b/mobile/src/app/season.tsx @@ -0,0 +1,5 @@ +import { ComingSoon } from '@/components/coming-soon'; + +export default function Screen() { + return ; +} diff --git a/mobile/src/app/sky.tsx b/mobile/src/app/sky.tsx new file mode 100644 index 0000000..a1e7c3b --- /dev/null +++ b/mobile/src/app/sky.tsx @@ -0,0 +1,5 @@ +import { ComingSoon } from '@/components/coming-soon'; + +export default function Screen() { + return ; +} diff --git a/mobile/src/app/week.tsx b/mobile/src/app/week.tsx new file mode 100644 index 0000000..64de3b6 --- /dev/null +++ b/mobile/src/app/week.tsx @@ -0,0 +1,5 @@ +import { ComingSoon } from '@/components/coming-soon'; + +export default function Screen() { + return ; +} diff --git a/mobile/src/components/coming-soon.tsx b/mobile/src/components/coming-soon.tsx new file mode 100644 index 0000000..d0513ef --- /dev/null +++ b/mobile/src/components/coming-soon.tsx @@ -0,0 +1,11 @@ +import { Text, View } from 'react-native'; + +/** 아직 옮기지 않은 탭 */ +export function ComingSoon({ title }: { title: string }) { + return ( + + {title} + 앱으로 옮기는 중이에요 + + ); +} diff --git a/mobile/src/components/sky-bg.tsx b/mobile/src/components/sky-bg.tsx new file mode 100644 index 0000000..f8b923c --- /dev/null +++ b/mobile/src/components/sky-bg.tsx @@ -0,0 +1,26 @@ +import type { TimeKind } from '@nalssigak/shared/lib'; +import { LinearGradient } from 'expo-linear-gradient'; +import { StyleSheet, View } from 'react-native'; + +import { useSky } from '@/lib/sky'; + +const SKY: Record = { + morning: { colors: ['#ffe0c4', '#fff0e2', '#e4f2ff'], locations: [0, 0.38, 1] }, + day: { colors: ['#cde7ff', '#e9f5ff', '#f7fbff'], locations: [0, 0.45, 1] }, + sunset: { colors: ['#ffd0b5', '#f9c3cf', '#ddd2f6'], locations: [0, 0.42, 1] }, + night: { colors: ['#0e1433', '#1b2356', '#2a2e6e'], locations: [0, 0.5, 1] }, +}; + +const STARS = Array.from({ length: 46 }, (_, i) => ({ left: `${(i * 41 + 7) % 100}%`, top: `${(i * 67 + 3) % 96}%`, size: 1 + (i % 3) * 0.8, opacity: 0.4 + ((i * 7) % 6) / 10 }) as const); + +/** 화면 전체 하늘: 시간대별 색, 밤에는 별 */ +export function SkyBg() { + const { kind } = useSky(); + return ( + + + {kind === 'night' && + STARS.map((s, i) => )} + + ); +} diff --git a/mobile/src/components/svg.tsx b/mobile/src/components/svg.tsx new file mode 100644 index 0000000..45ea166 --- /dev/null +++ b/mobile/src/components/svg.tsx @@ -0,0 +1,39 @@ +import Svg, { Circle, Path, Rect } from 'react-native-svg'; + +export type TabName = 'today' | 'gak' | 'sky' | 'week' | 'season'; + +const line = { fill: 'none', strokeLinecap: 'round', strokeLinejoin: 'round' } as const; + +export function PinIcon({ size, color }: { size: number; color: string }) { + return ( + + + + + ); +} + +export function TabIcon({ name, size, color, strokeWidth }: { name: TabName; size: number; color: string; strokeWidth: number }) { + return ( + + {name === 'today' && } + {name === 'gak' && ( + <> + + + + + + )} + {name === 'sky' && } + {name === 'week' && ( + <> + + + + + )} + {name === 'season' && } + + ); +} diff --git a/mobile/src/components/tab-bar.tsx b/mobile/src/components/tab-bar.tsx new file mode 100644 index 0000000..ececc72 --- /dev/null +++ b/mobile/src/components/tab-bar.tsx @@ -0,0 +1,60 @@ +import type { BottomTabBarProps } from 'expo-router/tabs'; +import { LinearGradient } from 'expo-linear-gradient'; +import { Pressable, Text, View } from 'react-native'; +import { useSafeAreaInsets } from 'react-native-safe-area-context'; +import { useCSSVariable } from 'uniwind'; + +import { TabIcon, type TabName } from '@/components/svg'; +import { useSky } from '@/lib/sky'; + +const LABELS: Record = { + sky: ['sky', '노을'], + gak: ['gak', '각'], + index: ['today', '오늘'], + week: ['week', '주말·행사'], + season: ['season', '계절·상식'], +}; + +/** 아래 탭 막대. 가운데 오늘 탭은 막대 위로 솟은 큰 주황 동그라미 */ +export function TabBar({ state, navigation }: BottomTabBarProps) { + const { bottom } = useSafeAreaInsets(); + const { kind } = useSky(); + const [ink, ink3, orange] = useCSSVariable(['--color-ink', '--color-ink3', '--color-orange']).map(String); + const night = kind === 'night'; + return ( + + {state.routes.map((route, i) => { + const [icon, label] = LABELS[route.name] ?? ['today', route.name]; + const focused = state.index === i; + const onPress = () => { + const event = navigation.emit({ type: 'tabPress', target: route.key, canPreventDefault: true }); + if (!focused && !event.defaultPrevented) navigation.navigate(route.name); + }; + if (icon === 'today') + return ( + + + + + + + + {label} + + + ); + return ( + + + + {label} + + + ); + })} + + ); +} diff --git a/mobile/src/components/today/hero.tsx b/mobile/src/components/today/hero.tsx new file mode 100644 index 0000000..5bf8294 --- /dev/null +++ b/mobile/src/components/today/hero.tsx @@ -0,0 +1,147 @@ +import type { Hero as HeroData, ResWeatherToday, TopIndex } from '@nalssigak/shared/api/client/types.gen'; +import { kindOfHour, kst, type Load, type TimeKind, WEEKDAYS } from '@nalssigak/shared/lib'; +import { KINDS, moonPath, PREVIEW, SLOT_KEY, WANING, WEATHER_ICON, weatherOf } from '@nalssigak/shared/lib/today'; +import { deg, slotAt } from '@nalssigak/shared/lib/weatherText'; +import { useEffect, useState, type ReactNode } from 'react'; +import { Pressable, Text, View } from 'react-native'; +import { LinearGradient } from 'expo-linear-gradient'; +import Svg, { Defs, Path, RadialGradient, Rect, Stop } from 'react-native-svg'; + +import { Ic, Skel } from '@/components/ui'; +import { useSky } from '@/lib/sky'; + +type Mode = 'now' | TimeKind; + +const HERO_BG: Record = { + morning: ['#ffd9b8', '#ffe9d4', '#dff0ff'], + day: ['#9fd3ff', '#cfe9ff', '#f1f8ff'], + sunset: ['#4c42b0', '#6a48b0', '#9a4a88'], + night: ['#141b3d', '#27306a', '#3d3f86'], + gray: ['#a9bbd0', '#cbd7e4', '#eef2f7'], +}; +// 가운데 해(낮)·달(저녁·밤) 색과 글자색 +const ORB: Record<'sun' | 'sunset' | 'night', { stops: [string, string, string, string]; text: string }> = { + sun: { stops: ['#fff5cf', '#ffc86e', '#ff8e4e', '#ee6436'], text: '#5c1f08' }, + sunset: { stops: ['#fff4e6', '#ffd9b8', '#f7a991', '#e07a8f'], text: '#4a2442' }, + night: { stops: ['#ffffff', '#e7e3ff', '#b9b0f2', '#8f86d9'], text: '#2b2a5c' }, +}; +const STARS = Array.from({ length: 26 }, (_, i) => ({ left: `${(i * 37) % 100}%`, top: `${(i * 53) % 60}%`, opacity: 0.4 + ((i * 7) % 6) / 10 }) as const); + +function useNow(ms = 20000) { + const [now, setNow] = useState(() => new Date()); + useEffect(() => { + const id = setInterval(() => setNow(new Date()), ms); + return () => clearInterval(id); + }, [ms]); + return now; +} + +const failed = (load: Load) => load === 'error' || load === 'retrying'; + +// 값이 오기 전엔 스켈레톤, 못 불러왔거나 값이 없으면 '?' +function heroVal(load: Load, v: ReactNode, skel: string) { + if (v != null) return v; + if (load === 'loading') return ; + return ?; +} + +type Props = { hero?: HeroData | null; today?: ResWeatherToday; ranked: TopIndex[]; feedLoad: Load; todayLoad: Load }; + +export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) { + const { preview, setServerKind, setPreview } = useSky(); + const mode: Mode = preview ?? 'now'; + const t = kst(useNow()); + const nowKind = hero?.sky_mode ?? kindOfHour(t.h, t.mo, t.mi); + const kind = mode === 'now' ? nowKind : mode; + // 화면 전체 하늘 배경도 같은 시간대로 맞춘다 + useEffect(() => setServerKind(hero?.sky_mode ?? null), [hero?.sky_mode, setServerKind]); + const slots = today?.slots ?? []; + // 지금은 가장 가까운 3시간 칸. 시간대는 그 시각 칸, 비어 있으면(지난 새벽 칸 등) 그 뒤 첫 예보 칸 + const slotOf = (k: Mode) => { + if (k === 'now') { + const known = slots.filter((x) => x.temp_c != null); + const at = t.h + t.mi / 60; + return known.length ? known.reduce((a, b) => (Math.abs(kst(b.at).h - at) < Math.abs(kst(a.at).h - at) ? b : a)) : undefined; + } + const h = PREVIEW[k].hour; + const s = slots.length ? slotAt(slots, h) : undefined; + return s?.temp_c != null ? s : (slots.find((x) => kst(x.at).h > h && x.temp_c != null) ?? s); + }; + const weather = weatherOf(slotOf(mode)); + const slotScore = mode === 'now' ? undefined : hero?.weather_slots?.[SLOT_KEY[mode]]; + const score = slotScore ?? hero?.weather_score; + const slotTop = mode === 'now' ? undefined : ranked.find((g) => g.active); + const top1 = slotTop ?? hero?.top1; + const dark = kind === 'sunset' || kind === 'night'; + const moon = dark && hero?.moon_name && hero.moon_pct != null ? { pct: hero.moon_pct, waning: WANING.includes(hero.moon_name) } : null; + const when = mode === 'now' || mode === nowKind ? '지금' : PREVIEW[mode].label; + const bubble = slotTop ? (slotTop.score >= 70 ? `${when}은 ${slotTop.name}!` : `${when}은 쉬어 가요`) : hero ? (hero.bubble ?? '지금은 쉬어 가요') : failed(feedLoad) ? '앗, 날씨를 못 불러왔어요' : null; + const status = hero?.status ?? []; + const gray = !dark && weather !== 'clear' && weather !== 'partly'; + const orb = ORB[kind === 'sunset' ? 'sunset' : kind === 'night' ? 'night' : 'sun']; + const text = dark ? 'text-white' : 'text-[#28304a]'; + + return ( + + + {kind === 'night' && STARS.map((s, i) => )} + + {t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일 + + + + + + + + + + + + + + {/* 안 보이는 쪽을 덮어 오늘 밤 달 모양으로 */} + {moon && } + + + {failed(feedLoad) ? '점수를 못 불러왔어요' : `${slotScore != null && mode !== 'now' ? PREVIEW[mode].label : '지금'} 날씨 점수`} + + + {heroVal(feedLoad, score, 'w-[84px] h-10')} + + + + + {bubble ? {bubble} : } + {top1?.summary ? {top1.summary} : feedLoad === 'loading' ? : null} + {/* 상태 한 줄: 습도·불쾌지수·자외선·미세먼지 단계 이름. 조심할 것만 색 */} + {status.length > 0 && ( + + {status.map((x, i) => ( + + {i > 0 && · } + + {x.label} {x.value} + + + ))} + + )} + + + {KINDS.map((k) => { + const isNow = k === nowKind; + const s = slotOf(isNow ? 'now' : k); + const on = k === kind; + return ( + setPreview(isNow ? null : k)} className={`flex-1 items-center rounded-[14px] py-1.5 ${on ? 'bg-white' : ''}`} style={on ? { boxShadow: '0 4px 12px rgb(40 48 74 / 0.1)' } : undefined}> + {isNow ? '지금' : PREVIEW[k].label} + + {heroVal(todayLoad, s?.temp_c != null ? deg(s.temp_c) : null, 'w-7')} + + ); + })} + + + ); +} diff --git a/mobile/src/components/today/rails.tsx b/mobile/src/components/today/rails.tsx new file mode 100644 index 0000000..92dd8aa --- /dev/null +++ b/mobile/src/components/today/rails.tsx @@ -0,0 +1,135 @@ +import type { BandArticle, BandEvent, TopIndex } from '@nalssigak/shared/api/client/types.gen'; +import { cardBg, MEDALS } from '@nalssigak/shared/lib'; +import { LinearGradient } from 'expo-linear-gradient'; +import { Link, type Href } from 'expo-router'; +import type { ReactNode } from 'react'; +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 { useSky } from '@/lib/sky'; + +const CARD = 'overflow-hidden rounded-[22px] border-b-[5px] border-shade bg-card'; + +/** 오늘의 각 순위: 동그라미 + 이름 + 점수. 지금 시간대가 아닌 각은 흐리게 */ +export function Stories({ items }: { items: TopIndex[] }) { + return ( + + {items.map((g, i) => ( + + + {!g.active || g.score < 50 ? ( + + ) : ( + + )} + + + + {i < 3 && g.active && } + + + {g.name} + + {g.active ? {g.score} : 지금 아님} + + ))} + + ); +} + +const SKELS = Array.from({ length: 6 }, (_, i) => i); + +export function StoriesSkel() { + return ( + + {SKELS.map((i) => ( + + + + + + ))} + + ); +} + +function Band({ tone, title, sub, to, children }: { tone: 1 | 2 | 3; title: string; sub: string; to: Href; children: ReactNode }) { + const { kind } = useSky(); + return ( + + + + + + {children} + + ); +} + +function useCardBg() { + const { kind } = useSky(); + return CARD_BG[kind === 'night' ? 'night' : 'day']; +} + +export function EventsBand({ events }: { events: BandEvent[] }) { + const bg = useCardBg(); + return ( + + + {events.map((e, i) => ( + + + + + + {e.status_label} + + + {e.name} + + + ))} + + + ); +} + +export function TopBand({ items, sub }: { items: TopIndex[]; sub: string }) { + return ( + + + {items.slice(0, 5).map((g, i) => ( + + {i < 3 ? : {i + 1}위} + + {g.name} + {g.score} + {g.summary && {g.summary}} + + ))} + + + ); +} + +export function SeasonBand({ news }: { news: BandArticle[] }) { + const bg = useCardBg(); + return ( + + + {news.map((a) => ( + + + + + + {a.title} + {a.meta} + + + ))} + + + ); +} diff --git a/mobile/src/components/top-bar.tsx b/mobile/src/components/top-bar.tsx new file mode 100644 index 0000000..8ae5642 --- /dev/null +++ b/mobile/src/components/top-bar.tsx @@ -0,0 +1,55 @@ +import { getSeasonWeekOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'; +import { kst, seasonOf } from '@nalssigak/shared/lib'; +import { useQuery } from '@tanstack/react-query'; +import { usePathname } from 'expo-router'; +import { useState } from 'react'; +import { Text, View } from 'react-native'; +import { useSafeAreaInsets } from 'react-native-safe-area-context'; +import { useCSSVariable } from 'uniwind'; + +import { PinIcon } from '@/components/svg'; +import { Ic } from '@/components/ui'; +import { useRegion } from '@/lib/region'; +import { useSky } from '@/lib/sky'; + +const TITLES: Record = { '/sky': '노을', '/gak': '오늘의 각', '/week': '주말·행사', '/season': '계절·상식' }; + +/** 로고 옆 계절 칩: 계절 이름과 지금 절기 */ +function SeasonChip() { + const week = useQuery(getSeasonWeekOptions()); + const [month] = useState(() => kst(new Date()).mo); + const [name, icon] = seasonOf(month); + const term = week.data?.term_now?.name; + return ( + + + + {name} + {term && · {term}} + + + ); +} + +export function TopBar() { + const pathname = usePathname(); + const { region } = useRegion(); + const { kind } = useSky(); + const { top } = useSafeAreaInsets(); + const ink = String(useCSSVariable('--color-ink')); + const title = TITLES[pathname]; + return ( + + + {title ? {title} : 날씨각} + + + + + {region.name.split(' ').at(-1)} + + + + + ); +} diff --git a/mobile/src/components/ui.tsx b/mobile/src/components/ui.tsx new file mode 100644 index 0000000..5587a48 --- /dev/null +++ b/mobile/src/components/ui.tsx @@ -0,0 +1,86 @@ +import 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 { ICONS } from '@/lib/icons'; +import { imageUri } from '@/lib/site'; + +/** 아이콘 이름 → 그림. 'none'(데이터 없는 칸)은 빈 자리, 모르는 이름은 구름 낀 해 */ +export function Ic({ name, size, style }: { name: string; size: number; style?: StyleProp }) { + if (name === 'none') return ; + return ; +} + +type Stops = readonly [string, string, ...string[]]; + +/** 위에서 아래로 흐르는 그라데이션 (웹 linear-gradient(180deg, ...)) */ +export function Grad({ colors, locations, className, style, children }: { colors: Stops; locations?: readonly [number, number, ...number[]]; className?: string; style?: StyleProp; children?: ReactNode }) { + return ( + + + {children} + + ); +} + +/** 사진이 있으면 사진, 없거나 못 불러오면 아이콘 */ +export function Thumb({ image, icon, iconSize, className, style, children }: { image?: string | null; icon: string; iconSize: number; className?: string; style?: StyleProp; children?: ReactNode }) { + const [failed, setFailed] = useState(null); + const photo = image && image !== failed ? image : null; + return ( + + {photo ? setFailed(photo)} style={{ position: 'absolute', inset: 0 }} contentFit="cover" /> : } + {children} + + ); +} + +/** 불러오는 동안 자리만 잡는 막대 */ +export function Skel({ className }: { className?: string }) { + return ; +} + +export function Sec({ title, sub, more }: { title: string; sub?: string; more?: Href }) { + return ( + + + {title} + {sub && {sub}} + + {more && ( + + 전체 보기 + + )} + + ); +} + +/** 가로로 넘기는 줄 */ +export function Rail({ children }: { children: ReactNode }) { + return ( + + {children} + + ); +} + +/** 실패·빈 목록 안내. 불러오는 중엔 그리지 않는다(그 자리는 스켈레톤) */ +export function StateBox({ load, onRetry, empty }: { load: Load; onRetry?: () => void; empty?: string }) { + const failed = load === 'error' || load === 'retrying'; + const text = failed ? '정보를 불러오지 못했어요.' : load === 'ready' ? empty : undefined; + if (!text) return null; + return ( + + {text} + {failed && onRetry && ( + + {load === 'retrying' ? '다시 불러오는 중…' : '다시 시도'} + + )} + + ); +} diff --git a/mobile/src/global.css b/mobile/src/global.css new file mode 100644 index 0000000..4bc6941 --- /dev/null +++ b/mobile/src/global.css @@ -0,0 +1,47 @@ +@import 'tailwindcss'; +@import 'uniwind'; + +/* 웹 b.css 의 색 토큰. 밤(dark)은 화면 전체를 어두운 테마로 (글자 대비 AA 4.5:1 이상) */ +@layer theme { + :root { + @variant light { + --color-ink: #28304a; + --color-ink2: #5a6380; + --color-ink3: #8a92aa; + --color-line: #e6ecf4; + --color-page: #f7fbff; + --color-shade: #d9e5f4; + --color-orange: #ff7a45; + --color-orange-deep: #d4552a; + --color-rain: #4f97e3; + --color-heart: #ff3b5c; + --color-card: #ffffff; + --color-chip: #ffffff; + --color-warn: #d4552a; + --color-skel: rgb(40 48 74 / 0.13); + --color-ink-btn: #28304a; + } + @variant dark { + --color-ink: #eef1ff; + --color-ink2: #c3c9ec; + --color-ink3: #a1a9db; + --color-line: rgb(255 255 255 / 0.1); + --color-page: #1a2150; + --color-shade: #141a42; + --color-orange: #ff8a57; + --color-orange-deep: #d4552a; + --color-rain: #4f97e3; + --color-heart: #ff6b85; + --color-card: #222a5c; + --color-chip: #2b3470; + --color-warn: #ffb38a; + --color-skel: rgb(238 241 255 / 0.17); + --color-ink-btn: #4b56b5; + } + } +} + +@theme { + --font-jua: 'Jua_400Regular'; + --font-bagel: 'BagelFatOne_400Regular'; +} diff --git a/mobile/src/lib/api.ts b/mobile/src/lib/api.ts new file mode 100644 index 0000000..fffdde5 --- /dev/null +++ b/mobile/src/lib/api.ts @@ -0,0 +1,13 @@ +import { configureApi } from '@nalssigak/shared/api/setup'; +import * as SecureStore from 'expo-secure-store'; + +configureApi({ + baseUrl: process.env.EXPO_PUBLIC_API_BASE_URL ?? 'http://localhost:9810', + storage: { + getItem: (key) => SecureStore.getItem(key), + setItem: (key, value) => SecureStore.setItem(key, value), + removeItem: (key) => { + SecureStore.deleteItemAsync(key).catch((e: unknown) => console.warn('토큰 삭제 실패', key, e)); + }, + }, +}); diff --git a/mobile/src/lib/colors.ts b/mobile/src/lib/colors.ts new file mode 100644 index 0000000..72b7c40 --- /dev/null +++ b/mobile/src/lib/colors.ts @@ -0,0 +1,28 @@ +// 웹 b.css 의 카드 배경(.b-bg-*)·가로 띠(.b-band-*) 그라데이션. 밤은 어두운 판 +type Stops = readonly [string, string, ...string[]]; + +export const CARD_BG: Record<'day' | 'night', Record> = { + day: { + sky: ['#bfe3ff', '#eef7ff'], + butter: ['#ffe7a0', '#fff6d8'], + peach: ['#ffd2bb', '#fff2ea'], + mint: ['#bfecd6', '#effaf4'], + lilac: ['#d8cffc', '#f4f1ff'], + dusk: ['#7e6fe6', '#f08aa2', '#ffc28a'], + night: ['#1f2658', '#3d3f86'], + }, + night: { + sky: ['#2a4384', '#1f2c62'], + butter: ['#4d4128', '#2c2a3e'], + peach: ['#553632', '#2e2840'], + mint: ['#1f4a45', '#1d2d4a'], + lilac: ['#3d3480', '#262a5e'], + dusk: ['#7e6fe6', '#f08aa2', '#ffc28a'], + night: ['#1f2658', '#3d3f86'], + }, +}; + +export const BAND_BG: Record<'day' | 'night', Record<1 | 2 | 3, Stops>> = { + day: { 1: ['#fff4ec', '#f7fbff'], 2: ['#fff6d8', '#f7fbff'], 3: ['#e9fbf2', '#f7fbff'] }, + night: { 1: ['rgba(255,160,110,0.12)', 'rgba(255,255,255,0)'], 2: ['rgba(255,214,110,0.12)', 'rgba(255,255,255,0)'], 3: ['rgba(110,230,180,0.12)', 'rgba(255,255,255,0)'] }, +}; diff --git a/mobile/src/lib/icons.ts b/mobile/src/lib/icons.ts new file mode 100644 index 0000000..7a9443b --- /dev/null +++ b/mobile/src/lib/icons.ts @@ -0,0 +1,77 @@ +// frontend/public 의 아이콘을 그대로 쓴다. Metro 는 정적 require 만 묶을 수 있어 이름마다 적는다 +export const ICONS: Record = { + apple: require('../../../frontend/public/icons/apple.png'), + baseball: require('../../../frontend/public/icons/baseball.png'), + bear: require('../../../frontend/public/icons/bear.png'), + bike: require('../../../frontend/public/icons/bike.png'), + bingsu: require('../../../frontend/public/icons/bingsu.png'), + blanket: require('../../../frontend/public/icons/blanket.png'), + bronze: require('../../../frontend/public/icons/bronze.png'), + bungeoppang: require('../../../frontend/public/icons/bungeoppang.png'), + camping: require('../../../frontend/public/icons/camping.png'), + carwash: require('../../../frontend/public/icons/carwash.png'), + chestnut: require('../../../frontend/public/icons/chestnut.png'), + chimaek: require('../../../frontend/public/icons/chimaek.png'), + cloud: require('../../../frontend/public/icons/cloud.png'), + coldwind: require('../../../frontend/public/icons/coldwind.png'), + delivery: require('../../../frontend/public/icons/delivery.png'), + dog: require('../../../frontend/public/icons/dog.png'), + drive: require('../../../frontend/public/icons/drive.png'), + fallen_leaf: require('../../../frontend/public/icons/fallen_leaf.png'), + fishing: require('../../../frontend/public/icons/fishing.png'), + flower: require('../../../frontend/public/icons/flower.png'), + garden: require('../../../frontend/public/icons/garden.png'), + glasses: require('../../../frontend/public/icons/glasses.png'), + gold: require('../../../frontend/public/icons/gold.png'), + golf: require('../../../frontend/public/icons/golf.png'), + hiking: require('../../../frontend/public/icons/hiking.png'), + iced_hot: require('../../../frontend/public/icons/iced_hot.png'), + indoordry: require('../../../frontend/public/icons/indoordry.png'), + jipkok: require('../../../frontend/public/icons/jipkok.png'), + jjamppong: require('../../../frontend/public/icons/jjamppong.png'), + kimchi: require('../../../frontend/public/icons/kimchi.png'), + kite: require('../../../frontend/public/icons/kite.png'), + laundry: require('../../../frontend/public/icons/laundry.png'), + letter: require('../../../frontend/public/icons/letter.png'), + makeup: require('../../../frontend/public/icons/makeup.png'), + makgeolli: require('../../../frontend/public/icons/makgeolli.png'), + maple: require('../../../frontend/public/icons/maple.png'), + mask: require('../../../frontend/public/icons/mask.png'), + moon: require('../../../frontend/public/icons/moon.png'), + muggy: require('../../../frontend/public/icons/muggy.png'), + naengmyeon: require('../../../frontend/public/icons/naengmyeon.png'), + netflix: require('../../../frontend/public/icons/netflix.png'), + pajeon: require('../../../frontend/public/icons/pajeon.png'), + peanut: require('../../../frontend/public/icons/peanut.png'), + photo: require('../../../frontend/public/icons/photo.png'), + picnic: require('../../../frontend/public/icons/picnic.png'), + rabbit: require('../../../frontend/public/icons/rabbit.png'), + rain: require('../../../frontend/public/icons/rain.png'), + riverwind: require('../../../frontend/public/icons/riverwind.png'), + running: require('../../../frontend/public/icons/running.png'), + silver: require('../../../frontend/public/icons/silver.png'), + singing_rain: require('../../../frontend/public/icons/singing_rain.png'), + snow: require('../../../frontend/public/icons/snow.png'), + stars: require('../../../frontend/public/icons/stars.png'), + study: require('../../../frontend/public/icons/study.png'), + sun_cloud: require('../../../frontend/public/icons/sun_cloud.png'), + sun: require('../../../frontend/public/icons/sun.png'), + sunset: require('../../../frontend/public/icons/sunset.png'), + sweet_potato: require('../../../frontend/public/icons/sweet_potato.png'), + tangerine: require('../../../frontend/public/icons/tangerine.png'), + taxi: require('../../../frontend/public/icons/taxi.png'), + trot: require('../../../frontend/public/icons/trot.png'), + umbrella: require('../../../frontend/public/icons/umbrella.png'), + vent: require('../../../frontend/public/icons/vent.png'), + walk: require('../../../frontend/public/icons/walk.png'), + waterplay: require('../../../frontend/public/icons/waterplay.png'), + yajang: require('../../../frontend/public/icons/yajang.png'), + bulb: require('../../../frontend/public/b/icons/bulb.png'), + calendar: require('../../../frontend/public/b/icons/calendar.png'), + concert: require('../../../frontend/public/b/icons/concert.png'), + exhibition: require('../../../frontend/public/b/icons/exhibition.png'), + fireworks: require('../../../frontend/public/b/icons/fireworks.png'), + popup: require('../../../frontend/public/b/icons/popup.png'), + sheaf: require('../../../frontend/public/b/icons/sheaf.png'), + thermo: require('../../../frontend/public/b/icons/thermo.png'), +}; diff --git a/mobile/src/lib/query-client.ts b/mobile/src/lib/query-client.ts new file mode 100644 index 0000000..de71424 --- /dev/null +++ b/mobile/src/lib/query-client.ts @@ -0,0 +1,15 @@ +import { focusManager, keepPreviousData, QueryClient } from '@tanstack/react-query'; +import { AppState, Platform } from 'react-native'; + +// 앱이 다시 앞으로 오면 '포커스'로 보고, 5분 넘게 묵은 데이터만 다시 받는다 +if (Platform.OS !== 'web') { + focusManager.setEventListener((setFocused) => { + const sub = AppState.addEventListener('change', (state) => setFocused(state === 'active')); + return () => sub.remove(); + }); +} + +// 웹과 같은 기본값: 다시 받는 동안 이전 결과를 그대로 두어 화면이 비지 않게 한다 +export const queryClient = new QueryClient({ + defaultOptions: { queries: { staleTime: 5 * 60 * 1000, retry: 1, placeholderData: keepPreviousData } }, +}); diff --git a/mobile/src/lib/region.tsx b/mobile/src/lib/region.tsx new file mode 100644 index 0000000..a6bb587 --- /dev/null +++ b/mobile/src/lib/region.tsx @@ -0,0 +1,19 @@ +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'; + +export type RegionApi = { region: RegionData; setRegion: (r: RegionData) => void }; + +const RegionContext = createContext(null); + +export function useRegion() { + const ctx = use(RegionContext); + if (!ctx) throw new Error('useRegion must be used inside RegionProvider'); + return ctx; +} + +export function RegionProvider({ children }: { children: ReactNode }) { + const [region, setRegion] = useState(DEFAULT_REGION); + const api = useMemo(() => ({ region, setRegion }), [region]); + return {children}; +} diff --git a/mobile/src/lib/site.ts b/mobile/src/lib/site.ts new file mode 100644 index 0000000..e77ff79 --- /dev/null +++ b/mobile/src/lib/site.ts @@ -0,0 +1,4 @@ +export const SITE_URL = (process.env.EXPO_PUBLIC_SITE_URL ?? 'https://weather.o2o.kr').replace(/\/+$/, ''); + +/** 서버가 주는 사진 경로가 '/season/..' 처럼 사이트 기준이면 사이트 주소를 붙인다 */ +export const imageUri = (path: string) => (path.startsWith('/') ? `${SITE_URL}${path}` : path); diff --git a/mobile/src/lib/sky.tsx b/mobile/src/lib/sky.tsx new file mode 100644 index 0000000..92219c4 --- /dev/null +++ b/mobile/src/lib/sky.tsx @@ -0,0 +1,30 @@ +import { kindOfHour, kst, type TimeKind } from '@nalssigak/shared/lib'; +import { createContext, use, useEffect, useMemo, useState, type ReactNode } from 'react'; +import { Uniwind } from 'uniwind'; + +/** 화면 전체 하늘의 시간대. 히어로에서 고른 미리보기는 탭을 옮겨도 유지된다 */ +export type SkyApi = { kind: TimeKind; preview: TimeKind | null; setServerKind: (k: TimeKind | null) => void; setPreview: (k: TimeKind | null) => void }; + +const SkyContext = createContext(null); + +export function useSky() { + const ctx = use(SkyContext); + if (!ctx) throw new Error('useSky must be used inside SkyProvider'); + return ctx; +} + +export function SkyProvider({ children }: { children: ReactNode }) { + const [preview, setPreview] = useState(null); + const [serverKind, setServerKind] = useState(null); + const [now, setNow] = useState(() => new Date()); + useEffect(() => { + const id = setInterval(() => setNow(new Date()), 60000); + return () => clearInterval(id); + }, []); + const t = kst(now); + const kind = preview ?? serverKind ?? kindOfHour(t.h, t.mo, t.mi); + // 밤에만 어두운 테마 (기기 다크 모드와 상관없이 하늘 시간대를 따른다) + useEffect(() => Uniwind.setTheme(kind === 'night' ? 'dark' : 'light'), [kind]); + const api = useMemo(() => ({ kind, preview, setPreview, setServerKind }), [kind, preview]); + return {children}; +} diff --git a/mobile/src/uniwind-types.d.ts b/mobile/src/uniwind-types.d.ts new file mode 100644 index 0000000..cc09941 --- /dev/null +++ b/mobile/src/uniwind-types.d.ts @@ -0,0 +1,10 @@ +// NOTE: This file is generated by uniwind and it should not be edited manually. +/// + +declare module 'uniwind' { + export interface UniwindConfig { + themes: readonly ['light', 'dark'] + } +} + +export {} diff --git a/mobile/tsconfig.json b/mobile/tsconfig.json new file mode 100644 index 0000000..2e9a669 --- /dev/null +++ b/mobile/tsconfig.json @@ -0,0 +1,20 @@ +{ + "extends": "expo/tsconfig.base", + "compilerOptions": { + "strict": true, + "paths": { + "@/*": [ + "./src/*" + ], + "@/assets/*": [ + "./assets/*" + ] + } + }, + "include": [ + "**/*.ts", + "**/*.tsx", + ".expo/types/**/*.ts", + "expo-env.d.ts" + ] +}