Compare commits
10
Commits
2ab2271d61
...
61080c6eb2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61080c6eb2 | ||
|
|
86401983fb | ||
|
|
4fc9214de5 | ||
|
|
b5d9adf396 | ||
|
|
865c521ab8 | ||
|
|
d56e906371 | ||
|
|
26bb6a00d2 | ||
|
|
f71dd2cebb | ||
|
|
28ff032160 | ||
|
|
e52f93fdbb |
No files matched your search
@@ -158,3 +158,28 @@
|
||||
| [ ] | **[결정 필요]** 각 순위가 점수 순이 아니라 보임 — 순위가 점수 × 중요도라 환기각 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` |
|
||||
| [x] | 안드로이드 에뮬레이터(Expo Go)에서 확인: 오늘 화면 실데이터, 위치 권한 창, 탭 이동, 각 근거 시트 | | `mobile/` |
|
||||
| [ ] | 안드로이드에서 로그인·좋아요·이미지 공유 눌러 보기 (에뮬레이터가 느려 일부만 확인) | | `mobile/` |
|
||||
| [ ] | Xcode 설치 후 iOS 시뮬레이터에서 전체 확인 | | `mobile/` |
|
||||
| [x] | 앱 아이콘 3D 해 그림(600px 원본)으로: iOS 1024, 안드로이드 적응형(앞·뒤·단색), 스플래시. Expo Go 에선 안 보이고 개발 빌드부터 보임. 스토어용으로는 1024px 이상 원본이 있으면 더 선명 | | `mobile/assets/images/` |
|
||||
| [x] | 3단계-1: 탭 5개 구조·위 막대·하늘 배경·밤 테마(Uniwind dark), Today 히어로·각 순위·행사/TOP5/계절 띠 | | `mobile/src/app/`, `mobile/src/components/` |
|
||||
| [x] | Today 게시물 카드(슬라이드 7종·넘기기·좋아요·댓글·텍스트 공유), 3·6·9번째 글 뒤 띠 | | `mobile/src/components/post/`, `mobile/src/app/index.tsx` |
|
||||
| [x] | 시트 7종(각 근거·읽을거리·댓글·이번 주 특집·로그인/가입·내 정보·지역 고르기)을 RN `Modal`로, 위 막대 로그인/아바타 | 새 패키지 없이 | `mobile/src/components/sheets/`, `mobile/src/components/top-bar.tsx` |
|
||||
| [x] | 고른 지역 저장 (SecureStore) | | `mobile/src/lib/region.tsx` |
|
||||
| [x] | 위치로 지역 찾기(`expo-location`): 처음 켠 사람은 가장 가까운 구로, 지역 시트 '지금 위치로 찾기' | 웹과 같게 | `mobile/src/lib/region.tsx`, `mobile/src/components/sheets/region.tsx` |
|
||||
| [x] | 움직임: 해·구름 떨어지기/둥둥, 비·눈, 스켈레톤 깜빡임, 첫 로딩 덮개, 하늘색 서서히 바뀜, 밤 별 반짝임 ('동작 줄이기' 켜면 멈춤) | | `mobile/src/components/today/hero.tsx`, `first-load.tsx`, `sky-bg.tsx` |
|
||||
| [x] | 나머지 탭(각·노을·주말·행사·계절·상식) 옮기기 | | `mobile/src/app/`, `mobile/src/components/{gak,sky,week,season}/` |
|
||||
| [x] | 이미지로 공유(`react-native-view-shot` + `expo-sharing`): 게시물은 보고 있는 슬라이드, 주말은 고른 날 추천 카드 | 웹 스토리 이미지(머리말·주소 붙인 9:16)와는 다름 | `mobile/src/lib/share-image.ts` |
|
||||
| [x] | 웹과 다른 작은 것들 맞춤: 좋아요 튀는 하트·토스트, 밤 별똥별, 단풍잎 떨어짐, 시 구절 고운바탕, 실패·빈 안내 높이 유지(hold), 시트 배경은 제자리 페이드 | | `mobile/src/` |
|
||||
| [ ] | 공유 이미지를 웹처럼 9:16 스토리(머리말·사이트 주소)로 — 지금은 화면 그대로 찍음. 좋아요 효과는 카드 안에만 뜸(RN에 portal 없음) | 남은 차이 | `mobile/src/lib/share-image.ts`, `mobile/src/components/post/` |
|
||||
| [x] | `mobile/` 템플릿 예제 화면·`.vscode`·`LICENSE`·README 지움, `AGENTS.md`·`.claude`는 둠 | 사용자 결정 | `mobile/` |
|
||||
| [ ] | `frontend-dev` 개발 컨테이너 실제로 띄워 확인 (이미지 빌드만 확인, 5173이 사용 중이라 실행은 못 함) | 볼륨 경로 바뀜 | `compose.yaml` |
|
||||
| [ ] | 운영 서버가 git pull 뒤 루트 `package-lock.json`으로 빌드되는지 배포 때 확인 | 빌드 대상이 `./frontend` → `.` | `deploy.sh`, `compose.yaml` |
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"enabledPlugins": {
|
||||
"expo@claude-plugins-official": true
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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<major>.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 <package> # 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 <command>` in Bun projects, or `npx eas-cli@latest <command>` 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
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"expo": {
|
||||
"name": "날씨각",
|
||||
"slug": "nalssigak",
|
||||
"version": "1.0.0",
|
||||
"orientation": "portrait",
|
||||
"icon": "./assets/images/icon.png",
|
||||
"scheme": "nalssigak",
|
||||
"userInterfaceStyle": "automatic",
|
||||
"ios": {
|
||||
"icon": "./assets/images/icon.png"
|
||||
},
|
||||
"android": {
|
||||
"adaptiveIcon": {
|
||||
"backgroundColor": "#bbeafd",
|
||||
"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": "#bbeafd",
|
||||
"image": "./assets/images/splash-icon.png",
|
||||
"imageWidth": 200
|
||||
}
|
||||
],
|
||||
"expo-secure-store",
|
||||
"expo-sharing",
|
||||
[
|
||||
"expo-location",
|
||||
{
|
||||
"locationWhenInUsePermission": "가장 가까운 동네 날씨를 보여 드리려고 위치를 써요."
|
||||
}
|
||||
]
|
||||
],
|
||||
"experiments": {
|
||||
"typedRoutes": true,
|
||||
"reactCompiler": true
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 107 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 705 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 207 KiB |
@@ -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/*"],
|
||||
}
|
||||
]);
|
||||
@@ -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',
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "mobile",
|
||||
"main": "expo-router/entry",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@expo-google-fonts/bagel-fat-one": "^0.4.0",
|
||||
"@expo-google-fonts/gowun-batang": "^0.4.1",
|
||||
"@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-location": "~57.0.21",
|
||||
"expo-router": "~57.0.26",
|
||||
"expo-secure-store": "~57.0.4",
|
||||
"expo-sharing": "~57.0.23",
|
||||
"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-view-shot": "5.1.0",
|
||||
"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
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import '@/lib/api';
|
||||
import { BagelFatOne_400Regular } from '@expo-google-fonts/bagel-fat-one';
|
||||
import { GowunBatang_400Regular } from '@expo-google-fonts/gowun-batang';
|
||||
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 { FirstLoad } from '@/components/first-load';
|
||||
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';
|
||||
|
||||
SplashScreen.preventAutoHideAsync();
|
||||
|
||||
function Shell() {
|
||||
const { kind } = useSky();
|
||||
return (
|
||||
<View className="flex-1">
|
||||
<SkyBg />
|
||||
<StatusBar style={kind === 'night' ? 'light' : 'dark'} />
|
||||
<Tabs initialRouteName="index" tabBar={(props) => <TabBar {...props} />} screenOptions={{ header: () => <TopBar />, sceneStyle: { backgroundColor: 'transparent' } }}>
|
||||
{/* 메인인 오늘 탭을 가운데에 */}
|
||||
<Tabs.Screen name="sky" />
|
||||
<Tabs.Screen name="gak" />
|
||||
<Tabs.Screen name="index" />
|
||||
<Tabs.Screen name="week" />
|
||||
<Tabs.Screen name="season" />
|
||||
</Tabs>
|
||||
<FirstLoad />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export default function RootLayout() {
|
||||
const [loaded, error] = useFonts({ Jua_400Regular, BagelFatOne_400Regular, GowunBatang_400Regular });
|
||||
useEffect(() => {
|
||||
if (loaded || error) SplashScreen.hideAsync();
|
||||
}, [loaded, error]);
|
||||
if (!loaded && !error) return null;
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<SkyProvider>
|
||||
<AuthProvider>
|
||||
<RegionProvider>
|
||||
<SheetProvider>
|
||||
<Shell />
|
||||
</SheetProvider>
|
||||
</RegionProvider>
|
||||
</AuthProvider>
|
||||
</SkyProvider>
|
||||
</QueryClientProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { listArticlesOptions, listIndicesOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { ArticleCategory, IndexCategory } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { kst, loadOf, seasonOf } from '@nalssigak/shared/lib';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useState } from 'react';
|
||||
import { Pressable, RefreshControl, ScrollView, Text, View } from 'react-native';
|
||||
|
||||
import { GakGrid, GridSkel } from '@/components/gak/grid';
|
||||
import { Podium, PodiumSkel } from '@/components/gak/podium';
|
||||
import { Chips, Ic, Sec, StateBox } from '@/components/ui';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
|
||||
type Cat = 'all' | 'out' | 'food' | 'home' | 'life' | 'core';
|
||||
|
||||
// 마지막 칩은 지금 계절의 제철 각 (예: 가을 각)
|
||||
const CATS: readonly (readonly [Cat, string])[] = [
|
||||
['all', '전체'],
|
||||
['out', '밖에서 놀기'],
|
||||
['food', '먹고 마시기'],
|
||||
['home', '집안일'],
|
||||
['life', '생활 고민'],
|
||||
['core', `${seasonOf(kst(new Date()).mo)[0]} 각`],
|
||||
];
|
||||
|
||||
const CAT_PARAM: Partial<Record<Cat, IndexCategory>> = { out: IndexCategory.OUTSIDE, food: IndexCategory.FOOD, home: IndexCategory.HOME, life: IndexCategory.LIFE };
|
||||
|
||||
export default function GakScreen() {
|
||||
const { region } = useRegion();
|
||||
const { open } = useSheet();
|
||||
const [cat, setCat] = useState<Cat>('all');
|
||||
const q = useQuery(listIndicesOptions({ query: { region: region.code, category: CAT_PARAM[cat], core: cat === 'core' ? true : undefined } }));
|
||||
const articles = useQuery(listArticlesOptions({ query: { category: ArticleCategory.GAK } }));
|
||||
const top = q.data?.top3 ?? [];
|
||||
const items = q.data?.items ?? [];
|
||||
const day = q.data?.day?.split('-').map(Number);
|
||||
const load = loadOf(q);
|
||||
const howto = articles.data?.articles?.find((a) => a.code === 'howgak');
|
||||
|
||||
return (
|
||||
<ScrollView contentContainerClassName="pb-6" refreshControl={<RefreshControl refreshing={q.isRefetching && !q.isPlaceholderData} onRefresh={() => q.refetch()} />}>
|
||||
<Sec title="오늘 1~3위" sub={`${day ? `${day[1]}월 ${day[2]}일 기준 · ` : ''}${region.name}`} />
|
||||
{top.length === 3 ? <Podium top={top} dim={q.isPlaceholderData} /> : load === 'loading' ? <PodiumSkel /> : <StateBox load={load} onRetry={() => q.refetch()} empty="오늘 1~3위를 아직 못 정했어요." hold={<PodiumSkel />} />}
|
||||
<Chips items={CATS} value={cat} onChange={setCat} />
|
||||
{load === 'loading' ? (
|
||||
<GridSkel />
|
||||
) : !items.length ? (
|
||||
// 실패 안내·다시 시도는 위 받침대 자리에 한 번만
|
||||
<StateBox load="ready" empty={load === 'ready' ? '이 분야는 오늘 계산된 각이 없어요.' : '각 목록을 불러오지 못했어요.'} hold={<GridSkel />} boxClassName="inset-3" />
|
||||
) : (
|
||||
<GakGrid items={items} dim={q.isPlaceholderData} />
|
||||
)}
|
||||
{howto && load !== 'loading' && (
|
||||
<Pressable onPress={() => open({ type: 'article', articleId: howto.article_id })} className="mx-3 mt-1.5 flex-row items-center gap-3 rounded-[22px] bg-[#ece7ff] p-3.5">
|
||||
<Ic name="bulb" size={44} />
|
||||
<View className="flex-1">
|
||||
<Text className="font-jua text-[17px] text-[#28304a]">각 점수는 어떻게 매길까?</Text>
|
||||
<Text className="text-[12.5px] font-semibold text-[#5a6380]">기온·비·바람·습도·공기·시간대 6가지로 계산해요</Text>
|
||||
</View>
|
||||
</Pressable>
|
||||
)}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
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 { Fragment, type ReactNode } from 'react';
|
||||
import { RefreshControl, ScrollView } from 'react-native';
|
||||
|
||||
import { PostCard, PostCardSkel } from '@/components/post/post-card';
|
||||
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 posts = f?.posts ?? [];
|
||||
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()]);
|
||||
|
||||
// 웹처럼 3·6·9번째 글 뒤에 띠를 넣고, 글이 모자라면 남은 띠는 맨 뒤에 붙인다
|
||||
const bandAt: [number, ReactNode][] = [
|
||||
[3, bands?.events?.length ? <EventsBand events={bands.events} /> : null],
|
||||
[6, bands?.top5?.length ? <TopBand items={sloted ? stories.filter((g) => g.active) : bands.top5} sub={sloted ? `${PREVIEW[preview].label} 기준` : nowAt ? `${kst(nowAt).h}시 기준` : '오늘 기준'} /> : null],
|
||||
[9, bands?.season?.length ? <SeasonBand news={bands.season} /> : null],
|
||||
];
|
||||
|
||||
return (
|
||||
// 지역마다 새로 그려 넘긴 슬라이드 위치가 남지 않게 한다
|
||||
<ScrollView key={region.code} contentContainerClassName="pb-6" refreshControl={<RefreshControl refreshing={feed.isRefetching && !feed.isPlaceholderData} onRefresh={refresh} />} style={{ opacity: feed.isPlaceholderData ? 0.6 : 1 }}>
|
||||
<Hero hero={f?.hero} today={today.data} ranked={stories} feedLoad={load} todayLoad={loadOf(today)} />
|
||||
<Sec title="오늘의 각" sub="누르면 계산 근거를 보여 줘요" more="/gak" />
|
||||
{stories.length ? <Stories items={stories} /> : load === 'loading' ? <StoriesSkel /> : <StateBox load={load} onRetry={() => feed.refetch()} empty="오늘 계산된 각이 없어요." hold={<StoriesSkel />} boxClassName="inset-x-3 top-3 bottom-1" />}
|
||||
{load === 'loading' && (
|
||||
<>
|
||||
<PostCardSkel />
|
||||
<PostCardSkel />
|
||||
</>
|
||||
)}
|
||||
{/* 글이 없거나 못 받아도 스켈레톤 두 장 자리는 그대로 둔다. 다시 시도는 위 각 줄에 한 번만 */}
|
||||
{load !== 'loading' && !posts.length && (
|
||||
<StateBox
|
||||
load="ready"
|
||||
empty={load === 'ready' ? '오늘 올라온 글이 아직 없어요.' : '글을 불러오지 못했어요.'}
|
||||
hold={
|
||||
<>
|
||||
<PostCardSkel />
|
||||
<PostCardSkel />
|
||||
</>
|
||||
}
|
||||
boxClassName="inset-x-3 top-3.5"
|
||||
/>
|
||||
)}
|
||||
{posts.map((p, i) => (
|
||||
<Fragment key={p.post_id}>
|
||||
<PostCard post={p} />
|
||||
{bandAt.find(([at]) => at === i + 1)?.[1]}
|
||||
</Fragment>
|
||||
))}
|
||||
{feed.isSuccess && bandAt.filter(([at]) => at > posts.length).map(([at, node]) => <Fragment key={at}>{node}</Fragment>)}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { getSeasonWeekOptions, listArticlesOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { ArticleCategory } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { loadOf } from '@nalssigak/shared/lib';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useState } from 'react';
|
||||
import { RefreshControl, ScrollView, View } from 'react-native';
|
||||
|
||||
import { ArticleRow, HeadSkel, RowsSkel, SeasonHead } from '@/components/season/parts';
|
||||
import { Chips, StateBox } from '@/components/ui';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
|
||||
const CATS = [
|
||||
['all', '전체'],
|
||||
['season', '계절 소식'],
|
||||
['tip', '날씨 상식'],
|
||||
['gak', '각 원리'],
|
||||
] as const;
|
||||
|
||||
const CAT_PARAM = { season: ArticleCategory.SEASON, tip: ArticleCategory.TIP, gak: ArticleCategory.GAK } as const;
|
||||
|
||||
export default function SeasonScreen() {
|
||||
const { open } = useSheet();
|
||||
const [cat, setCat] = useState<(typeof CATS)[number][0]>('all');
|
||||
const week = useQuery(getSeasonWeekOptions());
|
||||
const arts = useQuery(listArticlesOptions(cat === 'all' ? undefined : { query: { category: CAT_PARAM[cat] } }));
|
||||
const w = week.data;
|
||||
const list = arts.data?.articles ?? [];
|
||||
const weekLoad = loadOf(week);
|
||||
const artLoad = loadOf(arts);
|
||||
const refresh = () => Promise.all([week.refetch(), arts.refetch()]);
|
||||
|
||||
return (
|
||||
<ScrollView contentContainerClassName="pb-6" refreshControl={<RefreshControl refreshing={(week.isRefetching || arts.isRefetching) && !arts.isPlaceholderData} onRefresh={refresh} />}>
|
||||
{w?.headline ? <SeasonHead week={w} onPress={() => open({ type: 'seasonWeek' })} /> : weekLoad === 'loading' ? <HeadSkel /> : <StateBox load={weekLoad} onRetry={() => week.refetch()} empty="이번 주 특집이 아직 없어요." hold={<HeadSkel />} />}
|
||||
<Chips items={CATS} value={cat} onChange={setCat} />
|
||||
<View className="mt-1.5" style={{ opacity: arts.isPlaceholderData ? 0.6 : 1 }}>
|
||||
{artLoad === 'loading' && <RowsSkel />}
|
||||
{artLoad !== 'loading' && !list.length && <StateBox load={artLoad} onRetry={() => arts.refetch()} empty="읽을거리가 아직 없어요." hold={<RowsSkel />} boxClassName="inset-3" />}
|
||||
{list.map((a) => (
|
||||
<ArticleRow key={a.article_id} article={a} onPress={() => open({ type: 'article', articleId: a.article_id })} />
|
||||
))}
|
||||
</View>
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import { getSkyOptions, getSkyRankingOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { loadOf } from '@nalssigak/shared/lib';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useState } from 'react';
|
||||
import { RefreshControl, ScrollView, View } from 'react-native';
|
||||
|
||||
import { DayTiles, Li, LiSkel, ScoreHelp, SkyHero, Timeline } from '@/components/sky/parts';
|
||||
import { Sec, Skel, StateBox } from '@/components/ui';
|
||||
import { useRegion } from '@/lib/region';
|
||||
|
||||
const THREE = [0, 1, 2];
|
||||
const RANK_SKELS = Array.from({ length: 8 }, (_, i) => i);
|
||||
|
||||
/** 히어로 글자 자리 (실패·빈 안내를 같은 높이로 띄우려고) */
|
||||
function HeroHold() {
|
||||
return (
|
||||
<View>
|
||||
<Skel className="h-7 w-[230px]" />
|
||||
<Skel className="mt-2 w-[180px]" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function LiSkels({ n }: { n: number[] }) {
|
||||
return (
|
||||
<View className="mx-3 mt-1.5">
|
||||
{n.map((i) => (
|
||||
<LiSkel key={i} last={i === n.length - 1} />
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export default function SkyScreen() {
|
||||
const { region } = useRegion();
|
||||
const sky = useQuery(getSkyOptions({ query: { region: region.code } }));
|
||||
const ranking = useQuery(getSkyRankingOptions());
|
||||
const load = loadOf(sky);
|
||||
const rankLoad = loadOf(ranking);
|
||||
const plans = sky.data?.plans ?? [];
|
||||
const [picked, setPicked] = useState<string>();
|
||||
// 타일을 누르면 그날, 아니면 다음에 오는 날
|
||||
const plan = plans.find((p) => p.day === picked) ?? sky.data?.plan ?? undefined;
|
||||
const spots = (sky.data?.spots ?? []).slice(0, 3);
|
||||
const items = (ranking.data?.items ?? []).slice(0, 8);
|
||||
const rise = plan?.kind === 'sunrise';
|
||||
const refresh = () => Promise.all([sky.refetch(), ranking.refetch()]);
|
||||
|
||||
return (
|
||||
<ScrollView contentContainerClassName="pb-6" refreshControl={<RefreshControl refreshing={sky.isRefetching && !sky.isPlaceholderData} onRefresh={refresh} />} style={{ opacity: sky.isPlaceholderData ? 0.6 : 1 }}>
|
||||
{plan || load === 'loading' ? (
|
||||
<SkyHero plan={plan} />
|
||||
) : (
|
||||
<SkyHero>
|
||||
<StateBox load={load} onRetry={() => sky.refetch()} empty="오늘 노을 정보가 없어요." hold={<HeroHold />} boxClassName="inset-x-0 top-1.5 bottom-0" />
|
||||
</SkyHero>
|
||||
)}
|
||||
{plans.length > 1 && <DayTiles plans={plans} day={plan?.day} onPick={setPicked} />}
|
||||
{plan && <ScoreHelp plan={plan} />}
|
||||
<Sec title="언제 보면 좋을까" />
|
||||
{plan?.timeline?.length || load === 'loading' ? <Timeline rows={plan?.timeline} kind={plan?.kind} /> : <StateBox load="ready" empty={load === 'ready' ? '노을 시간 정보가 없어요.' : '노을 시간을 불러오지 못했어요.'} hold={<Timeline />} />}
|
||||
{!rise && <Sec title="가까운 노을 명소" sub="가까운 순 · 방향은 내 동네에서 본 쪽" />}
|
||||
{rise ? null : spots.length ? (
|
||||
<View className="mx-3 mt-1.5">
|
||||
{spots.map((p, i) => (
|
||||
<Li key={p.no} no={p.no} title={p.name} sub={p.direction ? `${p.direction}쪽` : null} right={`${p.distance_km}km`} place={p.name} last={i === 2} />
|
||||
))}
|
||||
{/* 3곳이 안 되면 빈 줄로 높이를 지켜 아래 순위가 밀리지 않게 */}
|
||||
{THREE.slice(spots.length).map((i) => (
|
||||
<LiSkel key={`ghost-${i}`} ghost last={i === 2} />
|
||||
))}
|
||||
</View>
|
||||
) : load === 'loading' ? (
|
||||
<View className="mx-3 mt-1.5">
|
||||
{THREE.map((i) => (
|
||||
<LiSkel key={i} last={i === 2} />
|
||||
))}
|
||||
</View>
|
||||
) : (
|
||||
// 실패 안내·다시 시도는 위 히어로에 한 번만
|
||||
<StateBox load="ready" empty={load === 'ready' ? '근처에 등록된 노을 명소가 없어요.' : '명소 정보를 불러오지 못했어요.'} hold={<LiSkels n={THREE} />} />
|
||||
)}
|
||||
<Sec title="전국 노을 순위" sub={ranking.data?.summary ?? '오늘 기준'} />
|
||||
{items.length ? (
|
||||
<View className="mx-3 mt-1.5">
|
||||
{items.map((r, i) => (
|
||||
<Li key={r.region_code} no={r.rank} title={r.name} sub={[r.note, r.situation_label].filter(Boolean).join(' · ')} right={`${r.score}점`} mine={r.region_code === region.code} last={i === items.length - 1} />
|
||||
))}
|
||||
</View>
|
||||
) : rankLoad === 'loading' ? (
|
||||
<View className="mx-3 mt-1.5">
|
||||
{RANK_SKELS.map((i) => (
|
||||
<LiSkel key={i} last={i === RANK_SKELS.length - 1} />
|
||||
))}
|
||||
</View>
|
||||
) : (
|
||||
<StateBox load={rankLoad} onRetry={() => ranking.refetch()} empty="순위가 아직 없어요." hold={<LiSkels n={RANK_SKELS} />} boxClassName="inset-x-3 top-1.5 bottom-0" />
|
||||
)}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
import { getWeekOptions, getWeekRankingOptions, listEventsOptions, listPlacesOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { loadOf, shortDay } from '@nalssigak/shared/lib';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useRef, useState } from 'react';
|
||||
import { Pressable, RefreshControl, ScrollView, Text, View } from 'react-native';
|
||||
|
||||
import { DayStrip, EventRow, PickCard, PlaceCard, RankRow } from '@/components/week/sections';
|
||||
import { DaysSkel, EventsSkel, PickSkel, PlacesSkel, RankSkel } from '@/components/week/skels';
|
||||
import { Chips, Rail, Sec, Skel, StateBox } from '@/components/ui';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { shareView } from '@/lib/share-image';
|
||||
import { SITE_URL } from '@/lib/site';
|
||||
|
||||
// 불러오는 동안에도 탭 줄 높이를 지키려고 같은 칩을 미리 그린다
|
||||
const RANK_TABS_HOLD = [
|
||||
['토', '토요일'],
|
||||
['일', '일요일'],
|
||||
] as const;
|
||||
|
||||
export default function WeekScreen() {
|
||||
const { region } = useRegion();
|
||||
const week = useQuery(getWeekOptions({ query: { region: region.code } }));
|
||||
const days = week.data?.days ?? [];
|
||||
const [picked, setPicked] = useState<string | null>(null);
|
||||
// 지역을 바꾸면 동네 고르기는 전체로 돌아간다
|
||||
const [areaPick, setAreaPick] = useState({ region: region.code, area: '전체' });
|
||||
const area = areaPick.region === region.code ? areaPick.area : '전체';
|
||||
// 처음에는 이번 토요일을 고른다
|
||||
const sel = days.find((d) => d.day === picked) ?? days.find((d) => d.weekday === '토') ?? days[0];
|
||||
const places = useQuery({ ...listPlacesOptions({ query: { region: region.code, day: sel?.day, area: area === '전체' ? undefined : area } }), enabled: !!sel });
|
||||
const events = useQuery(listEventsOptions({ query: { region: region.code } }));
|
||||
const ranking = useQuery(getWeekRankingOptions());
|
||||
const rankDays = ranking.data?.days ?? [];
|
||||
const [rankPick, setRankPick] = useState<string | null>(null);
|
||||
const rankDay = rankDays.find((d) => d.day === rankPick) ?? rankDays[0];
|
||||
const rankItems = (rankDay?.items ?? []).slice(0, 10);
|
||||
const rankLoad = loadOf(ranking);
|
||||
const areas = places.data?.areas ?? [];
|
||||
const rainy = places.data?.rainy ?? sel?.is_rainy;
|
||||
const placeList = places.data?.places ?? [];
|
||||
const eventList = events.data?.events ?? [];
|
||||
const weekLoad = loadOf(week);
|
||||
const eventLoad = loadOf(events);
|
||||
// 날씨(고른 날)가 와야 명소를 부를 수 있다
|
||||
const placeLoad = sel ? loadOf(places) : weekLoad === 'loading' ? 'loading' : 'ready';
|
||||
const refresh = () => Promise.all([week.refetch(), events.refetch(), ranking.refetch(), sel ? places.refetch() : null]);
|
||||
|
||||
const pickShot = useRef<View>(null);
|
||||
// 고른 날 추천 카드를 이미지로
|
||||
const sendPlan = () => {
|
||||
if (!sel) return;
|
||||
const message = [`${sel.weekday}요일 일정 · ${region.name}`, sel.headline, sel.summary, sel.pick, `날씨각 ${SITE_URL}`].filter(Boolean).join('\n');
|
||||
void shareView(pickShot, { title: `${sel.weekday}요일 일정`, message });
|
||||
};
|
||||
|
||||
const placeSub = sel ? `${sel.weekday}요일은 ${rainy ? '비가 와서 실내 명소를 먼저' : sel.icon === 'sun' ? '맑아서 야외 명소를 먼저' : '비 소식이 없어 야외 명소를 먼저'} 보여 줘요` : weekLoad === 'loading' ? undefined : '날씨에 맞춰 골라 보여 줘요';
|
||||
|
||||
return (
|
||||
<ScrollView key={region.code} contentContainerClassName="pb-6" refreshControl={<RefreshControl refreshing={week.isRefetching && !week.isPlaceholderData} onRefresh={refresh} />}>
|
||||
<Sec title="열흘 날씨" sub="날짜를 누르면 그날 추천이 바뀌어요" />
|
||||
{days.length ? (
|
||||
<DayStrip days={days} selected={sel?.day} onPick={setPicked} dim={week.isPlaceholderData} />
|
||||
) : weekLoad === 'loading' ? (
|
||||
<>
|
||||
<DaysSkel />
|
||||
<PickSkel />
|
||||
</>
|
||||
) : (
|
||||
<StateBox
|
||||
load={weekLoad}
|
||||
onRetry={() => week.refetch()}
|
||||
empty="날씨가 아직 없어요."
|
||||
hold={
|
||||
<>
|
||||
<DaysSkel />
|
||||
<PickSkel />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{sel && (
|
||||
<View ref={pickShot} collapsable={false}>
|
||||
<PickCard day={sel} />
|
||||
</View>
|
||||
)}
|
||||
{(sel || weekLoad !== 'ready') && (
|
||||
<>
|
||||
<Text className="mx-4 mt-3.5 text-[13.5px] font-bold text-ink2">30km 안 · 데이트 명소</Text>
|
||||
<Chips items={['전체', ...areas].map((a) => [a, a] as const)} value={area} onChange={(a) => setAreaPick({ region: region.code, area: a })} disabled={!areas.length} />
|
||||
</>
|
||||
)}
|
||||
{/* 명소 데이터가 없으면 칸 전체를 숨긴다 */}
|
||||
{!(placeLoad === 'ready' && !placeList.length) && (
|
||||
<>
|
||||
<View className="-mt-2.5">
|
||||
<Sec title="날씨 맞춤 데이트 명소" sub={placeSub} />
|
||||
</View>
|
||||
{!placeSub && <Skel className="mx-4 w-56" />}
|
||||
{placeList.length ? (
|
||||
<View style={{ opacity: places.isPlaceholderData ? 0.6 : 1 }}>
|
||||
<Rail>
|
||||
{placeList.map((p, i) => (
|
||||
<PlaceCard key={p.place_id} place={p} index={i} />
|
||||
))}
|
||||
</Rail>
|
||||
</View>
|
||||
) : placeLoad === 'loading' ? (
|
||||
<PlacesSkel />
|
||||
) : (
|
||||
<StateBox load={placeLoad} onRetry={() => places.refetch()} empty={sel ? '30km 안에 데이트 명소가 아직 없어요.' : '날씨를 불러오면 명소를 골라 드려요.'} hold={<PlacesSkel />} />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<Sec title="이번 주말 전국 날씨 순위" sub="낮 10~17시 나들이 날씨 · 대표 지역 30곳 중 10위까지" />
|
||||
{rankDays.length ? (
|
||||
<Chips items={rankDays.map((d) => [d.day, `${d.weekday}요일 ${shortDay(d.day)}`] as const)} value={rankDay?.day ?? ''} onChange={setRankPick} />
|
||||
) : (
|
||||
<Chips items={RANK_TABS_HOLD} value="토" onChange={() => undefined} disabled />
|
||||
)}
|
||||
{rankItems.length ? (
|
||||
<View className="mx-3 mt-1.5" style={{ opacity: ranking.isPlaceholderData ? 0.6 : 1 }}>
|
||||
{rankItems.map((r) => (
|
||||
<RankRow key={r.region_code} item={r} mine={r.region_code === region.code} />
|
||||
))}
|
||||
</View>
|
||||
) : rankLoad === 'loading' ? (
|
||||
<RankSkel />
|
||||
) : (
|
||||
<StateBox load={rankLoad} onRetry={() => ranking.refetch()} empty="주말 예보가 아직 없어요." hold={<RankSkel />} boxClassName="inset-x-3 top-1.5 bottom-0" />
|
||||
)}
|
||||
<Sec title="가까운 축제·행사" sub="30km 안 · 앞으로 30일 · 그날 날씨까지 같이 봐요" />
|
||||
{eventList.length ? (
|
||||
<View style={{ opacity: events.isPlaceholderData ? 0.6 : 1 }}>
|
||||
{eventList.map((e, i) => (
|
||||
<EventRow key={e.event_id} event={e} index={i} />
|
||||
))}
|
||||
</View>
|
||||
) : eventLoad === 'loading' ? (
|
||||
<EventsSkel />
|
||||
) : (
|
||||
<StateBox load={eventLoad} onRetry={() => events.refetch()} empty="30km 안에 열리는 행사가 아직 없어요. 다른 지역을 골라 보세요." hold={<EventsSkel />} boxClassName="inset-x-3 top-2.5 bottom-0" />
|
||||
)}
|
||||
{/* 행사 수가 정해진 뒤에 붙여 목록이 늘어날 때 밀리지 않게 */}
|
||||
{eventLoad !== 'loading' && (
|
||||
<Pressable onPress={sendPlan} disabled={!sel} className="mx-3 mt-4 items-center rounded-full border-b-[5px] border-orange-deep bg-orange p-[13px] disabled:opacity-60">
|
||||
<Text className="font-jua text-[17px] text-white">이번 주말 일정 보내기</Text>
|
||||
</Pressable>
|
||||
)}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { useEffect, type ReactNode } from 'react';
|
||||
import type { ViewStyle } from 'react-native';
|
||||
import Animated, { cancelAnimation, Easing, interpolate, useAnimatedStyle, useReducedMotion, useSharedValue, withDelay, withRepeat, withTiming } from 'react-native-reanimated';
|
||||
|
||||
/** 하늘에서 떨어진 뒤 둥둥 (웹 b-fall: b-drop 1.05초 뒤 b-float 무한). d·f 는 밀리초 */
|
||||
export function Fall({ d, f, amp = 9, style, children }: { d: number; f: number; amp?: number; style?: ViewStyle; children: ReactNode }) {
|
||||
const reduce = useReducedMotion();
|
||||
const drop = useSharedValue(reduce ? 1 : 0);
|
||||
const float = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
if (reduce) return;
|
||||
drop.value = withDelay(d, withTiming(1, { duration: 1050, easing: Easing.bezier(0.22, 0.9, 0.3, 1) }));
|
||||
float.value = withDelay(d + 1050, withRepeat(withTiming(1, { duration: f / 2, easing: Easing.inOut(Easing.ease) }), -1, true));
|
||||
return () => {
|
||||
cancelAnimation(drop);
|
||||
cancelAnimation(float);
|
||||
};
|
||||
}, [reduce, d, f, drop, float]);
|
||||
const anim = useAnimatedStyle(() => {
|
||||
const p = drop.value;
|
||||
const y = interpolate(p, [0, 0.72, 0.86, 1], [-400, 0, -10, 0]) - amp * float.value;
|
||||
const rot = interpolate(p, [0, 0.72, 1], [-10, 2, 0]) + 1.2 * float.value;
|
||||
return {
|
||||
opacity: interpolate(p, [0, 0.55, 1], [0, 1, 1]),
|
||||
transform: [{ translateY: y }, { rotate: `${rot}deg` }, { scaleX: interpolate(p, [0, 0.72, 0.86, 1], [1, 1.04, 1, 1]) }, { scaleY: interpolate(p, [0, 0.72, 0.86, 1], [1, 0.96, 1, 1]) }],
|
||||
};
|
||||
});
|
||||
return <Animated.View style={[style, anim]}>{children}</Animated.View>;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import type { TimeKind } from '@nalssigak/shared/lib';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { StyleSheet, Text, View } from 'react-native';
|
||||
import Animated, { cancelAnimation, Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withRepeat, withSequence, withTiming } from 'react-native-reanimated';
|
||||
|
||||
import { Ic } from '@/components/ui';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
// 덮개 색: 시간대별 하늘 맨 위 색을 반쯤 비치게
|
||||
const COVER: Record<TimeKind, string> = {
|
||||
morning: 'rgb(255 230 207 / 0.72)',
|
||||
day: 'rgb(214 235 255 / 0.72)',
|
||||
sunset: 'rgb(255 216 194 / 0.72)',
|
||||
night: 'rgb(14 20 51 / 0.72)',
|
||||
};
|
||||
|
||||
/** 캐릭터가 통통 뛴다 (웹 b-hop) */
|
||||
function Hop({ name }: { name: string }) {
|
||||
const reduce = useReducedMotion();
|
||||
const t = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
if (reduce) return;
|
||||
const ease = Easing.bezier(0.3, 0, 0.4, 1);
|
||||
t.value = withRepeat(withSequence(withTiming(1, { duration: 405, easing: ease }), withTiming(0, { duration: 495, easing: ease })), -1);
|
||||
return () => cancelAnimation(t);
|
||||
}, [reduce, t]);
|
||||
const style = useAnimatedStyle(() => ({
|
||||
transform: [{ translateY: -22 * t.value }, { scaleX: 1.06 - 0.09 * t.value }, { scaleY: 0.94 + 0.09 * t.value }],
|
||||
transformOrigin: 'bottom',
|
||||
}));
|
||||
return (
|
||||
<Animated.View style={style}>
|
||||
<Ic name={name} size={88} />
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 처음 들어올 때만: 첫 데이터를 다 받을 때까지 하늘 위에 캐릭터와 '날씨 불러오는 중…'. 한 번 사라지면 다시 안 뜬다 */
|
||||
export function FirstLoad() {
|
||||
const queryClient = useQueryClient();
|
||||
const { kind } = useSky();
|
||||
const [done, setDone] = useState(false);
|
||||
const [gone, setGone] = useState(false);
|
||||
// 받기 시작했다가 받는 게 없어지면 끝. 느린 망에서도 10초 넘게 막지 않는다 (그 뒤는 화면 안 스켈레톤이 맡는다)
|
||||
useEffect(() => {
|
||||
let seen = false;
|
||||
const unsubscribe = queryClient.getQueryCache().subscribe(() => {
|
||||
if (queryClient.isFetching() > 0) seen = true;
|
||||
else if (seen) setDone(true);
|
||||
});
|
||||
const id = setTimeout(() => setDone(true), 10000);
|
||||
return () => {
|
||||
unsubscribe();
|
||||
clearTimeout(id);
|
||||
};
|
||||
}, [queryClient]);
|
||||
const shown = useSharedValue(1);
|
||||
useEffect(() => {
|
||||
if (!done) return;
|
||||
shown.value = withTiming(0, { duration: 400 });
|
||||
const id = setTimeout(() => setGone(true), 400);
|
||||
return () => clearTimeout(id);
|
||||
}, [done, shown]);
|
||||
const fade = useAnimatedStyle(() => ({ opacity: shown.value }));
|
||||
if (gone) return null;
|
||||
return (
|
||||
<Animated.View pointerEvents={done ? 'none' : 'auto'} accessibilityRole="progressbar" accessibilityLabel="날씨 불러오는 중" style={[StyleSheet.absoluteFill, { zIndex: 50, backgroundColor: COVER[kind] }, fade]}>
|
||||
<View className="flex-1 items-center justify-center gap-3">
|
||||
<Hop name={kind === 'night' ? 'bear' : 'rabbit'} />
|
||||
<Text className="font-jua text-[19px] text-ink">날씨 불러오는 중…</Text>
|
||||
</View>
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import type { IndexSummary } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { Ic, Skel } from '@/components/ui';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
|
||||
const CELL = 'w-[32%] items-center rounded-[22px] border-b-[5px] border-shade bg-card px-1.5 pt-3 pb-2.5';
|
||||
const SKELS = Array.from({ length: 9 }, (_, i) => i);
|
||||
|
||||
export function GridSkel() {
|
||||
return (
|
||||
<View className="flex-row flex-wrap justify-between gap-y-2 p-3">
|
||||
{SKELS.map((i) => (
|
||||
<View key={i} className={`${CELL} gap-1.5`}>
|
||||
<View className="size-[50px] rounded-full bg-skel" />
|
||||
<Skel className="w-14" />
|
||||
<Skel className="h-5 w-8" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 3칸 바둑판. 지금 시간대가 아니거나 제철이 아닌 각은 흐리게 */
|
||||
export function GakGrid({ items, dim }: { items: IndexSummary[]; dim: boolean }) {
|
||||
const { open } = useSheet();
|
||||
return (
|
||||
<View className="flex-row flex-wrap gap-y-2 p-3" style={{ columnGap: '2%', opacity: dim ? 0.6 : 1 }}>
|
||||
{items.map((g) => (
|
||||
<Pressable
|
||||
key={g.index_id}
|
||||
onPress={() => open({ type: 'gak', indexId: g.index_id })}
|
||||
accessibilityLabel={g.active ? `${g.rank}위 ${g.name} ${g.score}점` : `${g.name}, ${g.in_season === false ? '제철 아님' : '지금 시간대 아님'}`}
|
||||
className={`${CELL} ${g.active ? '' : 'opacity-55'}`}
|
||||
>
|
||||
{g.active && <Text className="absolute top-[7px] left-[9px] font-jua text-[13px] text-ink3">{g.rank}</Text>}
|
||||
{g.season && <Text className="absolute top-2 right-2 text-[10.5px] font-extrabold text-[#1f9d62]">{g.season}</Text>}
|
||||
<Ic name={g.icon} size={50} />
|
||||
<Text numberOfLines={1} className="mt-1 font-jua text-[15px] text-ink">
|
||||
{g.name}
|
||||
</Text>
|
||||
{g.active ? (
|
||||
<Text className={`font-bagel text-[22px] leading-[24px] ${g.score < 50 ? 'text-ink3' : 'text-orange'}`}>{g.score}</Text>
|
||||
) : (
|
||||
<Text className="py-1 text-[12px] leading-[14px] font-extrabold text-ink3">{g.in_season === false ? '제철 아님' : '지금 아님'}</Text>
|
||||
)}
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import type { IndexSummary } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { MEDALS } from '@nalssigak/shared/lib';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { Ic, Skel } from '@/components/ui';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
// 가운데가 높은 3칸: 2위 · 1위 · 3위
|
||||
const ORDER = [1, 0, 2] as const;
|
||||
const FLEX = [1.15, 1, 1];
|
||||
|
||||
/** 1~3위 받침대와 같은 칸의 스켈레톤 */
|
||||
export function PodiumSkel() {
|
||||
return (
|
||||
<View className="flex-row gap-1.5 px-3 pt-3">
|
||||
{ORDER.map((k) => (
|
||||
<View key={k} style={{ flex: FLEX[k] }} className={`items-center gap-1.5 rounded-3xl border-b-[6px] border-shade bg-card px-1.5 ${k === 0 ? 'py-4' : 'mt-6 py-3'}`}>
|
||||
<View className={`aspect-square rounded-full bg-skel ${k === 0 ? 'w-20' : 'w-[62px]'}`} />
|
||||
<Skel className="w-16" />
|
||||
<Skel className="h-6 w-10" />
|
||||
<Skel className="w-full" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function Podium({ top, dim }: { top: IndexSummary[]; dim: boolean }) {
|
||||
const { open } = useSheet();
|
||||
const { kind } = useSky();
|
||||
return (
|
||||
<View className="flex-row gap-1.5 px-3 pt-3" style={{ opacity: dim ? 0.6 : 1 }}>
|
||||
{ORDER.map((k) => {
|
||||
const g = top[k];
|
||||
return (
|
||||
<Pressable key={g.index_id} style={{ flex: FLEX[k] }} onPress={() => open({ type: 'gak', indexId: g.index_id })} className={`items-center overflow-hidden rounded-3xl border-b-[6px] border-shade bg-card px-1.5 ${k === 0 ? 'py-4' : 'mt-6 py-3'}`}>
|
||||
{k === 0 && kind !== 'night' && <LinearGradient colors={['#fff1c4', '#ffffff']} style={{ position: 'absolute', inset: 0 }} />}
|
||||
<View>
|
||||
<Ic name={g.icon} size={k === 0 ? 80 : 62} />
|
||||
<Ic name={MEDALS[k]} size={28} style={{ position: 'absolute', top: -6, left: -12 }} />
|
||||
</View>
|
||||
<View className="mt-1.5 flex-1 justify-center">
|
||||
<Text className="text-center font-jua text-base text-ink">
|
||||
{k + 1}위 {g.name}
|
||||
</Text>
|
||||
</View>
|
||||
<Text className="font-bagel text-[30px] leading-[32px] text-orange">{g.score}</Text>
|
||||
{g.summary && <Text className="text-center text-[11.5px] font-semibold text-ink2">{g.summary}</Text>}
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import Svg, { Path } from 'react-native-svg';
|
||||
|
||||
export const HEART = 'M12 20.5s-8-4.9-8-11A4.6 4.6 0 0 1 12 6.8a4.6 4.6 0 0 1 8 2.7c0 6.1-8 11-8 11z';
|
||||
|
||||
type P = { size: number; color: string };
|
||||
|
||||
export function HeartIcon({ size, color, filled }: P & { filled: boolean }) {
|
||||
return (
|
||||
<Svg viewBox="0 0 24 24" width={size} height={size} fill={filled ? color : 'none'} stroke={color} strokeWidth={1.9}>
|
||||
<Path d={HEART} />
|
||||
</Svg>
|
||||
);
|
||||
}
|
||||
|
||||
export function CommentIcon({ size, color }: P) {
|
||||
return (
|
||||
<Svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke={color} strokeWidth={1.9} strokeLinejoin="round">
|
||||
<Path d="M20.5 12a8.5 8.5 0 0 1-12.6 7.4L3.5 20.5l1.2-4.2A8.5 8.5 0 1 1 20.5 12z" />
|
||||
</Svg>
|
||||
);
|
||||
}
|
||||
|
||||
export function SendIcon({ size, color }: P) {
|
||||
return (
|
||||
<Svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke={color} strokeWidth={1.9} strokeLinecap="round" strokeLinejoin="round">
|
||||
<Path d="M21 3 10 14M21 3l-6.5 18-4-7.5L3 9.5z" />
|
||||
</Svg>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { useEffect } from 'react';
|
||||
import { View } from 'react-native';
|
||||
import Animated, { Easing, interpolate, useAnimatedStyle, useReducedMotion, useSharedValue, withDelay, withTiming } from 'react-native-reanimated';
|
||||
import Svg, { Path } from 'react-native-svg';
|
||||
|
||||
import { HEART } from '@/components/post/icons';
|
||||
|
||||
// 튀어 나가는 작은 하트: x·y 이동, 회전, 색 (웹 BURST)
|
||||
const BURST: [number, number, number, string][] = [
|
||||
[-86, -60, -24, '#ff3b5c'],
|
||||
[84, -66, 22, '#ff8e4e'],
|
||||
[-104, 18, -40, '#ffc86e'],
|
||||
[102, 24, 36, '#ff3b5c'],
|
||||
[-48, -104, -8, '#ff8aa0'],
|
||||
[52, -100, 12, '#ffc86e'],
|
||||
];
|
||||
|
||||
function Bit({ dx, dy, rot, color }: { dx: number; dy: number; rot: number; color: string }) {
|
||||
const p = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
p.value = withDelay(80, withTiming(1, { duration: 900, easing: Easing.bezier(0.2, 0.8, 0.3, 1) }));
|
||||
}, [p]);
|
||||
const style = useAnimatedStyle(() => ({
|
||||
opacity: interpolate(p.value, [0, 0.25, 1], [0, 1, 0]),
|
||||
transform: [{ translateX: dx * p.value }, { translateY: dy * p.value }, { scale: interpolate(p.value, [0, 1], [0.4, 1.1]) }, { rotate: `${rot * p.value}deg` }],
|
||||
}));
|
||||
return (
|
||||
<Animated.View style={[{ position: 'absolute' }, style]}>
|
||||
<Svg viewBox="0 0 24 24" width={20} height={20} fill={color}>
|
||||
<Path d={HEART} />
|
||||
</Svg>
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
function Toast() {
|
||||
const p = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
p.value = withTiming(1, { duration: 1300, easing: Easing.bezier(0.2, 0.9, 0.3, 1) });
|
||||
}, [p]);
|
||||
const style = useAnimatedStyle(() => ({
|
||||
opacity: interpolate(p.value, [0, 0.18, 0.78, 1], [0, 1, 1, 0]),
|
||||
transform: [{ translateY: interpolate(p.value, [0, 0.18, 0.78, 1], [14, 0, 0, -8]) }, { scale: interpolate(p.value, [0, 0.18, 0.3, 1], [0.85, 1.06, 1, 1]) }],
|
||||
}));
|
||||
return (
|
||||
<Animated.View className="absolute top-[58%] rounded-full bg-white px-4 py-2" style={[{ boxShadow: '0 8px 18px rgb(40 48 74 / 0.18)' }, style]}>
|
||||
<Animated.Text className="font-jua text-[17px] text-heart">좋아요했어요!</Animated.Text>
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 좋아요 때 하트 조각이 튀어 나가고 '좋아요했어요!' 가 떴다 사라진다 */
|
||||
export function LikeBurst() {
|
||||
const reduce = useReducedMotion();
|
||||
if (reduce) return null;
|
||||
return (
|
||||
<View pointerEvents="none" className="absolute inset-0 items-center justify-center" accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
|
||||
{BURST.map(([dx, dy, rot, color], k) => (
|
||||
<Bit key={k} dx={dx} dy={dy} rot={rot} color={color} />
|
||||
))}
|
||||
<Toast />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { ScrollView, View, type NativeScrollEvent, type NativeSyntheticEvent } from 'react-native';
|
||||
|
||||
/** 옆으로 한 장씩 넘기는 슬라이드 (웹 Embla 캐러셀 대신 가로 paging ScrollView) */
|
||||
export function Pager({ width, height, onIndex, children }: { width: number; height: number; onIndex: (i: number) => void; children: ReactNode[] }) {
|
||||
const onEnd = (e: NativeSyntheticEvent<NativeScrollEvent>) => onIndex(Math.round(e.nativeEvent.contentOffset.x / width));
|
||||
return (
|
||||
<ScrollView horizontal pagingEnabled showsHorizontalScrollIndicator={false} scrollEnabled={children.length > 1} onMomentumScrollEnd={onEnd} style={{ width, height }}>
|
||||
{children.map((c, i) => (
|
||||
<View key={i} style={{ width, height }}>
|
||||
{c}
|
||||
</View>
|
||||
))}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
/** 슬라이드 위치 점 */
|
||||
export function Dots({ n, index }: { n: number; index: number }) {
|
||||
if (n < 2) return null;
|
||||
const items = Array.from({ length: n }, (_, i) => i);
|
||||
return (
|
||||
<View className="flex-row justify-center gap-1.5 pt-2" accessibilityElementsHidden>
|
||||
{items.map((i) => (
|
||||
<View key={i} className={`h-1.5 rounded-full ${i === index ? 'w-4 bg-orange' : 'w-1.5 bg-ink3/40'}`} />
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
import { likePostMutation, unlikePostMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { PostType, type PostData, type ResFeed } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Animated, Pressable, Text, View } from 'react-native';
|
||||
import Svg, { Path } from 'react-native-svg';
|
||||
import { useCSSVariable } from 'uniwind';
|
||||
|
||||
import { CommentIcon, HEART, HeartIcon, SendIcon } from '@/components/post/icons';
|
||||
import { LikeBurst } from '@/components/post/like-burst';
|
||||
import { Dots, Pager } from '@/components/post/pager';
|
||||
import { slideBg, SlideView } from '@/components/post/slides';
|
||||
import { Ic, Skel } from '@/components/ui';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { shareView } from '@/lib/share-image';
|
||||
import { SITE_URL } from '@/lib/site';
|
||||
|
||||
const ACCOUNTS: Record<PostType, readonly [string, string]> = {
|
||||
[PostType.WEATHER]: ['오늘 날씨', 'sun'],
|
||||
[PostType.GAK]: ['오늘의 각', 'rabbit'],
|
||||
[PostType.SUNSET]: ['노을', 'sunset'],
|
||||
[PostType.SEASON]: ['계절 소식', 'maple'],
|
||||
[PostType.EVENT]: ['가까운 행사', 'fireworks'],
|
||||
[PostType.TIP]: ['날씨 상식', 'bulb'],
|
||||
[PostType.WEEK]: ['주말 예보', 'calendar'],
|
||||
[PostType.ALERT]: ['생활 알림', 'umbrella'],
|
||||
[PostType.TOMORROW]: ['내일 미리보기', 'moon'],
|
||||
[PostType.QUOTE]: ['오늘의 한 문장', 'letter'],
|
||||
[PostType.WEEKEND_PLAN]: ['주말 플랜', 'calendar'],
|
||||
[PostType.AIR]: ['미세먼지', 'vent'],
|
||||
[PostType.DAY_TRIP]: ['당일치기', 'picnic'],
|
||||
[PostType.MOON]: ['오늘 밤 달', 'moon'],
|
||||
[PostType.UV]: ['자외선', 'glasses'],
|
||||
};
|
||||
|
||||
type PostProps = { post: PostData };
|
||||
|
||||
/** 받아 둔 피드 데이터에도 좋아요를 반영한다. 안 하면 다른 탭에 다녀왔을 때 예전 값으로 다시 그려진다 */
|
||||
function patchFeed(queryClient: QueryClient, postId: number, patch: Partial<PostData>) {
|
||||
queryClient.setQueriesData<ResFeed>({ predicate: (q) => (q.queryKey[0] as { _id?: string } | undefined)?._id === 'getFeed' }, (feed) =>
|
||||
feed?.posts ? { ...feed, posts: feed.posts.map((p) => (p.post_id === postId ? { ...p, ...patch } : p)) } : feed,
|
||||
);
|
||||
}
|
||||
|
||||
/** 한 줄 카드 (흐린 날 노을처럼 큰 그림이 필요 없는 소식) */
|
||||
function LineCard({ post }: PostProps) {
|
||||
const [account, avatar] = ACCOUNTS[post.post_type];
|
||||
return (
|
||||
<View className="mx-3 mt-3.5 flex-row items-center gap-3 rounded-[22px] border-b-4 border-shade bg-card px-4 py-3" accessibilityLabel={post.title}>
|
||||
<Ic name={post.icon || avatar} size={40} />
|
||||
<View className="flex-1">
|
||||
<Text className="text-xs font-bold text-ink3">{account}</Text>
|
||||
<Text className="text-sm text-ink2">
|
||||
<Text className="font-jua text-base text-ink">{post.title}</Text> {post.caption}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 인스타식 게시물: 옆으로 넘기는 슬라이드, 두 번 눌러 좋아요 */
|
||||
export function PostCard({ post }: PostProps) {
|
||||
return post.size === 'line' ? <LineCard post={post} /> : <FullCard post={post} />;
|
||||
}
|
||||
|
||||
/** FullCard 와 같은 틀(머리줄·4:5 그림·버튼줄·글 한 줄)의 스켈레톤 */
|
||||
export function PostCardSkel() {
|
||||
return (
|
||||
<View className="mt-3.5 border-y border-line bg-card" accessibilityElementsHidden>
|
||||
<View className="flex-row items-center gap-2.5 px-3 py-2.5">
|
||||
<View className="size-[34px] rounded-full bg-skel" />
|
||||
<View className="gap-1.5">
|
||||
<Skel className="w-12" />
|
||||
<Skel className="w-16" />
|
||||
</View>
|
||||
</View>
|
||||
<View className="aspect-[4/5] bg-skel" />
|
||||
<View className="flex-row gap-3.5 px-3 pt-2.5 pb-1">
|
||||
<View className="size-7 rounded-full bg-skel" />
|
||||
<View className="size-7 rounded-full bg-skel" />
|
||||
<View className="size-7 rounded-full bg-skel" />
|
||||
</View>
|
||||
<View className="gap-2 px-3 pt-1 pb-3">
|
||||
<Skel className="w-20" />
|
||||
<Skel className="w-4/5" />
|
||||
<Skel className="w-32" />
|
||||
<Skel className="w-8" />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 좋아요 때 가운데에 커졌다 사라지는 하트 */
|
||||
function HeartPop() {
|
||||
const [v] = useState(() => new Animated.Value(0));
|
||||
useEffect(() => {
|
||||
Animated.timing(v, { toValue: 1, duration: 800, useNativeDriver: true }).start();
|
||||
}, [v]);
|
||||
const opacity = v.interpolate({ inputRange: [0, 0.25, 0.6, 1], outputRange: [0, 1, 1, 0] });
|
||||
const scale = v.interpolate({ inputRange: [0, 0.25, 0.6, 1], outputRange: [0.3, 1.1, 1, 1] });
|
||||
return (
|
||||
<Animated.View pointerEvents="none" className="absolute inset-0 items-center justify-center" style={{ opacity, transform: [{ scale }] }}>
|
||||
<Svg viewBox="0 0 24 24" width={112} height={112} fill="#ff3b5c">
|
||||
<Path d={HEART} />
|
||||
</Svg>
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
function FullCard({ post }: PostProps) {
|
||||
const { open } = useSheet();
|
||||
const { loggedIn } = useAuth();
|
||||
const [ink, heart] = useCSSVariable(['--color-ink', '--color-heart']).map(String);
|
||||
const liked = !!post.liked;
|
||||
const likeCount = post.like_count;
|
||||
const queryClient = useQueryClient();
|
||||
const like = useMutation(likePostMutation());
|
||||
const unlike = useMutation(unlikePostMutation());
|
||||
const [width, setWidth] = useState(0);
|
||||
const [index, setIndex] = useState(0);
|
||||
const [pop, setPop] = useState(0);
|
||||
const [likeFailed, setLikeFailed] = useState(0);
|
||||
const lastTap = useRef(0);
|
||||
const [account, avatar] = ACCOUNTS[post.post_type];
|
||||
const n = post.slides.length;
|
||||
const patch = (values: Partial<PostData>) => patchFeed(queryClient, post.post_id, values);
|
||||
const comments = () => open({ type: 'comments', postId: post.post_id });
|
||||
const shot = useRef<View>(null);
|
||||
// 지금 보고 있는 슬라이드를 이미지로
|
||||
const share = () => void shareView(shot, { title: post.title, message: `${post.title} · 날씨각 ${SITE_URL}` });
|
||||
|
||||
useEffect(() => {
|
||||
if (!likeFailed) return;
|
||||
const t = setTimeout(() => setLikeFailed(0), 2500);
|
||||
return () => clearTimeout(t);
|
||||
}, [likeFailed]);
|
||||
|
||||
// 화면을 먼저 바꾸고, 실패하면 되돌린다 (서버는 실패도 200 + result.success=false 로 준다)
|
||||
const setLike = (on: boolean) => {
|
||||
if (!loggedIn) return open({ type: 'login' });
|
||||
if (on === liked || like.isPending || unlike.isPending) return;
|
||||
if (on) setPop((p) => p + 1);
|
||||
setLikeFailed(0);
|
||||
patch({ liked: on, like_count: likeCount + (on ? 1 : -1) });
|
||||
const revert = () => {
|
||||
patch({ liked, like_count: likeCount });
|
||||
setLikeFailed(Date.now());
|
||||
};
|
||||
(on ? like : unlike).mutate(
|
||||
{ path: { post_id: post.post_id } },
|
||||
{
|
||||
onSuccess: (res) => (res.result?.success ? patch({ liked: res.liked ?? on, ...(res.like_count != null ? { like_count: res.like_count } : {}) }) : revert()),
|
||||
onError: revert,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const onTap = () => {
|
||||
const now = Date.now();
|
||||
if (now - lastTap.current < 320) {
|
||||
if (liked && loggedIn) setPop((p) => p + 1);
|
||||
else setLike(true);
|
||||
}
|
||||
lastTap.current = now;
|
||||
};
|
||||
|
||||
return (
|
||||
<View className="mt-3.5 border-y border-line bg-card" accessibilityLabel={post.title}>
|
||||
<View className="flex-row items-center gap-2.5 px-3 py-2.5">
|
||||
<View className="size-[34px] rounded-full p-0.5">
|
||||
<LinearGradient colors={['#ff7a45', '#ffc86e', '#8fcaff']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={{ position: 'absolute', inset: 0, borderRadius: 17 }} />
|
||||
<View className="flex-1 items-center justify-center rounded-full bg-card">
|
||||
<Ic name={avatar} size={22} />
|
||||
</View>
|
||||
</View>
|
||||
<View>
|
||||
<Text className="text-sm leading-tight font-extrabold text-ink">날씨각</Text>
|
||||
<Text className="text-xs font-semibold text-ink2">{account}</Text>
|
||||
</View>
|
||||
</View>
|
||||
<Pressable onPress={onTap} onLayout={(e) => setWidth(e.nativeEvent.layout.width)} className="aspect-[4/5] overflow-hidden" accessibilityLabel={n > 1 ? `슬라이드 ${n}장, 옆으로 넘겨 보세요` : undefined}>
|
||||
<View ref={shot} collapsable={false}>
|
||||
{width > 0 && (
|
||||
<Pager width={width} height={(width * 5) / 4} onIndex={setIndex}>
|
||||
{post.slides.map((s, i) => (
|
||||
<SlideView key={i} slide={s} bg={slideBg(post, s)} />
|
||||
))}
|
||||
</Pager>
|
||||
)}
|
||||
</View>
|
||||
{n > 1 && (
|
||||
<View pointerEvents="none" className="absolute top-3 right-3 z-[2] rounded-full bg-[rgb(30_36_56/0.55)] px-[9px] py-[3px]">
|
||||
<Text className="text-xs font-extrabold text-white">
|
||||
{index + 1}/{n}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
{pop > 0 && <HeartPop key={pop} />}
|
||||
{pop > 0 && <LikeBurst key={`b${pop}`} />}
|
||||
{likeFailed > 0 && (
|
||||
<View pointerEvents="none" className="absolute inset-x-0 bottom-4 items-center px-4" accessibilityRole="alert">
|
||||
<Text className="overflow-hidden rounded-full bg-[rgb(30_36_56/0.82)] px-3.5 py-2 text-[13px] font-bold text-white">{liked ? '좋아요를 취소하지 못했어요' : '좋아요를 반영하지 못했어요'}. 다시 해 주세요.</Text>
|
||||
</View>
|
||||
)}
|
||||
</Pressable>
|
||||
<Dots n={n} index={index} />
|
||||
<View className="flex-row items-center gap-3.5 px-3 pt-2.5 pb-1">
|
||||
<Pressable onPress={() => setLike(!liked)} hitSlop={8} accessibilityRole="button" accessibilityState={{ selected: liked }} accessibilityLabel="좋아요">
|
||||
<HeartIcon size={26} color={liked ? heart : ink} filled={liked} />
|
||||
</Pressable>
|
||||
<Pressable onPress={comments} hitSlop={8} accessibilityRole="button" accessibilityLabel="댓글 보기">
|
||||
<CommentIcon size={26} color={ink} />
|
||||
</Pressable>
|
||||
<Pressable onPress={share} hitSlop={8} accessibilityRole="button" accessibilityLabel="보내기">
|
||||
<SendIcon size={26} color={ink} />
|
||||
</Pressable>
|
||||
</View>
|
||||
<Text className="px-3 py-0.5 text-sm font-extrabold text-ink">좋아요 {likeCount.toLocaleString()}개</Text>
|
||||
<Text className="px-3 py-0.5 text-sm text-ink">
|
||||
<Text className="font-extrabold">날씨각 </Text>
|
||||
{post.caption}
|
||||
</Text>
|
||||
<Pressable onPress={comments}>
|
||||
<Text className="px-3 pt-[3px] text-sm font-semibold text-ink3">{post.comment_count ? `댓글 ${post.comment_count}개 모두 보기` : '첫 댓글 남기기'}</Text>
|
||||
</Pressable>
|
||||
<Text className="px-3 pt-1 pb-3 text-[11.5px] font-semibold text-ink3">오늘</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
import type { GakSlide, HoursSlide, PlanSlide, PostData, RowsSlide, SunsetSlide, WeekSlide } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { PostType, SlotTone } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { cardBg, clockShort } from '@nalssigak/shared/lib';
|
||||
import type { SlideBg } from '@nalssigak/shared/lib/types';
|
||||
import { deg } from '@nalssigak/shared/lib/weatherText';
|
||||
import { Image } from 'expo-image';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import type { ReactNode } from 'react';
|
||||
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
||||
import Svg, { Polygon } from 'react-native-svg';
|
||||
|
||||
import { Credit, Ic, Rows, Thumb } from '@/components/ui';
|
||||
import { CARD_BG } from '@/lib/colors';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { imageUri } from '@/lib/site';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
export type Slide = HoursSlide | RowsSlide | GakSlide | SunsetSlide | WeekSlide | PlanSlide;
|
||||
|
||||
type Stops = readonly [string, string, ...string[]];
|
||||
|
||||
const GAK_BG: SlideBg[] = ['butter', 'peach', 'lilac'];
|
||||
const ROW_ICON_BG: Record<string, SlideBg> = { umbrella: 'lilac', vent: 'mint', sunset: 'peach', thermo: 'sky', maple: 'peach', moon: 'lilac', glasses: 'butter' };
|
||||
const DARK = new Set<SlideBg>(['dusk', 'night']);
|
||||
|
||||
// 노을 하늘 상황(1 가려짐 2 낮은 구름 3 물들 구름 적음 4 넓게 물듦 5 두꺼움)별 하늘, 시간 칸 색 (웹 .b-sit-*, .b-cut-*)
|
||||
const SIT_BG: Record<number, { colors: Stops; locations: readonly [number, number, ...number[]] }> = {
|
||||
1: { colors: ['#6f7690', '#9aa0b4', '#b9b4c0'], locations: [0, 0.55, 1] },
|
||||
2: { colors: ['#7a7f9c', '#a7a3bb', '#c9b8b8'], locations: [0, 0.55, 1] },
|
||||
3: { colors: ['#4b5aa8', '#7f86c6', '#e9b9a8', '#ffb27a', '#ff8a4c'], locations: [0, 0.38, 0.68, 0.86, 1] },
|
||||
4: { colors: ['#5b3f9e', '#c2559a', '#ff7a6a', '#ffb35c'], locations: [0, 0.4, 0.68, 1] },
|
||||
5: { colors: ['#6a6aa0', '#a98fb4', '#e3b1a0'], locations: [0, 0.55, 1] },
|
||||
};
|
||||
const CUT_BG: Stops[] = [
|
||||
['#9fd0ff', '#ffd79a', '#ff9a5c'],
|
||||
['#8f7cf0', '#ff6f8e', '#ff8a4c'],
|
||||
['#34306e', '#7a5cc8'],
|
||||
];
|
||||
// 건물 실루엣 (웹 .b-skyline clip-path)
|
||||
const SKYLINE = '0,55 8,55 8,30 15,30 15,50 22,50 22,10 28,10 28,45 36,45 36,25 44,25 44,55 52,55 52,35 60,35 60,5 66,5 66,40 74,40 74,20 82,20 82,50 90,50 90,30 100,30 100,100 0,100';
|
||||
|
||||
const HOUR_TONE: Record<string, { bg: string; edge: string }> = {
|
||||
[SlotTone.NIGHT]: { bg: '#e3e7ff', edge: '#c7cff5' },
|
||||
[SlotTone.SUNSET]: { bg: '#ffe3d2', edge: '#ffc19f' },
|
||||
};
|
||||
|
||||
/** 배경색은 API에 없어 글 종류·아이콘으로 고른다 */
|
||||
export function slideBg(post: PostData, slide: Slide): SlideBg {
|
||||
if (slide.kind === 'hours') return 'sky';
|
||||
if (slide.kind === 'sunset') return 'dusk';
|
||||
if (slide.kind === 'week') return 'mint';
|
||||
if (slide.kind === 'plan') return slide.eyebrow.startsWith('일') ? 'peach' : 'butter';
|
||||
if (slide.kind === 'gak') return GAK_BG[post.post_id % GAK_BG.length];
|
||||
if (post.post_type === PostType.EVENT) return 'night';
|
||||
if (post.post_type === PostType.TIP) return 'sky';
|
||||
if (post.post_type === PostType.AIR) return slide.icon === 'vent' ? 'mint' : 'lilac';
|
||||
if (post.post_type === PostType.DAY_TRIP) return slide.image ? 'night' : 'mint';
|
||||
return (ROW_ICON_BG[slide.icon] ?? cardBg(slide.icon, post.post_id)) as SlideBg;
|
||||
}
|
||||
|
||||
function Base({ colors, locations, children }: { colors: Stops; locations?: readonly [number, number, ...number[]]; children: ReactNode }) {
|
||||
return (
|
||||
<View className="flex-1 px-5 py-[22px]">
|
||||
<LinearGradient colors={colors} locations={locations} style={StyleSheet.absoluteFill} />
|
||||
{children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function Eyebrow({ children, light, className }: { children: ReactNode; light?: boolean; className?: string }) {
|
||||
return <Text className={`text-[13px] font-extrabold opacity-75 ${light ? 'text-white' : 'text-ink'} ${className ?? ''}`}>{children}</Text>;
|
||||
}
|
||||
|
||||
function Big({ children, light, className }: { children: ReactNode; light?: boolean; className?: string }) {
|
||||
return <Text className={`mt-1.5 font-jua text-[29px] leading-tight ${light ? 'text-white' : 'text-ink'} ${className ?? ''}`}>{children}</Text>;
|
||||
}
|
||||
|
||||
function Pic({ name, widthPct = 42 }: { name: string; widthPct?: number }) {
|
||||
return (
|
||||
<View pointerEvents="none" className="absolute top-[30%] right-3.5 aspect-square" style={{ width: `${widthPct}%` }}>
|
||||
<Ic name={name} size={0} style={{ width: '100%', height: '100%' }} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
|
||||
const { open } = useSheet();
|
||||
const { kind } = useSky();
|
||||
const palette = CARD_BG[kind === 'night' ? 'night' : 'day'];
|
||||
const colors = palette[bg] ?? palette.sky;
|
||||
const light = DARK.has(bg);
|
||||
|
||||
if (slide.kind === 'hours') {
|
||||
const temps = slide.hours.flatMap((h) => (h.temp_c == null ? [] : [h.temp_c]));
|
||||
const lo = Math.min(...temps);
|
||||
const span = Math.max(...temps) - lo || 1;
|
||||
return (
|
||||
<Base colors={palette.sky}>
|
||||
<Eyebrow>{slide.eyebrow}</Eyebrow>
|
||||
<Big>{slide.line}</Big>
|
||||
<View className="mt-3.5 flex-1 flex-row gap-2">
|
||||
{slide.hours.map((h) => {
|
||||
const tone = HOUR_TONE[h.tone ?? ''];
|
||||
return (
|
||||
<View key={h.label} className={`flex-1 items-center justify-between overflow-hidden rounded-[18px] px-1 pt-2.5 pb-[9px] ${tone ? '' : 'border-b-[5px] border-shade bg-card'}`} style={tone ? { backgroundColor: tone.bg, borderBottomWidth: 5, borderColor: tone.edge } : undefined}>
|
||||
{h.temp_c != null && <LinearGradient colors={['rgba(255,122,69,0.1)', 'rgba(255,122,69,0.34)']} style={{ position: 'absolute', left: 0, right: 0, bottom: 0, height: `${20 + ((h.temp_c - lo) / span) * 70}%` }} />}
|
||||
<Text className={`text-xs font-bold ${tone ? 'text-[#5a6380]' : 'text-ink2'}`}>{h.label}</Text>
|
||||
<Ic name={h.icon} size={34} />
|
||||
<Text className={`font-bagel text-[21px] ${tone ? 'text-[#28304a]' : 'text-ink'}`}>{deg(h.temp_c)}</Text>
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
</Base>
|
||||
);
|
||||
}
|
||||
if (slide.kind === 'gak')
|
||||
return (
|
||||
<Base colors={colors}>
|
||||
<Eyebrow>오늘의 각 · {slide.rank}위</Eyebrow>
|
||||
<Big>{slide.line}</Big>
|
||||
<Pic name={slide.code} />
|
||||
<Text className="mt-auto font-bagel text-[82px] leading-[82px] text-orange">{slide.score}</Text>
|
||||
<Text className="font-jua text-[29px] leading-tight text-ink">{slide.name}</Text>
|
||||
<Eyebrow className="mt-1">{slide.summary}</Eyebrow>
|
||||
<Pressable onPress={() => open({ type: 'gak', indexId: slide.index_id })} className="mt-3 self-start rounded-full border-b-[5px] border-orange-deep bg-orange px-4 py-[9px]">
|
||||
<Text className="font-jua text-[15px] text-white">계산 근거 보기</Text>
|
||||
</Pressable>
|
||||
</Base>
|
||||
);
|
||||
if (slide.kind === 'sunset') {
|
||||
const sit = slide.situation ? SIT_BG[slide.situation] : undefined;
|
||||
return (
|
||||
<Base colors={sit?.colors ?? palette.dusk} locations={sit?.locations}>
|
||||
<Eyebrow light>{slide.eyebrow}</Eyebrow>
|
||||
{/* 노을 탭 히어로와 같은 순서: 결론 → 가장 붉을 때 → 쉬운 이유 */}
|
||||
<Big light>{slide.headline ?? slide.grade_label}</Big>
|
||||
{slide.line && <Text className="mt-0.5 font-jua text-[18px] text-white">{slide.line}</Text>}
|
||||
<View className="mt-3 flex-1 gap-2">
|
||||
{slide.cuts.map((c, i) => (
|
||||
<View key={c.kind} className="flex-1 overflow-hidden rounded-2xl px-3 py-2">
|
||||
<LinearGradient colors={CUT_BG[Math.min(i, 2)]} style={StyleSheet.absoluteFill} />
|
||||
<Svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', left: 0, right: 0, bottom: 0, height: '32%' }}>
|
||||
<Polygon points={SKYLINE} fill="#2d2440" />
|
||||
</Svg>
|
||||
<Text className="font-bagel text-[21px] text-white">
|
||||
{clockShort(c.at)}
|
||||
<Text className="font-jua text-sm"> {c.label}</Text>
|
||||
</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</Base>
|
||||
);
|
||||
}
|
||||
if (slide.kind === 'week')
|
||||
return (
|
||||
<Base colors={palette.mint}>
|
||||
<Eyebrow>{slide.eyebrow}</Eyebrow>
|
||||
<Big>{slide.line}</Big>
|
||||
{/* 칸은 제목 바로 아래, 팁만 맨 아래로 */}
|
||||
<View className="mt-4 flex-row flex-wrap gap-2.5">
|
||||
{slide.days.map((d) => (
|
||||
<View key={d.day} className="grow basis-[45%] gap-0.5 rounded-[18px] border-b-[5px] border-shade bg-card/85 px-3 py-2.5">
|
||||
<Ic name={d.icon} size={34} />
|
||||
<Text className="font-jua text-lg text-ink">
|
||||
{d.weekday} {d.day.split('-').slice(1).map(Number).join('.')}
|
||||
</Text>
|
||||
<Text className="font-jua text-[22px] text-ink">
|
||||
<Text className="text-rain">{deg(d.temp_min_c)}</Text> → <Text className="text-orange">{deg(d.temp_max_c)}</Text>
|
||||
</Text>
|
||||
<Text className="text-xs font-bold text-ink2">
|
||||
비 {d.rain_prob ?? '?'}%{d.temp_min_c != null && d.temp_max_c != null && ` · 일교차 ${Math.round(d.temp_max_c - d.temp_min_c)}°`}
|
||||
</Text>
|
||||
{d.gaks && d.gaks.length > 0 && (
|
||||
<View className="mt-2 gap-1.5 border-t border-shade pt-2" accessibilityLabel={`${d.weekday}요일 대표 각`}>
|
||||
<Text className="text-[11px] font-extrabold text-ink2">이날 할 만한 각</Text>
|
||||
{d.gaks.map((g) => (
|
||||
<View key={g.index_id} className="flex-row items-center gap-1.5">
|
||||
<Ic name={g.icon} size={26} />
|
||||
<Text numberOfLines={1} className="flex-1 text-[14px] font-bold text-ink">
|
||||
{g.name}
|
||||
</Text>
|
||||
<Text className="font-bagel text-[16px] text-orange">{g.score}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
{slide.tip && <Text className="mt-auto overflow-hidden rounded-[14px] bg-ink-btn px-3 py-2.5 text-[13px] leading-snug font-bold text-white">{slide.tip}</Text>}
|
||||
</Base>
|
||||
);
|
||||
if (slide.kind === 'plan') {
|
||||
const credits = [...new Set(slide.steps.flatMap((st) => (st.image && st.image_credit ? [st.image_credit] : [])))];
|
||||
return (
|
||||
<Base colors={colors}>
|
||||
<Eyebrow>{slide.eyebrow}</Eyebrow>
|
||||
<Big className="text-[24px]">{slide.line}</Big>
|
||||
<View className="mt-auto gap-2">
|
||||
{slide.steps.map((st, i) => (
|
||||
<View key={i} className="flex-row items-center gap-1.5 rounded-[14px] bg-card/80 px-2 py-1.5">
|
||||
<Text className="w-[52px] font-jua text-sm text-ink2">{st.time}</Text>
|
||||
<Ic name={st.icon} size={22} />
|
||||
<View className="ml-1 flex-1">
|
||||
<Text numberOfLines={1} className="text-[13.5px] font-bold text-ink">
|
||||
{st.title}
|
||||
</Text>
|
||||
<Text numberOfLines={1} className="text-[11.5px] font-semibold text-ink2">
|
||||
{st.sub}
|
||||
</Text>
|
||||
</View>
|
||||
{st.image && <Thumb image={st.image} icon={st.icon} iconSize={26} className="size-[46px] rounded-[10px]" />}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
{credits.length > 0 && <Text className="mt-1.5 text-right text-[10px] font-semibold text-ink2">사진 {credits.join(' · ')}</Text>}
|
||||
</Base>
|
||||
);
|
||||
}
|
||||
if (slide.kind === 'rows' && slide.image)
|
||||
return (
|
||||
<View className="flex-1 justify-end">
|
||||
<Image source={{ uri: imageUri(slide.image) }} style={StyleSheet.absoluteFill} contentFit="cover" />
|
||||
{slide.image_credit && <Credit text={slide.image_credit} className="top-2.5 right-2.5" />}
|
||||
<View className="px-5 pt-20 pb-3.5">
|
||||
<LinearGradient colors={['rgba(16,20,34,0)', 'rgba(16,20,34,0.55)', 'rgba(16,20,34,0.85)']} locations={[0, 0.35, 1]} style={StyleSheet.absoluteFill} />
|
||||
<Eyebrow light>{slide.eyebrow}</Eyebrow>
|
||||
<Big light>{slide.line}</Big>
|
||||
<Rows rows={slide.rows ?? []} dark />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
return (
|
||||
<Base colors={colors}>
|
||||
<Eyebrow light={light} className={light ? 'opacity-85' : undefined}>
|
||||
{slide.eyebrow}
|
||||
</Eyebrow>
|
||||
<Big light={light} className="z-[1]">
|
||||
{slide.line}
|
||||
</Big>
|
||||
<Pic name={slide.icon} widthPct={36} />
|
||||
<Rows rows={slide.rows ?? []} dark={light} />
|
||||
</Base>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import type { ArticleSummary, ResSeasonWeek } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { ARTICLE_LABEL, cardBg, dateRange, shortDay } from '@nalssigak/shared/lib';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { Fall } from '@/components/fall';
|
||||
import { Credit, Ic, Skel, Thumb } from '@/components/ui';
|
||||
import { CARD_BG } from '@/lib/colors';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
const HEAD_BOX = 'mx-3 mt-3 min-h-[250px] overflow-hidden rounded-[28px] p-5';
|
||||
const ROW = 'flex-row items-center gap-3 border-b-[1.5px] border-line px-4 py-3.5';
|
||||
const ROW_SKELS = [0, 1, 2, 3];
|
||||
|
||||
// 분류 글자색 (웹 ARTICLE_CAT). 밤엔 밝게
|
||||
const CAT_COLOR: Record<number, [string, string]> = { 1: ['#1f9d62', '#4fd39a'], 2: ['#7a5cd6', '#b9a6ff'], 3: ['#ff7a45', '#ff8a57'] };
|
||||
|
||||
/** 특집 상자와 같은 틀: 머리말 · 제목 두 줄 · 시 한 줄 · 절기 막대 */
|
||||
export function HeadSkel() {
|
||||
return (
|
||||
<View className={`${HEAD_BOX} gap-1.5 bg-card`}>
|
||||
<Skel className="w-36" />
|
||||
<Skel className="mt-1 h-7 w-[62%]" />
|
||||
<Skel className="h-7 w-[40%]" />
|
||||
<Skel className="mt-auto h-5 w-[72%]" />
|
||||
<Skel className="mt-2.5 w-[70%]" />
|
||||
<View className="h-[7px] w-[70%] rounded-full bg-skel" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function RowsSkel() {
|
||||
return (
|
||||
<>
|
||||
{ROW_SKELS.map((i) => (
|
||||
<View key={i} className={ROW}>
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="w-12" />
|
||||
<Skel className="h-4 w-48" />
|
||||
<Skel className="w-14" />
|
||||
</View>
|
||||
<View className="h-[84px] w-[84px] rounded-[18px] bg-skel" />
|
||||
</View>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** 이번 주 특집: 제목·시·절기 막대. 누르면 이번 주 절기 창 */
|
||||
export function SeasonHead({ week: w, onPress }: { week: ResSeasonWeek; onPress: () => void }) {
|
||||
const { kind } = useSky();
|
||||
const night = kind === 'night';
|
||||
const progress = Math.round((w.progress ?? 0) * 100);
|
||||
const poem = w.poem_lines ?? [];
|
||||
return (
|
||||
<Pressable onPress={onPress} className={HEAD_BOX}>
|
||||
<LinearGradient colors={CARD_BG[night ? 'night' : 'day'].peach} style={{ position: 'absolute', inset: 0 }} />
|
||||
<Fall d={100} f={4800} style={{ position: 'absolute', top: '18%', right: 14, width: '38%', alignItems: 'center' }}>
|
||||
<Ic name="maple" size={140} />
|
||||
</Fall>
|
||||
<Text className="text-[13px] font-extrabold text-ink opacity-75">이번 주 특집{w.start && w.end ? ` · ${dateRange(w.start, w.end)}` : ''}</Text>
|
||||
<Text className="mt-1 max-w-[62%] font-jua text-[29px] leading-tight text-ink">{w.headline}</Text>
|
||||
{poem.length > 0 && <Text className="mt-auto max-w-[72%] pt-3 font-batang text-[22px] leading-[37px] text-ink">{poem.join('\n')}</Text>}
|
||||
{w.term_now && w.term_next && (
|
||||
<View className={`max-w-[70%] ${poem.length ? 'mt-2.5' : 'mt-auto'}`}>
|
||||
<View className="flex-row justify-between">
|
||||
<Text className="text-xs font-extrabold text-ink2">
|
||||
{w.term_now.name} {shortDay(w.term_now.day)}
|
||||
</Text>
|
||||
<Text className="text-xs font-extrabold text-ink2">
|
||||
{w.term_next.name} {shortDay(w.term_next.day)}
|
||||
</Text>
|
||||
</View>
|
||||
<View className="mt-1 h-[7px] overflow-hidden rounded-full bg-[rgb(40_48_74/0.1)]" accessibilityRole="image" accessibilityLabel={`다음 절기까지 ${progress}% 지났어요`}>
|
||||
<View className="h-full bg-orange" style={{ width: `${progress}%` }} />
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
export function ArticleRow({ article: a, onPress }: { article: ArticleSummary; onPress: () => void }) {
|
||||
const { kind } = useSky();
|
||||
const night = kind === 'night';
|
||||
const color = CAT_COLOR[a.category]?.[night ? 1 : 0];
|
||||
return (
|
||||
<Pressable onPress={onPress} className={ROW}>
|
||||
<View className="flex-1">
|
||||
{ARTICLE_LABEL[a.category] && (
|
||||
<Text className="text-xs font-extrabold" style={{ color }}>
|
||||
{ARTICLE_LABEL[a.category]}
|
||||
</Text>
|
||||
)}
|
||||
<Text className="mt-0.5 font-jua text-[17.5px] leading-snug text-ink">{a.title}</Text>
|
||||
<Text className="mt-1 text-xs font-semibold text-ink3">{a.read_minutes}분 읽기</Text>
|
||||
</View>
|
||||
<Thumb image={a.image} icon={a.icon} iconSize={54} className="h-[84px] w-[84px] rounded-[18px]">
|
||||
<LinearGradient colors={CARD_BG[night ? 'night' : 'day'][cardBg(a.icon, a.article_id)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
|
||||
{a.image && a.image_credit && <Credit text={a.image_credit} />}
|
||||
</Thumb>
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { getArticleOptions, getSeasonWeekOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { ARTICLE_LABEL, articleMeta, cardBg, dateRange, loadOf, shortDay } from '@nalssigak/shared/lib';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { useEffect } from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { Credit, Ic, StateBox, Thumb } from '@/components/ui';
|
||||
import { CARD_BG } from '@/lib/colors';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
import { ArticleSkel, Body } from './parts';
|
||||
|
||||
export function ArticleSheet({ articleId, onTitle }: { articleId: number; onTitle: (t: string) => void }) {
|
||||
const q = useQuery(getArticleOptions({ path: { article_id: articleId } }));
|
||||
const a = q.data?.article;
|
||||
const night = useSky().kind === 'night';
|
||||
|
||||
useEffect(() => {
|
||||
onTitle(a ? (ARTICLE_LABEL[a.category] ?? '') : '');
|
||||
}, [a, onTitle]);
|
||||
|
||||
const load = loadOf(q);
|
||||
if (!a) return <Body>{load === 'loading' ? <ArticleSkel /> : <StateBox load={load} onRetry={() => q.refetch()} empty="글을 찾지 못했어요." hold={<ArticleSkel />} boxClassName="inset-0" />}</Body>;
|
||||
return (
|
||||
<Body>
|
||||
<Thumb image={a.image} icon={a.icon} iconSize={96} className="mb-3.5 h-[150px] rounded-[20px]">
|
||||
<LinearGradient colors={CARD_BG[night ? 'night' : 'day'][cardBg(a.icon, a.article_id)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
|
||||
{a.image && a.image_credit && <Credit text={a.image_credit} />}
|
||||
</Thumb>
|
||||
<Text className="text-[13px] font-extrabold text-ink2">{articleMeta(a)}</Text>
|
||||
<Text className="mt-1.5 mb-2.5 font-jua text-2xl leading-tight text-ink">{a.title}</Text>
|
||||
{(q.data?.body ?? []).map((t) => (
|
||||
<Text key={t} className="mb-2.5 text-[15px] leading-[1.7] text-ink">
|
||||
{t}
|
||||
</Text>
|
||||
))}
|
||||
</Body>
|
||||
);
|
||||
}
|
||||
|
||||
export function SeasonWeekSheet() {
|
||||
const { open } = useSheet();
|
||||
const night = useSky().kind === 'night';
|
||||
const q = useQuery(getSeasonWeekOptions());
|
||||
const w = q.data;
|
||||
const load = loadOf(q);
|
||||
if (!w?.headline) return <Body>{load === 'loading' ? <ArticleSkel /> : <StateBox load={load} onRetry={() => q.refetch()} empty="이번 주 특집이 아직 없어요." hold={<ArticleSkel />} boxClassName="inset-0" />}</Body>;
|
||||
return (
|
||||
<Body>
|
||||
<View className="mb-3.5 h-[150px] items-center justify-center overflow-hidden rounded-[20px]">
|
||||
<LinearGradient colors={CARD_BG[night ? 'night' : 'day'].peach} style={{ position: 'absolute', inset: 0 }} />
|
||||
<Ic name="maple" size={96} />
|
||||
</View>
|
||||
<Text className="text-[13px] font-extrabold text-ink2">{w.start && w.end ? dateRange(w.start, w.end) : '이번 주'}</Text>
|
||||
<Text className="mt-1.5 mb-2.5 font-jua text-2xl leading-tight text-ink">{w.headline}</Text>
|
||||
{(w.poem_lines ?? []).length > 0 && (
|
||||
<View className="mb-2.5">
|
||||
<Text className="font-batang text-[17px] leading-[29px] text-ink">
|
||||
{w.poem_lines?.join(' ')}
|
||||
</Text>
|
||||
{w.author && <Text className="text-xs font-semibold text-ink3">{w.author}</Text>}
|
||||
</View>
|
||||
)}
|
||||
{w.term_now && w.term_next && (
|
||||
<Text className="mb-2.5 text-[15px] leading-[1.7] text-ink">
|
||||
지금 절기는 {w.term_now.name}({shortDay(w.term_now.day)}), 다음 절기는 {w.term_next.name}({shortDay(w.term_next.day)})예요.
|
||||
</Text>
|
||||
)}
|
||||
{(w.news ?? []).map((n) => (
|
||||
<Pressable key={n.code} onPress={() => open({ type: 'article', articleId: n.article_id })} className="flex-row items-center gap-2.5 border-b-[1.5px] border-line py-2.5">
|
||||
<Ic name={n.icon} size={32} />
|
||||
<Text className="flex-1 font-jua text-base text-ink">{n.title}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</Body>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
import {
|
||||
addCommentMutation,
|
||||
deleteCommentMutation,
|
||||
getFeedQueryKey,
|
||||
likeCommentMutation,
|
||||
listCommentsInfiniteOptions,
|
||||
listCommentsInfiniteQueryKey,
|
||||
unlikeCommentMutation,
|
||||
} from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import type { CommentData, ResCommentList } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { ago, loadOf } from '@nalssigak/shared/lib';
|
||||
import { useInfiniteQuery, useMutation, useQueryClient, type InfiniteData } from '@tanstack/react-query';
|
||||
import { useRef, useState } from 'react';
|
||||
import { Pressable, Text, TextInput, View } from 'react-native';
|
||||
import { useCSSVariable } from 'uniwind';
|
||||
|
||||
import { Avatar, Skel, StateBox } from '@/components/ui';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
|
||||
import { Body, ErrorLine, Field, HeartIcon } from './parts';
|
||||
|
||||
const NOT_FOUND = 3001; // 서버 ErrorType.NOT_FOUND
|
||||
const EMOJIS = ['☀️', '🌂', '🍻', '🌇', '😍', '👍'];
|
||||
const N3 = [0, 1, 2];
|
||||
|
||||
function CommentsSkel() {
|
||||
return (
|
||||
<View>
|
||||
{N3.map((i) => (
|
||||
<View key={i} className="flex-row items-start gap-2.5 py-2">
|
||||
<View className="size-[34px] rounded-full bg-skel" />
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="w-3/4" />
|
||||
<Skel className="w-24" />
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function CommentRow({ c, postId }: { c: CommentData; postId: number }) {
|
||||
const { region } = useRegion();
|
||||
const { loggedIn } = useAuth();
|
||||
const { open } = useSheet();
|
||||
const queryClient = useQueryClient();
|
||||
const [heart, ink3] = useCSSVariable(['--color-heart', '--color-ink3']).map(String);
|
||||
const [liked, setLiked] = useState(c.liked);
|
||||
const [count, setCount] = useState(c.like_count);
|
||||
const like = useMutation(likeCommentMutation());
|
||||
const unlike = useMutation(unlikeCommentMutation());
|
||||
const remove = useMutation(deleteCommentMutation());
|
||||
const [removeFailed, setRemoveFailed] = useState(false);
|
||||
const [likeFailed, setLikeFailed] = useState(false);
|
||||
|
||||
const toggle = () => {
|
||||
if (!loggedIn) return open({ type: 'login' });
|
||||
if (like.isPending || unlike.isPending) return;
|
||||
const next = !liked;
|
||||
setLikeFailed(false);
|
||||
setLiked(next);
|
||||
setCount((n) => n + (next ? 1 : -1));
|
||||
const revert = () => {
|
||||
setLiked(!next);
|
||||
setCount(c.like_count);
|
||||
};
|
||||
(next ? like : unlike).mutate(
|
||||
{ path: { comment_id: c.comment_id } },
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
if (res.result?.success) {
|
||||
setLiked(!!res.liked);
|
||||
if (res.like_count != null) setCount(res.like_count);
|
||||
return;
|
||||
}
|
||||
revert();
|
||||
// 그 사이 지워진 댓글이면 알림 없이 목록을 다시 받아 사라지게 한다
|
||||
if (res.result?.code === NOT_FOUND) queryClient.invalidateQueries({ queryKey: listCommentsInfiniteQueryKey({ path: { post_id: postId } }) });
|
||||
else setLikeFailed(true);
|
||||
},
|
||||
onError: () => {
|
||||
revert();
|
||||
setLikeFailed(true);
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
// 지우는 동안은 흐리게 두고, 성공하면 다시 받기 전에 목록 캐시에서 바로 뺀다
|
||||
const del = () => {
|
||||
setRemoveFailed(false);
|
||||
remove.mutate(
|
||||
{ path: { comment_id: c.comment_id } },
|
||||
{
|
||||
onSuccess: async (res) => {
|
||||
if (!res.result?.success) return setRemoveFailed(true);
|
||||
const key = listCommentsInfiniteQueryKey({ path: { post_id: postId } });
|
||||
await queryClient.cancelQueries({ queryKey: key });
|
||||
queryClient.setQueryData<InfiniteData<ResCommentList>>(key, (data) =>
|
||||
data ? { ...data, pages: data.pages.map((p) => ({ ...p, comments: p.comments?.filter((x) => x.comment_id !== c.comment_id) })) } : data,
|
||||
);
|
||||
queryClient.invalidateQueries({ queryKey: key });
|
||||
queryClient.invalidateQueries({ queryKey: getFeedQueryKey({ query: { region: region.code } }) });
|
||||
},
|
||||
onError: () => setRemoveFailed(true),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<View className={`flex-row items-start gap-2.5 py-2 ${remove.isPending ? 'opacity-50' : ''}`}>
|
||||
<Avatar character={c.character} color={c.color} mood={c.mood} />
|
||||
<View className="flex-1">
|
||||
<Text className="text-sm text-ink">
|
||||
<Text className="font-extrabold">{c.nickname} </Text>
|
||||
{c.body}
|
||||
</Text>
|
||||
<Text className="mt-0.5 text-xs font-bold text-ink3">
|
||||
{ago(c.created_at)} · {likeFailed ? <Text className="text-heart">좋아요를 못 했어요. 잠시 뒤에 다시 눌러 주세요</Text> : `좋아요 ${count}개`}
|
||||
{c.mine && (
|
||||
<>
|
||||
{' · '}
|
||||
<Text onPress={remove.isPending ? undefined : del} className={removeFailed && !remove.isPending ? 'text-heart' : 'text-ink3'}>
|
||||
{remove.isPending ? '지우는 중…' : removeFailed ? '못 지웠어요 · 다시' : '지우기'}
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
</Text>
|
||||
</View>
|
||||
<Pressable onPress={toggle} hitSlop={12} accessibilityRole="button" accessibilityState={{ selected: liked }} accessibilityLabel="댓글 좋아요" className="pt-1">
|
||||
<HeartIcon size={16} fill={liked ? heart : 'none'} stroke={liked ? heart : ink3} />
|
||||
</Pressable>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function CommentsSheet({ postId, draft }: { postId: number; draft?: string }) {
|
||||
const { region } = useRegion();
|
||||
const { open } = useSheet();
|
||||
const { loggedIn, me } = useAuth();
|
||||
const queryClient = useQueryClient();
|
||||
const list = useInfiniteQuery({
|
||||
...listCommentsInfiniteOptions({ path: { post_id: postId } }),
|
||||
initialPageParam: { path: { post_id: postId } },
|
||||
getNextPageParam: (last) => last.next_cursor ?? undefined,
|
||||
});
|
||||
const add = useMutation(addCommentMutation());
|
||||
const [addFailed, setAddFailed] = useState(false);
|
||||
const [text, setText] = useState(draft ?? '');
|
||||
const inputRef = useRef<TextInput>(null);
|
||||
const comments = list.data?.pages.flatMap((p) => p.comments ?? []) ?? [];
|
||||
|
||||
const submit = () => {
|
||||
if (!loggedIn) return open({ type: 'login', then: { type: 'comments', postId, draft: text } });
|
||||
const body = text.trim();
|
||||
if (!body || add.isPending) return;
|
||||
setAddFailed(false);
|
||||
add.mutate(
|
||||
{ path: { post_id: postId }, body: { body } },
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
setAddFailed(!res.result?.success);
|
||||
if (!res.result?.success) return;
|
||||
setText('');
|
||||
queryClient.invalidateQueries({ queryKey: listCommentsInfiniteQueryKey({ path: { post_id: postId } }) });
|
||||
queryClient.invalidateQueries({ queryKey: getFeedQueryKey({ query: { region: region.code } }) });
|
||||
},
|
||||
onError: () => setAddFailed(true),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Body>
|
||||
{comments.length ? (
|
||||
<>
|
||||
{/* 다시 받은 좋아요 상태(로그인 바뀜 등)가 행에 반영되도록 key 에 넣는다 */}
|
||||
{comments.map((c) => (
|
||||
<CommentRow key={`${c.comment_id}:${c.liked}:${c.like_count}`} c={c} postId={postId} />
|
||||
))}
|
||||
{list.hasNextPage && (
|
||||
<Pressable onPress={() => list.fetchNextPage()} disabled={list.isFetchingNextPage} className="my-2 disabled:opacity-50">
|
||||
<Text className="text-center text-sm font-bold text-ink3">{list.isFetchingNextPage ? '불러오는 중…' : '댓글 더 보기'}</Text>
|
||||
</Pressable>
|
||||
)}
|
||||
</>
|
||||
) : loadOf(list) === 'loading' ? (
|
||||
<CommentsSkel />
|
||||
) : (
|
||||
<StateBox load={loadOf(list)} onRetry={() => list.refetch()} empty="아직 댓글이 없어요. 첫 댓글을 남겨 보세요." hold={<CommentsSkel />} boxClassName="inset-0" />
|
||||
)}
|
||||
</Body>
|
||||
<View className="flex-row justify-around pt-1" accessibilityLabel="빠른 이모지">
|
||||
{EMOJIS.map((e) => (
|
||||
<Pressable
|
||||
key={e}
|
||||
disabled={add.isPending}
|
||||
className="disabled:opacity-40"
|
||||
onPress={() => {
|
||||
setText((t) => (t + e).slice(0, 60));
|
||||
inputRef.current?.focus();
|
||||
}}
|
||||
>
|
||||
<Text className="text-[22px]">{e}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
<ErrorLine className="h-4 text-xs leading-4" text={addFailed ? '댓글을 올리지 못했어요. 다시 해 주세요.' : undefined} />
|
||||
<View className="flex-row items-center gap-2.5 border-t border-line px-3 py-2.5">
|
||||
<View className="flex-1">
|
||||
<Field ref={inputRef} round value={text} onChangeText={setText} editable={!add.isPending} maxLength={60} placeholder={me ? `${me.nickname}(으)로 댓글 달기…` : '댓글 달기…'} accessibilityLabel="댓글" returnKeyType="send" onSubmitEditing={submit} />
|
||||
</View>
|
||||
<Pressable onPress={submit} disabled={add.isPending || (loggedIn && !text.trim())} className="disabled:opacity-40">
|
||||
<Text className="font-extrabold text-rain">{add.isPending ? '올리는 중…' : '게시'}</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
import { getIndexOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import type { Factor, ResIndexDetail } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { loadOf } from '@nalssigak/shared/lib';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { useEffect } from 'react';
|
||||
import { Text, View } from 'react-native';
|
||||
import Svg, { Circle, Line, Polygon, Text as SvgText, TSpan } from 'react-native-svg';
|
||||
|
||||
import { Ic, Skel, StateBox } from '@/components/ui';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
import { Body, useSoft } from './parts';
|
||||
|
||||
const SLOT_KEYS = ['morning', 'day', 'evening', 'night'] as const;
|
||||
const SLOT_NAMES = { morning: '아침', day: '낮', evening: '저녁', night: '밤' } as const;
|
||||
const N4 = [0, 1, 2, 3];
|
||||
const N6 = [0, 1, 2, 3, 4, 5];
|
||||
|
||||
const labelLines = (label: string) => {
|
||||
const cut = label.indexOf(' ');
|
||||
return cut < 0 ? [label] : [label.slice(0, cut), label.slice(cut + 1)];
|
||||
};
|
||||
|
||||
function Radar({ name, factors, size = 250 }: { name: string; factors: Factor[]; size?: number }) {
|
||||
const night = useSky().kind === 'night';
|
||||
const c = size / 2;
|
||||
const r = size / 2 - 40;
|
||||
const n = factors.length;
|
||||
const pt = (i: number, v: number) => {
|
||||
const a = -Math.PI / 2 + (i * 2 * Math.PI) / n;
|
||||
return [c + Math.cos(a) * r * v, c + Math.sin(a) * r * v] as const;
|
||||
};
|
||||
const ring = (v: number) => factors.map((_, i) => pt(i, v).join(',')).join(' ');
|
||||
return (
|
||||
<View className="mt-2 items-center" accessibilityRole="image" accessibilityLabel={`${name} 요소별 점수`}>
|
||||
<Svg width={size} height={size} viewBox={`0 0 ${size} ${size}`}>
|
||||
{[0.25, 0.5, 0.75, 1].map((v) => (
|
||||
<Polygon key={v} points={ring(v)} fill={v === 1 ? (night ? '#222a5c' : '#f7f9fc') : 'none'} stroke={night ? 'rgba(255,255,255,0.18)' : '#d9e2ef'} strokeWidth={1.5} />
|
||||
))}
|
||||
{factors.map((f, i) => (
|
||||
<Line key={f.axis} x1={c} y1={c} x2={pt(i, 1)[0]} y2={pt(i, 1)[1]} stroke={night ? 'rgba(255,255,255,0.12)' : '#e3e9f2'} strokeWidth={1.5} />
|
||||
))}
|
||||
<Polygon points={factors.map((f, i) => pt(i, f.value / 100).join(',')).join(' ')} fill="rgba(255,122,69,0.38)" stroke="#ff7a45" strokeWidth={3} strokeLinejoin="round" />
|
||||
{factors.map((f, i) => (
|
||||
<Circle key={f.axis} cx={pt(i, f.value / 100)[0]} cy={pt(i, f.value / 100)[1]} r={4.5} fill="#fff" stroke="#ff7a45" strokeWidth={2.5} />
|
||||
))}
|
||||
{factors.map((f, i) => {
|
||||
const lines = labelLines(f.label);
|
||||
const [x, y] = pt(i, 1.24);
|
||||
return (
|
||||
<SvgText key={f.axis} x={x} y={y - (lines.length - 1) * 7} textAnchor="middle" fontFamily="Jua_400Regular" fontSize={13} fill={night ? '#eef1ff' : '#28304a'}>
|
||||
{lines.map((line, k) => (
|
||||
<TSpan key={k} x={x} dy={k === 0 ? 4 : 14}>
|
||||
{line}
|
||||
</TSpan>
|
||||
))}
|
||||
</SvgText>
|
||||
);
|
||||
})}
|
||||
</Svg>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function GakSkel() {
|
||||
const s = useSoft();
|
||||
return (
|
||||
<View>
|
||||
<View className="flex-row items-center gap-3">
|
||||
<View className="size-[58px] rounded-full bg-skel" />
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="h-6 w-28" />
|
||||
<Skel className="w-4/5" />
|
||||
</View>
|
||||
<Skel className="h-10 w-14" />
|
||||
</View>
|
||||
<View className="mt-2 aspect-square w-full max-w-[250px] self-center rounded-full bg-skel" />
|
||||
<View className="mt-2.5 flex-row gap-1.5">
|
||||
{N4.map((i) => (
|
||||
<View key={i} className="flex-1 items-center gap-1.5 rounded-2xl px-1 py-2.5" style={{ backgroundColor: s.soft }}>
|
||||
<Skel className="w-8" />
|
||||
<Skel className="h-6 w-9" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<View className="mt-3.5 gap-3">
|
||||
{N6.map((i) => (
|
||||
<View key={i} className="flex-row items-center gap-2.5">
|
||||
<Skel className="w-[70px]" />
|
||||
<View className="h-[9px] flex-1 rounded-full bg-skel" />
|
||||
<Skel className="w-10" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function GakSheet({ indexId, onTitle }: { indexId: number; onTitle: (t: string) => void }) {
|
||||
const { region } = useRegion();
|
||||
const s = useSoft();
|
||||
const q = useQuery(getIndexOptions({ path: { index_id: indexId }, query: { region: region.code } }));
|
||||
const d: ResIndexDetail | undefined = q.data;
|
||||
const g = d?.index;
|
||||
|
||||
useEffect(() => {
|
||||
onTitle(g ? `${g.rank}위 ${g.name}` : '계산 근거');
|
||||
}, [g, onTitle]);
|
||||
|
||||
const load = loadOf(q);
|
||||
if (!g) return <Body>{load === 'loading' ? <GakSkel /> : <StateBox load={load} onRetry={() => q.refetch()} empty="이 각의 계산 근거가 아직 없어요." hold={<GakSkel />} boxClassName="inset-0" />}</Body>;
|
||||
const factors = d.factors ?? [];
|
||||
const bands = d.bands ?? [];
|
||||
const now = bands.find((b) => b.current);
|
||||
return (
|
||||
<Body>
|
||||
<View className="flex-row items-center gap-3">
|
||||
<Ic name={g.icon} size={58} />
|
||||
<View className="flex-1">
|
||||
<Text className="font-jua text-[22px] text-ink">{g.name}</Text>
|
||||
{d.description && <Text className="mt-0.5 text-[13.5px] font-semibold text-ink2">{d.description}</Text>}
|
||||
</View>
|
||||
<Text className={`font-bagel text-[42px] ${g.active ? 'text-orange' : 'text-ink3'}`}>{g.score}</Text>
|
||||
</View>
|
||||
{!g.active && <Text className="mt-2 text-[13px] font-bold text-ink2">지금 시간대엔 해당 없어요. 점수는 오늘 가장 좋은 시간대 기준이에요.</Text>}
|
||||
{now && (
|
||||
<Text className="mt-3 overflow-hidden rounded-2xl px-3.5 py-2.5 text-[14.5px] font-bold text-ink" style={{ backgroundColor: s.warm }}>
|
||||
<Text className="font-jua text-orange">
|
||||
{now.low}~{now.high}점{' '}
|
||||
</Text>
|
||||
{now.text}
|
||||
</Text>
|
||||
)}
|
||||
{factors.length > 2 && <Radar name={g.name} factors={factors} />}
|
||||
{g.slots && g.slots.length > 0 && (
|
||||
<View className="mt-2.5 flex-row gap-1.5" accessibilityLabel="오늘 시간대별 점수">
|
||||
{SLOT_KEYS.map((k) => {
|
||||
const sl = g.slots?.find((x) => x.slot === k);
|
||||
const cur = g.active && g.slot === k;
|
||||
return (
|
||||
<View key={k} className="flex-1 items-center rounded-2xl px-1 py-2" style={{ backgroundColor: cur ? s.warm : s.soft }}>
|
||||
<Text className="text-xs font-extrabold text-ink2">
|
||||
{SLOT_NAMES[k]}
|
||||
{cur && ' · 지금'}
|
||||
</Text>
|
||||
<Text className={`font-bagel text-xl ${sl ? 'text-orange' : 'text-ink3'}`}>{sl ? sl.score : '–'}</Text>
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
)}
|
||||
{g.trend && g.trend.length > 0 && (
|
||||
<View className="mt-2.5 flex-row gap-1.5">
|
||||
{g.trend.map((t) => (
|
||||
<View key={t.day} className="flex-1 items-center rounded-2xl px-1 py-2.5" style={{ backgroundColor: s.soft }}>
|
||||
<Text numberOfLines={1} className="text-xs font-extrabold text-ink2">
|
||||
{t.label}
|
||||
</Text>
|
||||
<Text className="font-bagel text-2xl text-orange">{t.score}</Text>
|
||||
<Text className={`text-[11px] leading-4 font-extrabold text-ink2 ${t.estimated ? '' : 'opacity-0'}`}>예상</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
)}
|
||||
{bands.length > 0 && (
|
||||
<View className="mt-3.5 gap-1.5" accessibilityLabel="점수 구간별 설명">
|
||||
{bands.map((b) => (
|
||||
<View key={b.low} className={`flex-row items-start gap-2 ${b.current ? '' : 'opacity-45'}`}>
|
||||
<View className={`w-[62px] items-center rounded-full py-px ${b.current ? 'bg-orange' : 'bg-ink3'}`}>
|
||||
<Text className="font-jua text-xs text-white">
|
||||
{b.low}~{b.high}
|
||||
</Text>
|
||||
</View>
|
||||
<Text className="flex-1 text-[13px] font-semibold text-ink">{b.text}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
)}
|
||||
<View className="mt-3.5 gap-2.5">
|
||||
{factors.map((f) => (
|
||||
<View key={f.axis}>
|
||||
<View className="flex-row items-center gap-2.5">
|
||||
<Text className="w-[84px] text-[13.5px] font-bold text-ink">{f.label}</Text>
|
||||
<View className="h-[9px] flex-1 overflow-hidden rounded-full" style={{ backgroundColor: s.bar }}>
|
||||
<LinearGradient colors={['#ffc86e', '#ff7a45']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }} style={{ height: '100%', width: `${f.value}%` }} />
|
||||
</View>
|
||||
<Text className="w-[52px] text-right text-xs text-ink2">비중 {f.weight}%</Text>
|
||||
</View>
|
||||
<Text className="mt-0.5 ml-[94px] text-[12.5px] font-semibold text-ink2">{f.note}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<View className="mt-3.5 gap-1.5">
|
||||
{d.zero_reason && (
|
||||
<Text className="text-[13px] font-semibold text-ink2">
|
||||
<Text className="font-bold text-heart">오늘 걸린 조건:</Text> {d.zero_reason}
|
||||
</Text>
|
||||
)}
|
||||
{factors.length > 0 && (
|
||||
<Text className="text-[13px] font-semibold text-ink2">
|
||||
<Text className="font-bold text-ink">계산 방법:</Text> 요소 점수에 비중을 곱해 더하고, 가장 낮은 요소가 낮을수록 최대 25%까지 더 깎아요
|
||||
</Text>
|
||||
)}
|
||||
{d.zero_rules && (
|
||||
<Text className="text-[13px] font-semibold text-ink2">
|
||||
<Text className="font-bold text-ink">점수 깎이는 조건:</Text> {d.zero_rules}
|
||||
</Text>
|
||||
)}
|
||||
{d.limit && (
|
||||
<Text className="text-[13px] font-semibold text-ink2">
|
||||
<Text className="font-bold text-ink">반영 못 한 것:</Text> {d.limit}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
</Body>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { subscribeAuth } from '@nalssigak/shared/api/auth';
|
||||
import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react';
|
||||
import { KeyboardAvoidingView, Modal, Platform, Pressable, Text, View } from 'react-native';
|
||||
import Animated, { Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withTiming } from 'react-native-reanimated';
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
|
||||
import { SheetContext, useSheet, type SheetState } from '@/lib/sheet';
|
||||
|
||||
import { ArticleSheet, SeasonWeekSheet } from './article';
|
||||
import { CommentsSheet } from './comments';
|
||||
import { GakSheet } from './gak';
|
||||
import { LoginSheet } from './login';
|
||||
import { MeSheet } from './me';
|
||||
import { RegionSheet } from './region';
|
||||
|
||||
export function SheetProvider({ children }: { children: ReactNode }) {
|
||||
const [state, setState] = useState<SheetState>(null);
|
||||
const open = useCallback((s: Exclude<SheetState, null>) => setState(s), []);
|
||||
const close = useCallback(() => setState(null), []);
|
||||
const api = useMemo(() => ({ open, close }), [open, close]);
|
||||
|
||||
// 로그인이 필요한 요청이 401을 받으면 로그인 창을 띄운다
|
||||
useEffect(() => subscribeAuth((reason) => reason === 'required' && open({ type: 'login' })), [open]);
|
||||
|
||||
return (
|
||||
<SheetContext value={api}>
|
||||
{children}
|
||||
<SheetHost state={state} onClose={close} />
|
||||
</SheetContext>
|
||||
);
|
||||
}
|
||||
|
||||
const TITLES = { article: '읽을거리', seasonWeek: '이번 주 특집', comments: '댓글', login: '로그인', me: '내 정보', region: '지역 바꾸기' } as const;
|
||||
|
||||
/** 판만 아래에서 올라온다 (웹 b-sheet: 0.26초, 40px 아래·흐릿하게에서) */
|
||||
function Rise({ children }: { children: ReactNode }) {
|
||||
const reduce = useReducedMotion();
|
||||
const p = useSharedValue(reduce ? 1 : 0);
|
||||
useEffect(() => {
|
||||
p.value = withTiming(1, { duration: 260, easing: Easing.bezier(0.2, 0.9, 0.3, 1) });
|
||||
}, [p]);
|
||||
const anim = useAnimatedStyle(() => ({ opacity: 0.4 + 0.6 * p.value, transform: [{ translateY: 40 * (1 - p.value) }] }));
|
||||
return <Animated.View style={[{ width: '100%', maxHeight: '86%', alignItems: 'center' }, anim]}>{children}</Animated.View>;
|
||||
}
|
||||
|
||||
/** 아래에서 올라오는 창. 배경은 제자리에서 서서히. 바깥을 누르거나 뒤로 가기(안드로이드)로 닫는다 */
|
||||
function SheetHost({ state: next, onClose }: { state: SheetState; onClose: () => void }) {
|
||||
// 닫는 동안(배경이 사라지는 동안)에도 마지막 내용을 그대로 보여 준다. 열 때마다 판을 새로 올린다
|
||||
const [last, setLast] = useState<SheetState>(next);
|
||||
const [isOpen, setIsOpen] = useState(next != null);
|
||||
const [opens, setOpens] = useState(0);
|
||||
if (next && next !== last) setLast(next);
|
||||
if ((next != null) !== isOpen) {
|
||||
setIsOpen(next != null);
|
||||
if (next) setOpens((n) => n + 1);
|
||||
}
|
||||
const state = next ?? last;
|
||||
const { open } = useSheet();
|
||||
const { bottom } = useSafeAreaInsets();
|
||||
const [gakTitle, setGakTitle] = useState('');
|
||||
const [articleTitle, setArticleTitle] = useState('');
|
||||
|
||||
const then = state?.type === 'login' ? state.then : undefined;
|
||||
const title = !state ? '' : state.type === 'gak' ? gakTitle : state.type === 'article' ? articleTitle || TITLES.article : TITLES[state.type];
|
||||
|
||||
return (
|
||||
<Modal visible={next != null} transparent animationType="fade" onRequestClose={onClose} statusBarTranslucent>
|
||||
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} className="flex-1 justify-end">
|
||||
<Pressable onPress={onClose} accessibilityLabel="닫기" className="absolute inset-0 bg-[rgb(20_26_45/0.45)]" />
|
||||
{state && (
|
||||
<Rise key={opens}>
|
||||
<View accessibilityViewIsModal accessibilityLabel={title} className="w-full max-w-[440px] rounded-t-[22px] bg-card" style={{ paddingBottom: bottom }}>
|
||||
<View className="border-b border-line px-4 pt-2 pb-2.5">
|
||||
<View className="mb-2.5 h-1 w-10 self-center rounded-full bg-line" />
|
||||
<Text numberOfLines={1} className="px-10 text-center text-[15px] font-extrabold text-ink">
|
||||
{title}
|
||||
</Text>
|
||||
<Pressable onPress={onClose} hitSlop={10} accessibilityRole="button" accessibilityLabel="닫기" className="absolute right-3 bottom-2 size-[30px] items-center justify-center">
|
||||
<Text className="text-xl text-ink2">×</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
{state.type === 'gak' && <GakSheet indexId={state.indexId} onTitle={setGakTitle} />}
|
||||
{state.type === 'article' && <ArticleSheet articleId={state.articleId} onTitle={setArticleTitle} />}
|
||||
{state.type === 'seasonWeek' && <SeasonWeekSheet />}
|
||||
{state.type === 'comments' && <CommentsSheet postId={state.postId} draft={state.draft} />}
|
||||
{state.type === 'login' && <LoginSheet onDone={onClose} onLoggedIn={then ? () => open(then) : onClose} />}
|
||||
{state.type === 'me' && <MeSheet onDone={onClose} />}
|
||||
{state.type === 'region' && <RegionSheet onDone={onClose} />}
|
||||
</View>
|
||||
</Rise>
|
||||
)}
|
||||
</KeyboardAvoidingView>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { setTokens } from '@nalssigak/shared/api/auth';
|
||||
import { loginMutation, signupMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import type { ResAuth } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useState } from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { useAuth } from '@/lib/auth';
|
||||
|
||||
import { MeSheet } from './me';
|
||||
import { Body, ErrorLine, Field, useSoft } from './parts';
|
||||
|
||||
const AUTH_ERRORS: Record<string, string> = {
|
||||
AUTH_FAILED: '아이디나 비밀번호가 맞지 않아요.',
|
||||
AUTH_DUPLICATE_ID: '이미 쓰고 있는 아이디예요.',
|
||||
INVALID_INPUT: '아이디는 영어 소문자·숫자·_ 4~20자, 비밀번호는 8~64자, 닉네임은 2~12자로 써 주세요.',
|
||||
};
|
||||
|
||||
const MODES = [
|
||||
['login', '로그인'],
|
||||
['signup', '처음이에요'],
|
||||
] as const;
|
||||
|
||||
export function LoginSheet({ onDone, onLoggedIn }: { onDone: () => void; onLoggedIn: () => void }) {
|
||||
const { me } = useAuth();
|
||||
const s = useSoft();
|
||||
const [mode, setMode] = useState<'login' | 'signup'>('login');
|
||||
const [loginId, setLoginId] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [nickname, setNickname] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const login = useMutation(loginMutation());
|
||||
const signup = useMutation(signupMutation());
|
||||
const pending = login.isPending || signup.isPending;
|
||||
|
||||
const done = (res: ResAuth) => {
|
||||
if (!res.result?.success || !res.access_token) {
|
||||
setError(AUTH_ERRORS[res.result?.desc ?? ''] ?? '잠시 뒤에 다시 해 주세요.');
|
||||
return;
|
||||
}
|
||||
setTokens(res.access_token, res.refresh_token ?? null);
|
||||
onLoggedIn();
|
||||
};
|
||||
const fail = () => setError('서버에 닿지 못했어요. 잠시 뒤에 다시 해 주세요.');
|
||||
|
||||
// 웹 폼의 required·minLength 를 그대로 앞에서 확인한다
|
||||
const submit = () => {
|
||||
setError('');
|
||||
const id = loginId.trim();
|
||||
if (id.length < 4 || !password || (mode === 'signup' && (password.length < 8 || nickname.trim().length < 2))) {
|
||||
setError(AUTH_ERRORS.INVALID_INPUT);
|
||||
return;
|
||||
}
|
||||
if (mode === 'login') login.mutate({ body: { login_id: id, password } }, { onSuccess: done, onError: fail });
|
||||
else signup.mutate({ body: { login_id: id, password, nickname: nickname.trim() } }, { onSuccess: done, onError: fail });
|
||||
};
|
||||
|
||||
if (me) return <MeSheet onDone={onDone} />;
|
||||
|
||||
return (
|
||||
<Body className="gap-2.5">
|
||||
<Text className="text-center text-sm font-semibold text-ink2">좋아요·댓글은 로그인한 뒤에 할 수 있어요.</Text>
|
||||
<View className="flex-row gap-1 rounded-full p-1" style={{ backgroundColor: s.soft }} accessibilityLabel="로그인 또는 가입">
|
||||
{MODES.map(([m, l]) => (
|
||||
<Pressable key={m} accessibilityState={{ selected: mode === m }} onPress={() => setMode(m)} className={`flex-1 rounded-full py-2 ${mode === m ? 'bg-ink-btn' : ''}`}>
|
||||
<Text className={`text-center text-sm font-extrabold ${mode === m ? 'text-white' : 'text-ink2'}`}>{l}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
<Field value={loginId} onChangeText={setLoginId} autoCapitalize="none" autoCorrect={false} autoComplete="username" textContentType="username" maxLength={20} placeholder="아이디" accessibilityLabel="아이디" />
|
||||
<Field value={password} onChangeText={setPassword} secureTextEntry autoComplete={mode === 'login' ? 'current-password' : 'new-password'} textContentType={mode === 'login' ? 'password' : 'newPassword'} maxLength={64} placeholder={mode === 'signup' ? '비밀번호 (8자 이상)' : '비밀번호'} accessibilityLabel="비밀번호" onSubmitEditing={mode === 'login' ? submit : undefined} />
|
||||
{mode === 'signup' && <Field value={nickname} onChangeText={setNickname} maxLength={12} placeholder="닉네임 (2~12자)" accessibilityLabel="닉네임" onSubmitEditing={submit} />}
|
||||
<ErrorLine text={error} />
|
||||
<Pressable onPress={submit} disabled={pending} className="rounded-[14px] border-b-[5px] border-orange-deep bg-orange p-[13px] disabled:opacity-60">
|
||||
<Text className="text-center font-jua text-[17px] text-white">{mode === 'login' ? (pending ? '로그인 중…' : '로그인') : pending ? '가입하는 중…' : '가입하고 시작하기'}</Text>
|
||||
</Pressable>
|
||||
<Pressable onPress={onDone} className="rounded-[14px] p-[13px]">
|
||||
<Text className="text-center text-[15px] font-extrabold text-ink2">나중에 할게요</Text>
|
||||
</Pressable>
|
||||
</Body>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import { meQueryKey, updateMeMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { AVATAR_COLORS, CHARACTERS, MOODS } from '@nalssigak/shared/lib';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useState } from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { Avatar, Ic } from '@/components/ui';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
|
||||
import { Body, Field, useSoft } from './parts';
|
||||
|
||||
/** 내 정보: 캐릭터·배경색·기분·닉네임·로그아웃 */
|
||||
export function MeSheet({ onDone }: { onDone: () => void }) {
|
||||
const { me, logout } = useAuth();
|
||||
const s = useSoft();
|
||||
const queryClient = useQueryClient();
|
||||
const update = useMutation(updateMeMutation());
|
||||
const [nickname, setNickname] = useState(me?.nickname ?? '');
|
||||
const [error, setError] = useState('');
|
||||
if (!me) return null;
|
||||
|
||||
const save = (body: { nickname?: string; character?: string; color?: string; mood?: string }) => {
|
||||
setError('');
|
||||
update.mutate(
|
||||
{ body },
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
if (!res.result?.success) return setError(res.result?.desc === 'INVALID_INPUT' ? '닉네임은 2~12자로 써 주세요.' : '잠시 뒤에 다시 해 주세요.');
|
||||
queryClient.setQueryData(meQueryKey(), res);
|
||||
// 댓글에 보이는 내 캐릭터·닉네임도 바뀐다
|
||||
queryClient.invalidateQueries({ predicate: (q) => (q.queryKey[0] as { _id?: string } | undefined)?._id === 'listComments' });
|
||||
},
|
||||
onError: () => setError('서버에 닿지 못했어요. 잠시 뒤에 다시 해 주세요.'),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
// 저장하는 동안은 고른 값을 바로 선택으로 보여 준다. 실패하면 me 값으로 돌아간다
|
||||
const saving = update.isPending ? update.variables?.body : undefined;
|
||||
const character = saving?.character ?? me.character;
|
||||
const color = saving?.color ?? me.color;
|
||||
const mood = saving?.mood ?? me.mood;
|
||||
const nick = nickname.trim();
|
||||
|
||||
return (
|
||||
<Body className="gap-3">
|
||||
<View className="items-center gap-1.5">
|
||||
<Avatar character={me.character} color={me.color} mood={me.mood} size={64} />
|
||||
<Text className="text-center text-sm font-semibold text-ink2">{me.login_id}(으)로 로그인했어요</Text>
|
||||
</View>
|
||||
<View accessibilityLabel="내 캐릭터">
|
||||
<Text className="mb-2 text-sm font-extrabold text-ink">내 캐릭터</Text>
|
||||
<View className="flex-row flex-wrap gap-2">
|
||||
{CHARACTERS.map(([key, label]) => (
|
||||
<Pressable
|
||||
key={key}
|
||||
accessibilityRole="radio"
|
||||
accessibilityState={{ checked: character === key }}
|
||||
disabled={update.isPending}
|
||||
onPress={() => save({ character: key })}
|
||||
className={`items-center gap-1 rounded-[18px] border-2 py-2.5 ${character === key ? 'border-orange' : 'border-transparent'}`}
|
||||
style={{ width: '31.5%', backgroundColor: s.field }}
|
||||
>
|
||||
<Ic name={key} size={48} />
|
||||
<Text className={`font-jua text-[15px] ${character === key ? 'text-orange' : 'text-ink'}`}>{label}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
<View accessibilityLabel="배경색">
|
||||
<Text className="mb-2 text-sm font-extrabold text-ink">배경색</Text>
|
||||
<View className="flex-row flex-wrap gap-2.5">
|
||||
{Object.entries(AVATAR_COLORS).map(([key, hex]) => (
|
||||
<Pressable
|
||||
key={key}
|
||||
accessibilityRole="radio"
|
||||
accessibilityState={{ checked: color === key }}
|
||||
accessibilityLabel={key}
|
||||
disabled={update.isPending}
|
||||
onPress={() => save({ color: key })}
|
||||
className={`size-9 rounded-full border-[3px] ${color === key ? 'border-ink' : 'border-white'}`}
|
||||
style={{ backgroundColor: hex }}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
<View accessibilityLabel="오늘 기분">
|
||||
<Text className="mb-2 text-sm font-extrabold text-ink">오늘 기분</Text>
|
||||
<View className="flex-row flex-wrap gap-2">
|
||||
{MOODS.map(([key, emoji, label]) => (
|
||||
<Pressable
|
||||
key={key}
|
||||
accessibilityRole="radio"
|
||||
accessibilityState={{ checked: mood === key }}
|
||||
disabled={update.isPending}
|
||||
onPress={() => save({ mood: mood === key ? '' : key })}
|
||||
className={`items-center gap-0.5 rounded-[14px] border-2 py-2 ${mood === key ? 'border-orange' : 'border-transparent'}`}
|
||||
style={{ width: '23%', backgroundColor: s.field }}
|
||||
>
|
||||
<Text className="text-[22px] leading-[26px]">{emoji}</Text>
|
||||
<Text className={`text-xs font-bold ${mood === key ? 'text-orange' : 'text-ink2'}`}>{label}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
<Text className="mt-1.5 text-xs font-semibold text-ink3">한 번 더 누르면 지워져요</Text>
|
||||
</View>
|
||||
<View className="flex-row items-center gap-2">
|
||||
<View className="flex-1">
|
||||
<Field value={nickname} onChangeText={setNickname} maxLength={12} accessibilityLabel="닉네임" placeholder="닉네임 (2~12자)" onSubmitEditing={() => nick.length >= 2 && save({ nickname: nick })} />
|
||||
</View>
|
||||
<Pressable onPress={() => save({ nickname: nick })} disabled={update.isPending || nick === me.nickname || nick.length < 2} className="rounded-[14px] bg-ink-btn px-4 py-3 disabled:opacity-40">
|
||||
<Text className="text-sm font-extrabold text-white">{saving?.nickname != null ? '저장 중…' : '바꾸기'}</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
<Text className={`min-h-5 text-center text-[13px] font-bold ${saving ? 'text-ink2' : 'text-heart'}`}>{saving ? (saving.nickname == null ? '저장 중…' : '') : error}</Text>
|
||||
<Pressable
|
||||
onPress={() => {
|
||||
logout();
|
||||
onDone();
|
||||
}}
|
||||
className="rounded-[14px] p-[13px]"
|
||||
style={{ backgroundColor: s.soft }}
|
||||
>
|
||||
<Text className="text-center text-[15px] font-extrabold text-ink">로그아웃</Text>
|
||||
</Pressable>
|
||||
</Body>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { ReactNode, Ref } from 'react';
|
||||
import { ScrollView, Text, TextInput, View, type TextInputProps } from 'react-native';
|
||||
import Svg, { Path } from 'react-native-svg';
|
||||
|
||||
import { Skel } from '@/components/ui';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
/** 웹의 연한 판(#f3f6fb)·입력칸·따뜻한 판(#fff4ec)을 밤엔 어두운 판으로 */
|
||||
export function useSoft() {
|
||||
const night = useSky().kind === 'night';
|
||||
return {
|
||||
soft: night ? '#2b3470' : '#f3f6fb',
|
||||
field: night ? '#2b3470' : '#f7f9fc',
|
||||
fieldBorder: night ? 'rgba(255,255,255,0.12)' : '#dfe5ee',
|
||||
warm: night ? 'rgba(255,138,87,0.16)' : '#fff4ec',
|
||||
bar: night ? 'rgba(255,255,255,0.12)' : '#e3eaf4',
|
||||
placeholder: night ? '#a1a9db' : '#8a92aa',
|
||||
};
|
||||
}
|
||||
|
||||
export function Body({ children, className }: { children: ReactNode; className?: string }) {
|
||||
return (
|
||||
<ScrollView className="shrink" contentContainerClassName={`px-4 pt-3.5 pb-[18px] ${className ?? ''}`} keyboardShouldPersistTaps="handled">
|
||||
{children}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
/** 입력칸: 둥근 연한 판 */
|
||||
export function Field({ round = false, style, ...props }: TextInputProps & { round?: boolean; ref?: Ref<TextInput> }) {
|
||||
const s = useSoft();
|
||||
return (
|
||||
<TextInput
|
||||
placeholderTextColor={s.placeholder}
|
||||
className={`px-3.5 text-[16px] text-ink ${round ? 'rounded-full py-2.5' : 'rounded-[14px] py-3'}`}
|
||||
style={[{ backgroundColor: s.field, borderWidth: 1, borderColor: s.fieldBorder }, style]}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function HeartIcon({ size, fill, stroke }: { size: number; fill: string; stroke: string }) {
|
||||
return (
|
||||
<Svg viewBox="0 0 24 24" width={size} height={size} fill={fill} stroke={stroke} strokeWidth={2}>
|
||||
<Path d="M12 20.5s-8-4.9-8-11A4.6 4.6 0 0 1 12 6.8a4.6 4.6 0 0 1 8 2.7c0 6.1-8 11-8 11z" />
|
||||
</Svg>
|
||||
);
|
||||
}
|
||||
|
||||
const N3 = [0, 1, 2];
|
||||
|
||||
/** 읽을거리·이번 주 특집: 그림 150px · 머리말 · 제목 · 본문 */
|
||||
export function ArticleSkel() {
|
||||
return (
|
||||
<View className="gap-2.5">
|
||||
<View className="h-[150px] rounded-[20px] bg-skel" />
|
||||
<Skel className="w-24" />
|
||||
<Skel className="h-6 w-4/5" />
|
||||
{N3.map((k) => (
|
||||
<View key={k} className="gap-1.5">
|
||||
<Skel className="w-full" />
|
||||
<Skel className="w-2/3" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 빨간 안내 한 줄 (자리 높이는 그대로) */
|
||||
export function ErrorLine({ text, className }: { text?: string; className?: string }) {
|
||||
return <Text className={`min-h-5 text-center text-[13px] font-bold text-heart ${className ?? ''}`}>{text ?? ''}</Text>;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import { listRegionsOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { loadOf } from '@nalssigak/shared/lib';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useDeferredValue, useEffect, useRef, useState } from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { Skel, StateBox } from '@/components/ui';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
|
||||
import { Body, Field } from './parts';
|
||||
|
||||
const LOCATE_TEXT = { idle: '', locating: '위치를 찾는 중이에요…', denied: '위치 권한이 꺼져 있어요. 아래 목록에서 골라 주세요.', error: '위치를 찾지 못했어요. 아래 목록에서 골라 주세요.' } as const;
|
||||
|
||||
const N14 = Array.from({ length: 14 }, (_, i) => i);
|
||||
|
||||
function RegionsSkel() {
|
||||
return (
|
||||
<View className="mt-2">
|
||||
{N14.map((i) => (
|
||||
<View key={i} className="border-b-[1.5px] border-line px-1 py-3.5">
|
||||
<Skel className="w-28" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 지역 바꾸기: 지금 위치로 찾기 + 구 이름으로 찾기 + 목록 */
|
||||
export function RegionSheet({ onDone }: { onDone: () => void }) {
|
||||
const { region, setRegion, locate, locateStatus } = useRegion();
|
||||
const alive = useRef(true);
|
||||
useEffect(() => {
|
||||
alive.current = true;
|
||||
return () => {
|
||||
alive.current = false;
|
||||
};
|
||||
}, []);
|
||||
const { me, logout } = useAuth();
|
||||
const { open } = useSheet();
|
||||
const [q, setQ] = useState('');
|
||||
const deferred = useDeferredValue(q.trim());
|
||||
const list = useQuery(listRegionsOptions(deferred ? { query: { q: deferred } } : undefined));
|
||||
const regions = list.data?.regions ?? [];
|
||||
const listLoad = loadOf(list);
|
||||
|
||||
return (
|
||||
<Body>
|
||||
<Pressable onPress={() => locate(() => alive.current && onDone())} disabled={locateStatus === 'locating'} className="items-center rounded-full border-b-[5px] border-orange-deep bg-orange p-3 disabled:opacity-60">
|
||||
<Text className="font-jua text-[17px] text-white">지금 위치로 찾기</Text>
|
||||
</Pressable>
|
||||
<Text className="mt-2 min-h-5 text-center text-[13px] font-bold text-ink2" accessibilityLiveRegion="polite">
|
||||
{LOCATE_TEXT[locateStatus]}
|
||||
</Text>
|
||||
<Field round value={q} onChangeText={setQ} placeholder="구 이름으로 찾기 (예: 마포)" accessibilityLabel="구 이름으로 찾기" />
|
||||
{listLoad === 'loading' && <RegionsSkel />}
|
||||
{listLoad !== 'loading' && !regions.length && (listLoad === 'ready' ? <StateBox load={listLoad} empty="찾는 구가 없어요." /> : <StateBox load={listLoad} onRetry={() => list.refetch()} hold={<RegionsSkel />} boxClassName="inset-x-0 top-2 bottom-0" />)}
|
||||
<View className={`mt-2 ${list.isPlaceholderData ? 'opacity-60' : ''}`}>
|
||||
{regions.map((r) => {
|
||||
const here = r.code === region.code;
|
||||
return (
|
||||
<Pressable
|
||||
key={r.code}
|
||||
accessibilityState={{ selected: here }}
|
||||
onPress={() => {
|
||||
setRegion(r);
|
||||
onDone();
|
||||
}}
|
||||
className="flex-row items-center justify-between border-b-[1.5px] border-line px-1 py-3"
|
||||
>
|
||||
<Text className={`font-jua text-[17px] ${here ? 'text-orange' : 'text-ink'}`}>{r.name}</Text>
|
||||
{here && <Text className="text-xs font-extrabold text-orange">지금 보는 곳</Text>}
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
<View className="mt-4 flex-row items-center justify-center gap-2">
|
||||
<Text className="text-[13px] font-bold text-ink2">{me ? `${me.nickname}(으)로 로그인했어요` : '로그인하면 좋아요·댓글을 쓸 수 있어요'}</Text>
|
||||
<Pressable onPress={me ? logout : () => open({ type: 'login' })} hitSlop={8}>
|
||||
<Text className="text-[13px] font-extrabold text-rain">{me ? '로그아웃' : '로그인'}</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</Body>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import type { TimeKind } from '@nalssigak/shared/lib';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { useEffect } from 'react';
|
||||
import { StyleSheet, View, type DimensionValue } from 'react-native';
|
||||
import Animated, { cancelAnimation, Easing, interpolate, useAnimatedStyle, useReducedMotion, useSharedValue, withDelay, withRepeat, withTiming } from 'react-native-reanimated';
|
||||
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
const KINDS: TimeKind[] = ['morning', 'day', 'sunset', 'night'];
|
||||
|
||||
const SKY: Record<TimeKind, { colors: readonly [string, string, string]; locations: readonly [number, number, number] }> = {
|
||||
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, period: (3 + (i % 5)) * 1000, delay: ((i * 0.7) % 6) * 1000 }) as const);
|
||||
|
||||
/** 시간대 하나의 하늘 판. 고른 시간대만 1.4초 동안 서서히 드러난다 */
|
||||
function Layer({ kind, on, reduce }: { kind: TimeKind; on: boolean; reduce: boolean }) {
|
||||
const shown = useSharedValue(on ? 1 : 0);
|
||||
useEffect(() => {
|
||||
shown.value = reduce ? (on ? 1 : 0) : withTiming(on ? 1 : 0, { duration: 1400, easing: Easing.ease });
|
||||
}, [on, reduce, shown]);
|
||||
const style = useAnimatedStyle(() => ({ opacity: shown.value }));
|
||||
return (
|
||||
<Animated.View style={[StyleSheet.absoluteFill, style]}>
|
||||
<LinearGradient {...SKY[kind]} style={StyleSheet.absoluteFill} />
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 밤 별: 제각각 주기로 반짝인다 */
|
||||
function Star({ star, reduce }: { star: (typeof STARS)[number]; reduce: boolean }) {
|
||||
const glow = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
if (reduce) return;
|
||||
glow.value = withDelay(star.delay, withRepeat(withTiming(1, { duration: star.period / 2, easing: Easing.inOut(Easing.ease) }), -1, true));
|
||||
return () => cancelAnimation(glow);
|
||||
}, [reduce, glow, star]);
|
||||
const style = useAnimatedStyle(() => ({ opacity: reduce ? 0.7 : 0.25 + glow.value * 0.75 }));
|
||||
return <Animated.View style={[{ position: 'absolute', left: star.left, top: star.top, width: star.size, height: star.size, borderRadius: star.size, backgroundColor: '#fff', boxShadow: '0 0 6px rgb(255 255 255 / 0.8)' }, style]} />;
|
||||
}
|
||||
|
||||
export type ShootSpec = { top: DimensionValue; left: DimensionValue; len: number; dur: number; dl: number };
|
||||
|
||||
// 별똥별: 위치·길이·주기를 엇갈려 몇 초마다 하나씩 떨어지게 (웹 BLayout SHOOTS, 밀리초)
|
||||
const SHOOTS: ShootSpec[] = [
|
||||
{ top: '8%', left: '78%', len: 110, dur: 7000, dl: 1000 },
|
||||
{ top: '22%', left: '46%', len: 80, dur: 9000, dl: 3500 },
|
||||
{ top: '5%', left: '30%', len: 95, dur: 8000, dl: 5500 },
|
||||
{ top: '36%', left: '88%', len: 70, dur: 10000, dl: 2200 },
|
||||
{ top: '52%', left: '62%', len: 90, dur: 11000, dl: 7000 },
|
||||
{ top: '14%', left: '96%', len: 120, dur: 12000, dl: 9000 },
|
||||
];
|
||||
|
||||
/** 별똥별 하나: 주기 끝 14% 동안만 비스듬히 240px 미끄러지며 반짝 (웹 .b-shoot). 동작 줄이기면 그리지 않는다 */
|
||||
export function Shoot({ top, left, len, dur, dl }: ShootSpec) {
|
||||
const reduce = useReducedMotion();
|
||||
const p = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
if (reduce) return;
|
||||
p.value = withDelay(dl, withRepeat(withTiming(1, { duration: dur, easing: Easing.in(Easing.ease) }), -1, false));
|
||||
return () => cancelAnimation(p);
|
||||
}, [reduce, dur, dl, p]);
|
||||
const style = useAnimatedStyle(() => ({
|
||||
opacity: interpolate(p.value, [0, 0.86, 0.89, 1], [0, 0, 1, 0]),
|
||||
transform: [{ rotate: '-24deg' }, { translateX: interpolate(p.value, [0, 0.86, 1], [0, 0, -240]) }],
|
||||
}));
|
||||
if (reduce) return null;
|
||||
return (
|
||||
<Animated.View style={[{ position: 'absolute', top, left, width: len, height: 1.5 }, style]}>
|
||||
<LinearGradient colors={['rgba(255,255,255,0)', '#ffffff']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }} style={{ flex: 1, borderRadius: 2 }} />
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 화면 전체 하늘: 시간대별 색이 서서히 바뀌고, 밤에는 별이 반짝이고 별똥별이 떨어진다 */
|
||||
export function SkyBg() {
|
||||
const { kind } = useSky();
|
||||
const reduce = useReducedMotion();
|
||||
return (
|
||||
<View style={StyleSheet.absoluteFill} pointerEvents="none">
|
||||
{KINDS.map((k) => (
|
||||
<Layer key={k} kind={k} on={k === kind} reduce={reduce} />
|
||||
))}
|
||||
{kind === 'night' && STARS.map((s, i) => <Star key={i} star={s} reduce={reduce} />)}
|
||||
{kind === 'night' && SHOOTS.map((s, i) => <Shoot key={i} {...s} />)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 웹 b.css 노을 탭 그라데이션. 등급별 하늘색(히어로·3일 타일)과 시간표 막대
|
||||
type Grad = { colors: readonly [string, string, ...string[]]; locations?: readonly [number, number, ...number[]] };
|
||||
|
||||
export const GRADE_SKY: Record<string, { hero: Grad; tile: Grad }> = {
|
||||
잿빛: { hero: { colors: ['#6f7690', '#9aa0b4', '#b9b4c0'], locations: [0, 0.55, 1] }, tile: { colors: ['#8f8aa5', '#b9b0bf'] } },
|
||||
은은함: { hero: { colors: ['#4b5aa8', '#7f86c6', '#e9b9a8', '#ffb27a'], locations: [0, 0.4, 0.78, 1] }, tile: { colors: ['#7f86c6', '#e9b9a8', '#f6b07a'], locations: [0, 0.7, 1] } },
|
||||
고움: { hero: { colors: ['#5b3f9e', '#c2559a', '#ff7a6a', '#ffb35c'], locations: [0, 0.45, 0.78, 1] }, tile: { colors: ['#5b3f9e', '#c2559a', '#ff7a6a'], locations: [0, 0.55, 1] } },
|
||||
붉음: { hero: { colors: ['#4a2a8a', '#b0306a', '#ff4a3a', '#ff9a3c'], locations: [0, 0.4, 0.72, 1] }, tile: { colors: ['#4a2a8a', '#b0306a', '#ff4a3a'], locations: [0, 0.5, 1] } },
|
||||
};
|
||||
|
||||
export const skyOf = (grade?: string | null) => GRADE_SKY[grade ?? ''] ?? GRADE_SKY['은은함'];
|
||||
|
||||
export const RAIL = {
|
||||
sunset: { colors: ['#f2b84b', '#f6844e', '#e8506a', '#8c5aa6', '#2d3f8f'], locations: [0, 0.45, 0.62, 0.82, 1] },
|
||||
sunrise: { colors: ['#2d3f8f', '#8c5aa6', '#e8506a', '#f6844e', '#f2b84b'], locations: [0, 0.25, 0.45, 0.6, 1] },
|
||||
} satisfies Record<string, Grad>;
|
||||
@@ -0,0 +1,189 @@
|
||||
import type { BestTime, SkyPlanData } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { clockShort } from '@nalssigak/shared/lib';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { useState, type ReactNode } from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
import { useCSSVariable } from 'uniwind';
|
||||
|
||||
import { RAIL, skyOf } from '@/components/sky/colors';
|
||||
import { SitSun, Skyline } from '@/components/sky/skyline';
|
||||
import { MapLink, Skel } from '@/components/ui';
|
||||
|
||||
const SHADOW = { textShadowColor: 'rgb(50 25 70 / 0.35)', textShadowOffset: { width: 0, height: 2 }, textShadowRadius: 10 };
|
||||
const FOUR = [0, 1, 2, 3];
|
||||
|
||||
/** 히어로엔 답만: 노을 피크 시각과 어떻게 물드는지. 상자는 불러오는 중·실패·빈 값 모두 같은 크기 */
|
||||
export function SkyHero({ plan, children }: { plan?: SkyPlanData; children?: ReactNode }) {
|
||||
const g = skyOf(plan?.grade_label).hero;
|
||||
return (
|
||||
<View className="mx-3 mt-1 min-h-[230px] overflow-hidden rounded-[32px] px-5 pt-5 pb-14">
|
||||
<LinearGradient colors={g.colors} locations={g.locations} style={{ position: 'absolute', inset: 0 }} />
|
||||
<SitSun />
|
||||
<Skyline />
|
||||
{children ?? (
|
||||
<View>
|
||||
{plan ? (
|
||||
<Text className="font-jua text-[28px] leading-tight text-white" style={SHADOW}>
|
||||
{plan.title}
|
||||
</Text>
|
||||
) : (
|
||||
<Skel className="h-7 w-[230px]" />
|
||||
)}
|
||||
{!plan ? (
|
||||
<Skel className="mt-2 w-[180px]" />
|
||||
) : plan.situation_label ? (
|
||||
<Text className="mt-1.5 text-[15px] font-bold text-white" style={SHADOW}>
|
||||
{plan.situation_label}
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 오늘·내일·모레를 그날 예상 하늘색 타일로. 누르면 그날로 */
|
||||
export function DayTiles({ plans, day, onPick }: { plans: SkyPlanData[]; day?: string; onPick: (day: string) => void }) {
|
||||
const ink = String(useCSSVariable('--color-ink'));
|
||||
return (
|
||||
<View className="mx-3 mt-2.5 flex-row gap-2">
|
||||
{plans.map((p) => {
|
||||
const g = skyOf(p.grade_label).tile;
|
||||
const on = p.day === day;
|
||||
return (
|
||||
<Pressable key={p.day} accessibilityState={{ selected: on }} onPress={() => onPick(p.day)} className="flex-1 rounded-[18px] p-[2px]" style={{ borderWidth: 3, borderColor: on ? ink : 'transparent' }}>
|
||||
<View className="overflow-hidden rounded-2xl px-2.5 pt-2 pb-2.5">
|
||||
<LinearGradient colors={g.colors} locations={g.locations} start={{ x: 0.2, y: 0 }} end={{ x: 0.8, y: 1 }} style={{ position: 'absolute', inset: 0 }} />
|
||||
<Text className="text-[11.5px] font-extrabold text-white">{p.when}</Text>
|
||||
<Text className="font-jua text-lg leading-tight text-white">{p.best_at ? clockShort(p.best_at) : '–'}</Text>
|
||||
<Text className="text-[11.5px] font-bold text-white">
|
||||
{p.grade_label} {p.score}
|
||||
</Text>
|
||||
</View>
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function Toggle({ label, children, end }: { label: ReactNode; children: ReactNode; end?: boolean }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<View>
|
||||
<Pressable onPress={() => setOpen(!open)} accessibilityState={{ expanded: open }} className={`flex-row items-center gap-1.5 ${end ? 'justify-between' : ''}`}>
|
||||
{label}
|
||||
</Pressable>
|
||||
{open && children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const Q = ({ className = 'bg-card/80' }: { className?: string }) => (
|
||||
<View className={`size-[18px] items-center justify-center rounded-full ${className}`}>
|
||||
<Text className="text-[11px] font-extrabold text-ink">?</Text>
|
||||
</View>
|
||||
);
|
||||
|
||||
/** 노을 점수 뜻. 지금 하늘이 아니라 해 질(뜰) 무렵 예보라는 것도 */
|
||||
export function ScoreHelp({ plan }: { plan: SkyPlanData }) {
|
||||
const sunAt = plan.timeline?.find((t) => t.kind === 'sun')?.at;
|
||||
const rise = plan.kind === 'sunrise';
|
||||
return (
|
||||
<View className="mx-3 mt-1.5 px-1">
|
||||
<Toggle
|
||||
end
|
||||
label={
|
||||
<>
|
||||
<Text className="text-[12px] font-bold text-ink2">노을 점수 100점 만점 · 높을수록 붉어요</Text>
|
||||
<Q />
|
||||
</>
|
||||
}
|
||||
>
|
||||
<Text className="mt-1.5 rounded-xl bg-card/70 px-2.5 py-2 text-[12px] leading-snug font-semibold text-ink2">
|
||||
80점 넘으면 붉게, 60점 넘으면 곱게, 40점 넘으면 은은하게 물들어요.
|
||||
{sunAt && ` 해 ${rise ? '뜰' : '질'} 무렵(${new Date(sunAt).getHours()}시) 날씨 예보로 계산했고, 노을 피크 시각은 해 ${rise ? '뜨기 10~20분 전' : '지고 10~20분 뒤'}로 어림한 거라 실제와 다를 수 있어요.`}
|
||||
</Text>
|
||||
</Toggle>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 언제 보면 좋을까: 왼쪽 세로 줄 색이 그 시각 하늘색, 노을 피크만 강조 */
|
||||
export function Timeline({ rows, kind = 'sunset' }: { rows?: BestTime[]; kind?: SkyPlanData['kind'] }) {
|
||||
const rail = RAIL[kind === 'sunrise' ? 'sunrise' : 'sunset'];
|
||||
const list = rows ?? FOUR.map(() => undefined);
|
||||
return (
|
||||
<View className="mx-3 mt-3 rounded-[22px] border-b-[5px] border-shade bg-card px-4 pt-3.5 pb-3">
|
||||
<View className="flex-row gap-3">
|
||||
<LinearGradient colors={rail.colors} locations={rail.locations} style={{ width: 12, borderRadius: 6 }} />
|
||||
<View className="flex-1">
|
||||
{list.map((t, i) => {
|
||||
const peak = t?.kind === 'peak';
|
||||
return (
|
||||
<View key={t?.kind ?? i} className={`flex-row items-baseline gap-2.5 ${peak ? '-mx-1.5 my-0.5 rounded-xl bg-[#fff1f2] px-2.5 py-2' : 'py-1.5'}`} style={!peak && i < list.length - 1 ? { borderBottomWidth: 1 } : undefined}>
|
||||
<View className="min-w-[96px]">
|
||||
{t ? <Text className={`font-jua ${peak ? 'text-[20px] text-[#d23d5a]' : 'text-[17px] text-ink'}`}>{t.end ? `${clockShort(t.at)}~${clockShort(t.end)}` : clockShort(t.at)}</Text> : <Skel className="w-11" />}
|
||||
</View>
|
||||
{t ? <Text className={`flex-1 ${peak ? 'font-jua text-base text-[#d23d5a]' : 'text-[13.5px] font-bold text-ink2'}`}>{t.label}</Text> : <Skel className="w-20" />}
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
</View>
|
||||
{rows && (
|
||||
<View className="mt-2">
|
||||
<Toggle
|
||||
label={
|
||||
<>
|
||||
<Q className="bg-[#f1ebe3]" />
|
||||
<Text className="text-[12px] font-bold text-ink2">골든아워·블루아워가 뭐예요</Text>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<Text className="mt-1.5 rounded-xl bg-[#faf6f1] px-2.5 py-2 text-[12px] leading-snug text-[#5a6380]">
|
||||
<Text className="font-bold text-[#28304a]">골든아워</Text> 해가 {kind === 'sunrise' ? '뜬 뒤' : '지기 전'}, 햇빛이 금빛으로 물드는 시간{'\n'}
|
||||
<Text className="font-bold text-[#28304a]">블루아워</Text> 해가 {kind === 'sunrise' ? '뜨기 전' : '진 뒤'}, 하늘이 짙은 파랑으로 남는 시간
|
||||
</Text>
|
||||
</Toggle>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const ROW = 'flex-row items-center gap-2.5 px-1 py-3';
|
||||
|
||||
export function LiSkel({ ghost = false, last = false }: { ghost?: boolean; last?: boolean }) {
|
||||
return (
|
||||
<View className={`${ROW} border-line ${ghost ? 'opacity-0' : ''}`} style={last ? undefined : { borderBottomWidth: 1.5 }}>
|
||||
<View className="w-[34px] items-center">
|
||||
<Skel className="w-5" />
|
||||
</View>
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="h-4 w-24" />
|
||||
<Skel className="w-40" />
|
||||
</View>
|
||||
<Skel className="w-9" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 번호 · 이름(+설명) · 오른쪽 값 한 줄 */
|
||||
export function Li({ no, title, sub, right, mine = false, place, last = false }: { no: number; title: string; sub?: string | null; right: string; mine?: boolean; place?: string; last?: boolean }) {
|
||||
return (
|
||||
<View className={`${ROW} border-line ${mine ? 'rounded-2xl bg-card' : ''}`} style={last ? undefined : { borderBottomWidth: 1.5 }}>
|
||||
<Text className="w-[34px] text-center font-bagel text-xl text-orange">{no}</Text>
|
||||
<View className="min-w-0 flex-1">
|
||||
<Text className="font-jua text-[17px] text-ink">
|
||||
{place ? <MapLink place={place}>{title}</MapLink> : title}
|
||||
{mine && <Text className="text-xs font-extrabold text-rain"> 내 지역</Text>}
|
||||
</Text>
|
||||
<Text numberOfLines={1} className="text-[12.5px] font-semibold text-ink2">
|
||||
{sub || ' '}
|
||||
</Text>
|
||||
</View>
|
||||
<Text className="font-jua text-base text-ink">{right}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { View } from 'react-native';
|
||||
import Svg, { Defs, Polygon, RadialGradient, Rect, Stop } from 'react-native-svg';
|
||||
|
||||
// 웹 .b-skyline::after 의 clip-path 를 그대로 (0~100 비율)
|
||||
const POINTS = '0,55 8,55 8,30 15,30 15,50 22,50 22,10 28,10 28,45 36,45 36,25 44,25 44,55 52,55 52,35 60,35 60,5 66,5 66,40 74,40 74,20 82,20 82,50 90,50 90,30 100,30 100,100 0,100';
|
||||
|
||||
/** 아래에 깔리는 동네 건물 실루엣. height 는 상자 높이 대비 비율 */
|
||||
export function Skyline({ height = '22%' }: { height?: `${number}%` }) {
|
||||
return (
|
||||
<View pointerEvents="none" style={{ position: 'absolute', left: 0, right: 0, bottom: 0, height }}>
|
||||
<Svg width="100%" height="100%" viewBox="0 0 100 100" preserveAspectRatio="none">
|
||||
<Polygon points={POINTS} fill="#2d2440" />
|
||||
</Svg>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 건물 뒤로 지는 해 (.b-sit-sun) */
|
||||
export function SitSun({ size = 112, bottom = 24, opacity = 1 }: { size?: number; bottom?: number; opacity?: number }) {
|
||||
return (
|
||||
<View pointerEvents="none" style={{ position: 'absolute', bottom, left: '50%', marginLeft: -size / 2, width: size, height: size, opacity }}>
|
||||
<Svg width={size} height={size} viewBox="0 0 2 2">
|
||||
<Defs>
|
||||
<RadialGradient id="sitsun" cx="1" cy="1" r="1" gradientUnits="userSpaceOnUse">
|
||||
<Stop offset="0" stopColor="#fff6dd" />
|
||||
<Stop offset="0.38" stopColor="#ffd08f" />
|
||||
<Stop offset="0.7" stopColor="#ffa05a" stopOpacity={0} />
|
||||
</RadialGradient>
|
||||
</Defs>
|
||||
<Rect x="0" y="0" width="2" height="2" fill="url(#sitsun)" />
|
||||
</Svg>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<Svg viewBox="0 0 24 24" width={size} height={size} {...line} stroke={color} strokeWidth={2.2}>
|
||||
<Path d="M12 21s7-6.2 7-11.5A7 7 0 0 0 5 9.5C5 14.8 12 21 12 21z" />
|
||||
<Circle cx="12" cy="9.5" r="2.5" />
|
||||
</Svg>
|
||||
);
|
||||
}
|
||||
|
||||
export function TabIcon({ name, size, color, strokeWidth }: { name: TabName; size: number; color: string; strokeWidth: number }) {
|
||||
return (
|
||||
<Svg viewBox="0 0 24 24" width={size} height={size} {...line} stroke={color} strokeWidth={strokeWidth}>
|
||||
{name === 'today' && <Path d="M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z" />}
|
||||
{name === 'gak' && (
|
||||
<>
|
||||
<Rect x="3.5" y="3.5" width="7" height="7" rx="2" />
|
||||
<Rect x="13.5" y="3.5" width="7" height="7" rx="2" />
|
||||
<Rect x="3.5" y="13.5" width="7" height="7" rx="2" />
|
||||
<Rect x="13.5" y="13.5" width="7" height="7" rx="2" />
|
||||
</>
|
||||
)}
|
||||
{name === 'sky' && <Path d="M3 18h18M6 14a6 6 0 0 1 12 0M12 4v3M4.9 7.9l2 2M19.1 7.9l-2 2M8 21h8" />}
|
||||
{name === 'week' && (
|
||||
<>
|
||||
<Rect x="3.5" y="5" width="17" height="15.5" rx="2.5" />
|
||||
<Path d="M3.5 10h17M8 3v4M16 3v4" />
|
||||
<Circle cx="12" cy="15" r="1.6" />
|
||||
</>
|
||||
)}
|
||||
{name === 'season' && <Path d="M12 6.5C10 5 7 4.5 3.5 5v14c3.5-.5 6.5 0 8.5 1.5 2-1.5 5-2 8.5-1.5V5C17 4.5 14 5 12 6.5zM12 6.5v14" />}
|
||||
</Svg>
|
||||
);
|
||||
}
|
||||
@@ -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<string, [TabName, string]> = {
|
||||
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 (
|
||||
<View
|
||||
className="flex-row border-t px-1 pt-[7px]"
|
||||
style={{ paddingBottom: 8 + bottom, backgroundColor: night ? 'rgb(18 24 60 / 0.92)' : 'rgb(255 255 255 / 0.85)', borderColor: night ? 'rgb(255 255 255 / 0.08)' : 'rgb(255 255 255 / 0.4)' }}
|
||||
>
|
||||
{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 (
|
||||
<Pressable key={route.key} onPress={onPress} accessibilityRole="tab" accessibilityState={{ selected: focused }} className="-mt-6 flex-1 items-center gap-1">
|
||||
<View className="size-[68px] items-center justify-center rounded-full" style={{ backgroundColor: night ? 'rgb(18 24 60 / 0.9)' : 'rgb(255 255 255 / 0.85)' }}>
|
||||
<LinearGradient colors={['#ffb067', '#ff7a45', '#d4552a']} locations={[0, 0.55, 1]} start={{ x: 0.3, y: 0 }} end={{ x: 0.7, y: 1 }} style={{ width: 60, height: 60, borderRadius: 30, alignItems: 'center', justifyContent: 'center', boxShadow: '0 8px 18px rgb(255 122 69 / 0.45)' }}>
|
||||
<TabIcon name="today" size={30} color="#fff" strokeWidth={2.6} />
|
||||
</LinearGradient>
|
||||
</View>
|
||||
<Text className="text-[12px] font-extrabold" style={{ color: focused ? orange : ink3 }}>
|
||||
{label}
|
||||
</Text>
|
||||
</Pressable>
|
||||
);
|
||||
return (
|
||||
<Pressable key={route.key} onPress={onPress} accessibilityRole="tab" accessibilityState={{ selected: focused }} className="flex-1 items-center gap-0.5">
|
||||
<TabIcon name={icon} size={25} color={focused ? ink : ink3} strokeWidth={focused ? 2.4 : 1.9} />
|
||||
<Text className="text-[11px] font-extrabold" style={{ color: focused ? ink : ink3 }}>
|
||||
{label}
|
||||
</Text>
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
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, type Weather, 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, type DimensionValue, type ViewStyle } from 'react-native';
|
||||
import Animated, { cancelAnimation, Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withDelay, withRepeat, withTiming } from 'react-native-reanimated';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import Svg, { Defs, Path, RadialGradient, Rect, Stop } from 'react-native-svg';
|
||||
|
||||
import { Fall } from '@/components/fall';
|
||||
import { Shoot, type ShootSpec } from '@/components/sky-bg';
|
||||
import { Ic, Skel } from '@/components/ui';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
type Mode = 'now' | TimeKind;
|
||||
|
||||
const HERO_BG: Record<TimeKind | 'gray', readonly [string, string, string]> = {
|
||||
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);
|
||||
|
||||
// 구름 자리·떨어지는 지연·둥둥 주기 (웹 CLOUDS). 구름 수: 구름 많음 둘, 흐림·비·눈 셋
|
||||
// 별똥별 셋: 위치·길이·주기를 엇갈려 하나씩 떨어지게 (웹 TodayPage SHOOTS, 밀리초)
|
||||
const SHOOTS: ShootSpec[] = [
|
||||
{ top: '6%', left: '80%', len: 90, dur: 7000, dl: 1500 },
|
||||
{ top: '20%', left: '52%', len: 70, dur: 9000, dl: 4000 },
|
||||
{ top: '34%', left: '94%', len: 80, dur: 11000, dl: 6500 },
|
||||
];
|
||||
|
||||
const CLOUDS = [
|
||||
{ top: 36, left: '5%', w: 84, h: 32, d: 100, f: 6000 },
|
||||
{ top: 96, left: '63%', w: 96, h: 36, d: 250, f: 6400 },
|
||||
{ top: 30, left: '72%', w: 64, h: 28, d: 400, f: 5400 },
|
||||
] as const;
|
||||
const CLOUD_N: Record<Weather, number> = { clear: 0, partly: 2, cloudy: 3, rain: 3, snow: 3, sleet: 3 };
|
||||
|
||||
// 비·눈 줄기: 위치·주기를 엇갈려 고르게
|
||||
const DROPS = Array.from({ length: 22 }, (_, i) => ({ left: `${(i * 41) % 100}%`, top: `${(i * 29) % 90}%`, delay: ((i * 37) % 100) * 10, dur: 550 + ((i * 13) % 5) * 100 }) as const);
|
||||
const FLAKES = Array.from({ length: 16 }, (_, i) => ({ left: `${(i * 47) % 100}%`, top: `${(i * 31) % 90}%`, delay: ((i * 53) % 100) * 40, dur: 3200 + ((i * 7) % 5) * 500 }) as const);
|
||||
|
||||
/** 둥근 구름: 몸통 위에 동그라미 둘을 겹친다 (웹 .b-cloud ::before/::after) */
|
||||
function Cloud({ w, h, night }: { w: number; h: number; night: boolean }) {
|
||||
const bg = night ? '#c9cdf0' : '#fff';
|
||||
const big = w * 0.46;
|
||||
const small = w * 0.36;
|
||||
return (
|
||||
<View style={{ width: w, height: h }}>
|
||||
<View style={{ position: 'absolute', left: w * 0.16, top: -h * 0.58, width: big, height: big, borderRadius: big, backgroundColor: bg }} />
|
||||
<View style={{ position: 'absolute', left: w * 0.5, top: -h * 0.36, width: small, height: small, borderRadius: small, backgroundColor: bg }} />
|
||||
<View style={{ width: w, height: h, borderRadius: h, backgroundColor: bg, boxShadow: '0 16px 28px rgb(40 70 120 / 0.13)' }} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 비 줄기·눈송이 하나: 위에서 아래로 계속 떨어진다. 동작 줄이기면 제자리에 멈춘다 */
|
||||
function Particle({ left, top, delay, dur, snow, light }: { left: DimensionValue; top: DimensionValue; delay: number; dur: number; snow: boolean; light: boolean }) {
|
||||
const reduce = useReducedMotion();
|
||||
const t = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
if (reduce) return;
|
||||
t.value = withDelay(delay, withRepeat(withTiming(1, { duration: dur, easing: Easing.linear }), -1, false));
|
||||
return () => cancelAnimation(t);
|
||||
}, [reduce, delay, dur, t]);
|
||||
const anim = useAnimatedStyle(() => ({ transform: [{ translateX: (snow ? 18 : -8) * t.value }, { translateY: 440 * t.value }] }));
|
||||
const place: ViewStyle = { position: 'absolute', left, top: reduce ? top : -24 };
|
||||
if (snow) return <Animated.View style={[place, { width: 7, height: 7, borderRadius: 7, backgroundColor: '#fff', boxShadow: '0 0 4px rgb(120 150 200 / 0.5)' }, anim]} />;
|
||||
return (
|
||||
<Animated.View style={[place, anim]}>
|
||||
<LinearGradient colors={['transparent', light ? 'rgba(220,230,255,0.7)' : 'rgba(80,130,200,0.7)']} style={{ width: 2, height: 18, borderRadius: 2 }} />
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
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 <Skel className={skel} />;
|
||||
return <Text className="opacity-50">?</Text>;
|
||||
}
|
||||
|
||||
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());
|
||||
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 rain = weather === 'rain' || weather === 'sleet';
|
||||
const snow = weather === 'snow' || weather === 'sleet';
|
||||
const orb = ORB[kind === 'sunset' ? 'sunset' : kind === 'night' ? 'night' : 'sun'];
|
||||
const text = dark ? 'text-white' : 'text-[#28304a]';
|
||||
|
||||
return (
|
||||
<View className="mx-3 mt-1 overflow-hidden rounded-[28px] px-4 pt-3 pb-3">
|
||||
<LinearGradient colors={HERO_BG[gray ? 'gray' : kind]} locations={kind === 'night' ? [0, 0.6, 1] : [0, 0.5, 1]} style={{ position: 'absolute', inset: 0 }} />
|
||||
{kind === 'night' && STARS.map((s, i) => <View key={i} className="absolute size-[3px] rounded-full bg-white" style={{ left: s.left, top: s.top, opacity: s.opacity }} />)}
|
||||
{kind === 'night' && SHOOTS.map((s, i) => <Shoot key={i} {...s} />)}
|
||||
{(rain || snow) && (
|
||||
<View pointerEvents="none" style={{ position: 'absolute', inset: 0 }}>
|
||||
{rain && DROPS.map((p, i) => <Particle key={`r${i}`} {...p} snow={false} light={dark} />)}
|
||||
{snow && FLAKES.map((p, i) => <Particle key={`s${i}`} {...p} snow light={dark} />)}
|
||||
</View>
|
||||
)}
|
||||
<Text className={`text-[14px] font-bold opacity-80 ${text}`}>
|
||||
{t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일
|
||||
</Text>
|
||||
<View className="h-[146px] items-center">
|
||||
<Fall d={0} f={5600} amp={8}>
|
||||
<View className="mt-2 size-32 items-center justify-center" style={{ boxShadow: `0 20px 40px ${kind === 'night' ? 'rgb(190 180 255 / 0.35)' : kind === 'sunset' ? 'rgb(255 150 110 / 0.4)' : 'rgb(240 106 58 / 0.32)'}`, borderRadius: 64 }}>
|
||||
<Svg viewBox="-1 -1 2 2" width={128} height={128} style={{ position: 'absolute' }}>
|
||||
<Defs>
|
||||
<RadialGradient id="orb" cx="-0.32" cy="-0.4" r="1.4" gradientUnits="userSpaceOnUse">
|
||||
<Stop offset="0" stopColor={orb.stops[0]} />
|
||||
<Stop offset="0.3" stopColor={orb.stops[1]} />
|
||||
<Stop offset="0.68" stopColor={orb.stops[2]} />
|
||||
<Stop offset="1" stopColor={orb.stops[3]} />
|
||||
</RadialGradient>
|
||||
</Defs>
|
||||
<Rect x="-1" y="-1" width="2" height="2" rx="1" fill="url(#orb)" opacity={gray ? 0.85 : 1} />
|
||||
{/* 안 보이는 쪽을 덮어 오늘 밤 달 모양으로 */}
|
||||
{moon && <Path d={moonPath(moon.pct, 1, false)} fill={kind === 'sunset' ? 'rgb(96 40 86 / .55)' : 'rgb(34 30 86 / .62)'} transform={moon.waning ? 'scale(-1,1)' : undefined} />}
|
||||
</Svg>
|
||||
<Text className="font-jua text-[12px]" style={{ color: orb.text }}>
|
||||
{failed(feedLoad) ? '점수를 못 불러왔어요' : `${slotScore != null && mode !== 'now' ? PREVIEW[mode].label : '지금'} 날씨 점수`}
|
||||
</Text>
|
||||
<Text className="font-bagel text-[52px] leading-[52px]" style={{ color: orb.text }}>
|
||||
{heroVal(feedLoad, score, 'w-[84px] h-10')}
|
||||
</Text>
|
||||
</View>
|
||||
</Fall>
|
||||
{CLOUDS.slice(0, CLOUD_N[weather]).map((c) => (
|
||||
<Fall key={c.left} d={c.d} f={c.f} style={{ position: 'absolute', top: c.top, left: c.left }}>
|
||||
<Cloud w={c.w} h={c.h} night={kind === 'night'} />
|
||||
</Fall>
|
||||
))}
|
||||
</View>
|
||||
<View className="items-center">
|
||||
{bubble ? (
|
||||
<Pressable disabled={!top1} onPress={() => top1 && open({ type: 'gak', indexId: top1.index_id })} accessibilityLabel={top1 ? `${bubble} 1위 ${top1.name} ${top1.score}점, 계산 근거 보기` : undefined}>
|
||||
<Text className={`text-center font-jua text-[24px] leading-tight ${text}`}>{bubble}</Text>
|
||||
</Pressable>
|
||||
) : (
|
||||
<Skel className="h-6 w-[160px]" />
|
||||
)}
|
||||
{top1?.summary ? <Text className={`mt-0.5 text-center text-[15px] font-bold opacity-80 ${text}`}>{top1.summary}</Text> : feedLoad === 'loading' ? <Skel className="mt-1 w-[140px]" /> : null}
|
||||
{/* 상태 한 줄: 습도·불쾌지수·자외선·미세먼지 단계 이름. 조심할 것만 색 */}
|
||||
{status.length > 0 && (
|
||||
<Text className={`mt-1.5 text-center font-jua text-[14px] ${text}`}>
|
||||
{status.map((x, i) => (
|
||||
<Text key={x.label}>
|
||||
{i > 0 && <Text className="opacity-30"> · </Text>}
|
||||
<Text style={x.tone === 'warn' ? { color: dark ? '#ffb38a' : '#d4552a' } : undefined}>
|
||||
<Text className={x.tone !== 'warn' ? 'opacity-75' : undefined}>{x.label}</Text> {x.value}
|
||||
</Text>
|
||||
</Text>
|
||||
))}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
<View className="mt-2.5 flex-row gap-1 rounded-[18px] p-[3px]" style={{ backgroundColor: dark ? 'rgb(255 255 255 / 0.14)' : 'rgb(255 255 255 / 0.42)' }} accessibilityRole="tablist" accessibilityLabel="하루 흐름, 누르면 그 시간대 하늘로">
|
||||
{KINDS.map((k) => {
|
||||
const isNow = k === nowKind;
|
||||
const s = slotOf(isNow ? 'now' : k);
|
||||
const on = k === kind;
|
||||
return (
|
||||
<Pressable key={k} accessibilityRole="tab" accessibilityState={{ selected: on }} onPress={() => 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}>
|
||||
<Text className={`text-[13px] font-bold ${on ? 'text-[#d4552a]' : `opacity-75 ${text}`}`}>{isNow ? '지금' : PREVIEW[k].label}</Text>
|
||||
<Ic name={k === 'night' && weatherOf(s) === 'clear' ? 'moon' : WEATHER_ICON[weatherOf(s)]} size={22} style={{ marginVertical: 2 }} />
|
||||
<Text className={`font-jua text-[15px] ${on ? 'text-[#28304a]' : text}`}>{heroVal(todayLoad, s?.temp_c != null ? deg(s.temp_c) : null, 'w-7')}</Text>
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
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 { 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 (
|
||||
<Rail>
|
||||
{items.map((g, i) => (
|
||||
<Pressable key={g.index_id} onPress={() => 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'}`}>
|
||||
<View className="size-[68px]">
|
||||
{!g.active || g.score < 50 ? (
|
||||
<View className="absolute inset-0 rounded-full bg-[#d6deea]" />
|
||||
) : (
|
||||
<LinearGradient colors={['#ff7a45', '#ffc86e', '#8fcaff']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={{ position: 'absolute', inset: 0, borderRadius: 34 }} />
|
||||
)}
|
||||
<View className="m-[3px] flex-1 items-center justify-center rounded-full border-[3px] border-page bg-page">
|
||||
<Ic name={g.icon} size={42} />
|
||||
</View>
|
||||
{i < 3 && g.active && <Ic name={MEDALS[i]} size={25} style={{ position: 'absolute', right: -4, bottom: -4 }} />}
|
||||
</View>
|
||||
<Text numberOfLines={1} className="font-jua text-[13px] text-ink">
|
||||
{g.name}
|
||||
</Text>
|
||||
{g.active ? <Text className="font-bagel text-[12.5px] leading-[14px] text-orange">{g.score}</Text> : <Text className="text-[11px] leading-[14px] font-extrabold text-ink3">지금 아님</Text>}
|
||||
</Pressable>
|
||||
))}
|
||||
</Rail>
|
||||
);
|
||||
}
|
||||
|
||||
const SKELS = Array.from({ length: 6 }, (_, i) => i);
|
||||
|
||||
export function StoriesSkel() {
|
||||
return (
|
||||
<Rail>
|
||||
{SKELS.map((i) => (
|
||||
<View key={i} className="w-[72px] items-center gap-1.5">
|
||||
<View className="size-[68px] rounded-full bg-skel" />
|
||||
<Skel className="w-12" />
|
||||
<Skel className="w-6" />
|
||||
</View>
|
||||
))}
|
||||
</Rail>
|
||||
);
|
||||
}
|
||||
|
||||
function Band({ tone, title, sub, to, children }: { tone: 1 | 2 | 3; title: string; sub: string; to: Href; children: ReactNode }) {
|
||||
const { kind } = useSky();
|
||||
return (
|
||||
<View className="mt-3.5 pb-3.5" accessibilityLabel={title}>
|
||||
<LinearGradient colors={BAND_BG[kind === 'night' ? 'night' : 'day'][tone]} style={{ position: 'absolute', inset: 0 }} />
|
||||
<View className="-mt-[6px]">
|
||||
<Sec title={title} sub={sub} more={to} />
|
||||
</View>
|
||||
{children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function useCardBg() {
|
||||
const { kind } = useSky();
|
||||
return CARD_BG[kind === 'night' ? 'night' : 'day'];
|
||||
}
|
||||
|
||||
export function EventsBand({ events }: { events: BandEvent[] }) {
|
||||
const bg = useCardBg();
|
||||
return (
|
||||
<Band tone={1} title="이번 주 가까운 행사" sub="30km 안 · 날씨까지 같이 보고 골라요" to="/week">
|
||||
<Rail>
|
||||
{events.map((e, i) => (
|
||||
<Link key={e.event_id} href="/week" asChild>
|
||||
<Pressable className={`w-[200px] ${CARD}`}>
|
||||
<Thumb image={e.image} icon={e.icon} iconSize={76} className="h-[116px]">
|
||||
<LinearGradient colors={bg[cardBg(e.icon, i)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
|
||||
<View className={`absolute top-2.5 left-2.5 rounded-full px-2 py-[3px] ${e.status_label === '진행 중' ? 'bg-[#1f9d62]' : 'bg-orange'}`}>
|
||||
<Text className="text-[11.5px] font-extrabold text-white">{e.status_label}</Text>
|
||||
</View>
|
||||
</Thumb>
|
||||
<Text className="px-3 pt-2.5 pb-3 font-jua text-[16.5px] leading-snug text-ink">{e.name}</Text>
|
||||
</Pressable>
|
||||
</Link>
|
||||
))}
|
||||
</Rail>
|
||||
</Band>
|
||||
);
|
||||
}
|
||||
|
||||
export function TopBand({ items, sub }: { items: TopIndex[]; sub: string }) {
|
||||
const { open } = useSheet();
|
||||
return (
|
||||
<Band tone={2} title="지금 뜨는 각 TOP 5" sub={sub} to="/gak">
|
||||
<Rail>
|
||||
{items.slice(0, 5).map((g, i) => (
|
||||
<Pressable key={g.index_id} onPress={() => 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 ? <Ic name={MEDALS[i]} size={26} style={{ position: 'absolute', top: 8, left: 8 }} /> : <Text className="absolute top-2.5 left-3 font-jua text-ink3">{i + 1}위</Text>}
|
||||
<Ic name={g.icon} size={58} style={{ alignSelf: 'center' }} />
|
||||
<Text className="font-jua text-base text-ink">{g.name}</Text>
|
||||
<Text className="font-bagel text-[22px] leading-[24px] text-orange">{g.score}</Text>
|
||||
{g.summary && <Text className="text-xs font-semibold text-ink2">{g.summary}</Text>}
|
||||
</Pressable>
|
||||
))}
|
||||
</Rail>
|
||||
</Band>
|
||||
);
|
||||
}
|
||||
|
||||
export function SeasonBand({ news }: { news: BandArticle[] }) {
|
||||
const bg = useCardBg();
|
||||
const { open } = useSheet();
|
||||
return (
|
||||
<Band tone={3} title="이번 주 계절 이야기" sub="예년 이맘때의 소식" to="/season">
|
||||
<Rail>
|
||||
{news.map((a) => (
|
||||
<Pressable key={a.article_id} onPress={() => open({ type: 'article', articleId: a.article_id })} className={`w-[200px] ${CARD}`}>
|
||||
<Thumb image={a.image} icon={a.icon} iconSize={76} className="h-[116px]">
|
||||
<LinearGradient colors={bg[cardBg(a.icon, a.article_id)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
|
||||
</Thumb>
|
||||
<View className="px-3 pt-2.5 pb-3">
|
||||
<Text className="font-jua text-[16.5px] leading-snug text-ink">{a.title}</Text>
|
||||
<Text className="text-[12.5px] font-semibold text-ink2">{a.meta}</Text>
|
||||
</View>
|
||||
</Pressable>
|
||||
))}
|
||||
</Rail>
|
||||
</Band>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
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 { Pressable, Text, View } from 'react-native';
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
import { useCSSVariable } from 'uniwind';
|
||||
|
||||
import { PinIcon } from '@/components/svg';
|
||||
import { Avatar, Ic, Skel } from '@/components/ui';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
const TITLES: Record<string, string> = { '/sky': '노을', '/gak': '오늘의 각', '/week': '주말·행사', '/season': '계절·상식' };
|
||||
|
||||
/** 로고 옆 계절 칩: 계절 이름과 지금 절기. 누르면 이번 주 절기 창 */
|
||||
function SeasonChip() {
|
||||
const { open } = useSheet();
|
||||
const week = useQuery(getSeasonWeekOptions());
|
||||
const [month] = useState(() => kst(new Date()).mo);
|
||||
const [name, icon] = seasonOf(month);
|
||||
const term = week.data?.term_now?.name;
|
||||
return (
|
||||
<Pressable onPress={() => open({ type: 'seasonWeek' })} accessibilityLabel={`지금 ${name}${term ? `, ${term}` : ''}. 이번 주 절기 보기`} className="shrink flex-row items-center gap-1 rounded-full bg-card/70 py-1 pr-2.5 pl-1.5">
|
||||
<Ic name={icon} size={18} />
|
||||
<Text numberOfLines={1} className="shrink text-[13px] font-extrabold text-ink">
|
||||
{name}
|
||||
{term && <Text className="font-bold opacity-70"> · {term}</Text>}
|
||||
</Text>
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
/** 오른쪽 끝: 내 정보(아바타) 또는 로그인 버튼 */
|
||||
function Account() {
|
||||
const { open } = useSheet();
|
||||
const { me, mePending } = useAuth();
|
||||
if (mePending) return <View className="size-9 shrink-0 rounded-full bg-skel" />;
|
||||
if (me)
|
||||
return (
|
||||
<Pressable onPress={() => open({ type: 'me' })} accessibilityLabel={`내 정보, ${me.nickname}`} className="shrink-0 rounded-full" style={{ boxShadow: '0 6px 12px rgb(40 48 74 / 0.12)' }}>
|
||||
<Avatar character={me.character} color={me.color} mood={me.mood} size={36} />
|
||||
</Pressable>
|
||||
);
|
||||
return (
|
||||
<Pressable onPress={() => open({ type: 'login' })} className="shrink-0 rounded-full bg-ink-btn px-3 py-1.5">
|
||||
<Text className="text-[13px] font-extrabold text-white">로그인</Text>
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
export function TopBar() {
|
||||
const pathname = usePathname();
|
||||
const { region, locateStatus } = useRegion();
|
||||
const { open } = useSheet();
|
||||
const { kind } = useSky();
|
||||
const { top } = useSafeAreaInsets();
|
||||
const ink = String(useCSSVariable('--color-ink'));
|
||||
const title = TITLES[pathname];
|
||||
return (
|
||||
<View style={{ paddingTop: top, backgroundColor: kind === 'night' ? 'rgb(14 20 51 / 0.35)' : 'rgb(255 255 255 / 0.18)' }}>
|
||||
<View className="h-[54px] flex-row items-center gap-2 px-4">
|
||||
{title ? <Text className="font-jua text-[22px] text-ink">{title}</Text> : <Text className="font-jua text-[25px] text-orange">날씨각</Text>}
|
||||
<SeasonChip />
|
||||
<Pressable onPress={() => open({ type: 'region' })} accessibilityLabel={`위치 바꾸기, 지금 ${region.name}`} className="ml-auto shrink-0 flex-row items-center gap-1 rounded-full border-b-4 border-shade bg-card px-3 pt-1 pb-1.5">
|
||||
<PinIcon size={14} color={ink} />
|
||||
{locateStatus === 'locating' ? (
|
||||
<Skel className="w-[52px]" />
|
||||
) : (
|
||||
<Text numberOfLines={1} className="text-[13.5px] font-bold text-ink">
|
||||
{region.name.split(' ').at(-1)}
|
||||
</Text>
|
||||
)}
|
||||
</Pressable>
|
||||
<Account />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
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 { useEffect, useState, type ReactNode } from 'react';
|
||||
import Animated, { cancelAnimation, Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated';
|
||||
import { Linking, 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<ImageStyle> }) {
|
||||
if (name === 'none') return <View style={{ width: size, height: size }} />;
|
||||
return <Image source={ICONS[name] ?? ICONS.sun_cloud} style={[{ width: size, height: size }, style]} contentFit="contain" />;
|
||||
}
|
||||
|
||||
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<ViewStyle>; children?: ReactNode }) {
|
||||
return (
|
||||
<View className={className} style={style}>
|
||||
<LinearGradient colors={colors} locations={locations} style={{ position: 'absolute', inset: 0 }} />
|
||||
{children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 사진이 있으면 사진, 없거나 못 불러오면 아이콘 */
|
||||
export function Thumb({ image, icon, iconSize, className, style, children }: { image?: string | null; icon: string; iconSize: number; className?: string; style?: StyleProp<ViewStyle>; children?: ReactNode }) {
|
||||
const [failed, setFailed] = useState<string | null>(null);
|
||||
const photo = image && image !== failed ? image : null;
|
||||
return (
|
||||
<View className={`items-center justify-center overflow-hidden ${className ?? ''}`} style={style}>
|
||||
{photo ? <Image source={{ uri: imageUri(photo) }} onError={() => setFailed(photo)} style={{ position: 'absolute', inset: 0 }} contentFit="cover" /> : <Ic name={icon} size={iconSize} />}
|
||||
{children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 불러오는 동안 자리만 잡는 막대. 천천히 깜빡인다 (웹 animate-pulse, 동작 줄이기면 멈춤) */
|
||||
export function Skel({ className }: { className?: string }) {
|
||||
const reduce = useReducedMotion();
|
||||
const dim = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
if (reduce) return;
|
||||
dim.value = withRepeat(withTiming(1, { duration: 1000, easing: Easing.bezier(0.4, 0, 0.6, 1) }), -1, true);
|
||||
return () => cancelAnimation(dim);
|
||||
}, [reduce, dim]);
|
||||
const pulse = useAnimatedStyle(() => ({ opacity: 1 - dim.value * 0.5 }));
|
||||
return (
|
||||
<Animated.View style={pulse}>
|
||||
<View className={`h-[0.9em] min-h-3 rounded-full bg-skel ${className ?? ''}`} />
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
export function Sec({ title, sub, more }: { title: string; sub?: string; more?: Href }) {
|
||||
return (
|
||||
<View className="flex-row items-end justify-between px-4 pt-[22px] pb-1.5">
|
||||
<View>
|
||||
<Text className="font-jua text-[21px] text-ink">{title}</Text>
|
||||
{sub && <Text className="mt-0.5 text-[13px] font-semibold text-ink2">{sub}</Text>}
|
||||
</View>
|
||||
{more && (
|
||||
<Link href={more} className="text-[13px] font-bold text-ink2">
|
||||
전체 보기
|
||||
</Link>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 가로로 넘기는 줄 */
|
||||
export function Rail({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerClassName="gap-2.5 px-4 pt-3 pb-1">
|
||||
{children}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 실패·빈 목록 안내. 불러오는 중엔 그리지 않는다(그 자리는 스켈레톤).
|
||||
* hold 에 스켈레톤을 주면 그 크기를 보이지 않게 깔고 안내를 그 위에 띄운다 — 로딩·실패·빈 상태의 자리 크기가 같다.
|
||||
* 이때 boxClassName 은 안내 상자의 위치(스켈레톤 바깥 여백만큼 inset).
|
||||
*/
|
||||
export function StateBox({ load, onRetry, empty, hold, boxClassName = 'inset-x-3 top-3 bottom-0' }: { load: Load; onRetry?: () => void; empty?: string; hold?: ReactNode; boxClassName?: string }) {
|
||||
const failed = load === 'error' || load === 'retrying';
|
||||
const text = failed ? '정보를 불러오지 못했어요.' : load === 'ready' ? empty : undefined;
|
||||
if (!text) return null;
|
||||
const box = (
|
||||
<View className={`items-center justify-center gap-2 rounded-[22px] border-b-[5px] border-shade bg-card px-4 py-6 ${hold ? `absolute ${boxClassName}` : 'mx-3 mt-3'}`}>
|
||||
<Text className="text-center text-[13.5px] font-semibold text-ink2">{text}</Text>
|
||||
{failed && onRetry && (
|
||||
<Pressable onPress={onRetry} disabled={load === 'retrying'} className="rounded-full bg-ink-btn px-4 py-1.5 disabled:opacity-60">
|
||||
<Text className="text-[13px] font-bold text-white">{load === 'retrying' ? '다시 불러오는 중…' : '다시 시도'}</Text>
|
||||
</Pressable>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
if (!hold) return box;
|
||||
return (
|
||||
<View>
|
||||
<View style={{ opacity: 0 }} pointerEvents="none" accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
|
||||
{hold}
|
||||
</View>
|
||||
{box}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 사진 출처 표기 (공공누리 조건). 위치는 className 으로 */
|
||||
export function Credit({ text, className = 'right-1 bottom-1' }: { text: string; className?: string }) {
|
||||
return (
|
||||
<View pointerEvents="none" className={`absolute z-[1] rounded-[5px] bg-[rgb(16_20_34/0.5)] px-1 py-px ${className}`}>
|
||||
<Text numberOfLines={1} className="text-[9px] leading-tight font-semibold text-white">
|
||||
{text}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 프로필 동그라미: 고른 배경색 위에 캐릭터, 오른쪽 위에 오늘 기분 */
|
||||
export function Avatar({ character, color, mood, size = 34 }: { character: string; color?: string | null; mood?: string | null; size?: number }) {
|
||||
const emoji = moodEmoji(mood);
|
||||
return (
|
||||
<View className="items-center justify-center rounded-full" style={{ width: size, height: size, backgroundColor: AVATAR_COLORS[color ?? ''] ?? AVATAR_COLORS.orange }}>
|
||||
<Ic name={character} size={size * 0.7} />
|
||||
{emoji && (
|
||||
<View className="absolute -top-1 -right-1 items-center justify-center rounded-full bg-white" style={{ width: size * 0.48, height: size * 0.48 }}>
|
||||
<Text style={{ fontSize: size * 0.3 }}>{emoji}</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
type ChipsProps<K extends string> = { items: readonly (readonly [K, string])[]; value: K; onChange: (k: K) => void; disabled?: boolean };
|
||||
|
||||
/** 가로로 넘기는 고르기 칩 */
|
||||
export function Chips<K extends string>({ items, value, onChange, disabled }: ChipsProps<K>) {
|
||||
return (
|
||||
<ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerClassName="gap-2 px-4 pt-3 pb-0.5">
|
||||
{items.map(([k, l]) => (
|
||||
<Pressable key={k} accessibilityState={{ selected: value === k }} disabled={disabled} onPress={() => onChange(k)} className={`rounded-full px-3.5 py-[7px] ${value === k ? 'bg-ink-btn' : 'border-b-[3px] border-shade bg-chip'}`}>
|
||||
<Text className={`text-[13.5px] font-bold ${value === k ? 'text-white' : 'text-ink2'}`}>{l}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
/** 장소 이름. 누르면 네이버 지도가 열린다 */
|
||||
export function MapLink({ place, children }: { place: string; children: ReactNode }) {
|
||||
return (
|
||||
<Text onPress={() => Linking.openURL(naverMap(place))} accessibilityRole="link" accessibilityLabel={`${place}, 네이버 지도에서 보기`} className="underline">
|
||||
{children}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
/** 자외선 단계(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 (
|
||||
<View className="mt-auto">
|
||||
{rows.map((r, i) => (
|
||||
<View key={r.label} className="flex-row items-center justify-between gap-2.5 py-2.5" style={i < rows.length - 1 ? { borderBottomWidth: 2, borderColor: dark ? 'rgb(255 255 255 / 0.18)' : 'rgb(40 48 74 / 0.08)' } : undefined}>
|
||||
<Text className={`font-bold ${dark ? 'text-white' : 'text-ink'}`}>{r.label}</Text>
|
||||
{r.level ? (
|
||||
<Text className="overflow-hidden rounded-full px-2.5 py-[3px] font-jua text-[15px]" style={{ backgroundColor: LEVEL_CHIP[r.level - 1][0], color: LEVEL_CHIP[r.level - 1][1] }}>
|
||||
{r.value}
|
||||
</Text>
|
||||
) : (
|
||||
<Text className={`text-right font-jua text-[17px] ${dark ? 'text-white' : 'text-ink'}`}>{r.place ? <MapLink place={r.place}>{r.value}</MapLink> : r.value}</Text>
|
||||
)}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
import type { EventData, PlaceData, WeekRankItem, DayData } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { cardBg, dateRange } from '@nalssigak/shared/lib';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { Pressable, ScrollView, Text, View } from 'react-native';
|
||||
|
||||
import { Credit, Ic, MapLink, Thumb } from '@/components/ui';
|
||||
import { CARD_BG } from '@/lib/colors';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
import { DAY_W, EVENT_CARD, PLACE_CARD } from './skels';
|
||||
|
||||
const PLACE_BG: Record<string, string> = { picnic: 'mint', walk: 'mint', sunset: 'dusk', chimaek: 'peach', photo: 'butter', bulb: 'lilac' };
|
||||
|
||||
function useBg() {
|
||||
const { kind } = useSky();
|
||||
return { night: kind === 'night', bg: CARD_BG[kind === 'night' ? 'night' : 'day'] };
|
||||
}
|
||||
|
||||
/** 열흘 날짜 줄: 누르면 그날 추천이 바뀐다 */
|
||||
export function DayStrip({ days, selected, onPick, dim }: { days: DayData[]; selected?: string; onPick: (day: string) => void; dim: boolean }) {
|
||||
const { night } = useBg();
|
||||
const red = night ? '#ff8db5' : '#d6457a';
|
||||
return (
|
||||
<ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerClassName="gap-1 px-3 pt-3" style={{ opacity: dim ? 0.6 : 1 }} accessibilityLabel="날짜 고르기">
|
||||
{days.map((d) => {
|
||||
const on = d.day === selected;
|
||||
const weekend = d.weekday === '토' || d.weekday === '일' || !!d.holiday;
|
||||
return (
|
||||
<Pressable key={d.day} accessibilityState={{ selected: on }} onPress={() => onPick(d.day)} className={`${DAY_W} items-center gap-0.5 rounded-[18px] pt-[9px] pb-2 ${on ? 'bg-ink-btn' : 'border-b-4 border-shade bg-card'}`}>
|
||||
<Text className={`text-xs font-extrabold ${on ? 'text-white' : weekend ? '' : 'text-ink2'}`} style={!on && weekend ? { color: red } : undefined}>
|
||||
{d.weekday}
|
||||
</Text>
|
||||
<Ic name={d.icon} size={28} />
|
||||
<Text className={`font-jua text-sm ${on ? 'text-white' : 'text-ink'}`}>{d.temp_max_c != null ? `${Math.round(d.temp_max_c)}°` : <Text className="opacity-50">?</Text>}</Text>
|
||||
<Text numberOfLines={1} className="px-0.5 text-[9.5px] font-extrabold" style={{ color: on ? '#ffb3c4' : red }}>
|
||||
{d.holiday ? d.holiday.replace(/\(.*\)/, '') : `${Number(d.day.slice(8))}일`}
|
||||
</Text>
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
/** 고른 날 추천 한 장 */
|
||||
export function PickCard({ day }: { day: DayData }) {
|
||||
const { night, bg } = useBg();
|
||||
return (
|
||||
<View className="mx-3 mt-3 flex-row items-center gap-3.5 overflow-hidden rounded-3xl border-b-[5px] border-shade p-4" accessibilityLiveRegion="polite">
|
||||
<LinearGradient colors={night ? bg.mint : ['#e9fbf2', '#ffffff']} style={{ position: 'absolute', inset: 0 }} />
|
||||
<Ic name={day.icon} size={64} />
|
||||
<View className="flex-1">
|
||||
<Text className="font-jua text-[19px] text-ink">{day.headline}</Text>
|
||||
<Text className="mt-0.5 text-[13.5px] font-semibold text-ink2">{day.summary}</Text>
|
||||
<Text className="mt-2 font-jua text-base text-ink">{day.pick}</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function PlaceCard({ place: p, index }: { place: PlaceData; index: number }) {
|
||||
const { bg } = useBg();
|
||||
return (
|
||||
<View className={PLACE_CARD}>
|
||||
<Thumb image={p.image} icon={p.icon} iconSize={62} className="h-[104px]">
|
||||
<LinearGradient colors={bg[PLACE_BG[p.icon] ?? (p.is_outdoor ? 'mint' : cardBg(p.icon, index))]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
|
||||
{p.is_good && (
|
||||
<View className={`absolute top-2.5 left-2.5 rounded-full px-2 py-[3px] ${p.is_outdoor ? 'bg-[#1f9d62]' : 'bg-rain'}`}>
|
||||
<Text className="text-[11.5px] font-extrabold text-white">{p.is_outdoor ? '오늘 딱' : '비 와도 OK'}</Text>
|
||||
</View>
|
||||
)}
|
||||
{p.image && p.image_credit && <Credit text={p.image_credit} />}
|
||||
</Thumb>
|
||||
<View className="px-3 pt-2.5 pb-3">
|
||||
<Text className="text-[11.5px] font-extrabold text-ink3">
|
||||
{p.area} · {p.distance_km}km · {p.is_outdoor ? '야외' : '실내'}
|
||||
</Text>
|
||||
<Text className="font-jua text-[16.5px] text-ink">
|
||||
<MapLink place={p.name}>{p.name}</MapLink>
|
||||
</Text>
|
||||
<Text className="text-[12.5px] leading-snug font-semibold text-ink2">
|
||||
{p.reason}
|
||||
{'\n'}추천 {p.best_time}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function RankRow({ item: r, mine }: { item: WeekRankItem; mine: boolean }) {
|
||||
return (
|
||||
<View className={`flex-row items-center gap-2.5 border-b-[1.5px] border-line px-1 py-3 ${mine ? 'rounded-2xl bg-card' : ''}`}>
|
||||
<Text className="w-[34px] text-center font-bagel text-xl text-orange">{r.rank}</Text>
|
||||
<View className="min-w-0 flex-1">
|
||||
<Text numberOfLines={1} className="font-jua text-[17px] text-ink">
|
||||
{r.name}
|
||||
{mine && <Text className="text-xs font-extrabold text-rain"> 내 지역</Text>}
|
||||
</Text>
|
||||
<Text numberOfLines={1} className="text-[12.5px] font-semibold text-ink2">
|
||||
{r.reason}
|
||||
{r.estimated && ' · 예상'}
|
||||
</Text>
|
||||
<View className="mt-[5px] h-1.5 overflow-hidden rounded-full bg-[#eef1f6]">
|
||||
<LinearGradient colors={['#9be7c4', '#1f9d62']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }} style={{ height: '100%', width: `${r.score}%` }} />
|
||||
</View>
|
||||
</View>
|
||||
<View className="flex-row items-center gap-1">
|
||||
<Ic name={r.icon} size={24} />
|
||||
<Text className="font-jua text-base text-ink">{r.score}점</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function EventRow({ event: e, index }: { event: EventData; index: number }) {
|
||||
const { night, bg } = useBg();
|
||||
const live = e.status === 'live';
|
||||
const rainy = e.fit?.includes('비');
|
||||
return (
|
||||
<View className={EVENT_CARD}>
|
||||
<Thumb image={e.image} icon={e.icon} iconSize={56} className="h-[84px] w-[84px] rounded-2xl">
|
||||
<LinearGradient colors={bg[cardBg(e.icon, index)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
|
||||
{e.image && e.image_credit && <Credit text={e.image_credit} />}
|
||||
</Thumb>
|
||||
{/* 이름 두 줄·정보 한 줄·날씨 한 줄로 고정해 카드 높이가 데이터와 무관하게 같다 */}
|
||||
<View className="min-w-0 flex-1">
|
||||
<Text numberOfLines={2} className="h-[46px] font-jua text-[17px] leading-snug text-ink">
|
||||
<Text className="text-[11px] font-extrabold" style={{ color: live ? (night ? '#4fd39a' : '#1f7a4f') : night ? '#ffab85' : '#c2471b', backgroundColor: live ? (night ? 'rgba(79,211,154,0.16)' : '#dff5ea') : night ? 'rgba(255,138,87,0.16)' : '#ffe8dc' }}>
|
||||
{` ${e.status_label} `}
|
||||
</Text>{' '}
|
||||
{e.name}
|
||||
</Text>
|
||||
<Text numberOfLines={1} className="text-[12.5px] font-semibold text-ink2">
|
||||
{dateRange(e.start_date, e.end_date)}
|
||||
{e.place_name && (
|
||||
<>
|
||||
{' · '}
|
||||
<MapLink place={e.place_name}>{e.place_name}</MapLink>
|
||||
</>
|
||||
)}
|
||||
{!e.is_confirmed && ' · 일정 확인 필요'}
|
||||
</Text>
|
||||
<Text numberOfLines={1} className="mt-[5px] text-xs font-extrabold" style={{ color: rainy ? (night ? '#ff8db5' : '#d6457a') : night ? '#4fd39a' : '#1f9d62' }}>
|
||||
{e.fit ?? ' '}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import { View } from 'react-native';
|
||||
|
||||
import { Skel } from '@/components/ui';
|
||||
|
||||
const TEN = Array.from({ length: 10 }, (_, i) => i);
|
||||
const THREE = [0, 1, 2];
|
||||
|
||||
export const DAY_W = 'w-[46px]';
|
||||
export const PLACE_CARD = 'w-[178px] overflow-hidden rounded-[22px] border-b-[5px] border-shade bg-card';
|
||||
export const EVENT_CARD = 'mx-3 mt-2.5 flex-row items-center gap-3 rounded-[22px] border-b-[5px] border-shade bg-card p-3';
|
||||
|
||||
export function DaysSkel() {
|
||||
return (
|
||||
<View className="flex-row gap-1 overflow-hidden px-3 pt-3">
|
||||
{TEN.map((i) => (
|
||||
<View key={i} className={`${DAY_W} items-center gap-1 rounded-[18px] border-b-4 border-shade bg-card pt-[9px] pb-2`}>
|
||||
<Skel className="w-3" />
|
||||
<View className="size-7 rounded-full bg-skel" />
|
||||
<Skel className="w-6" />
|
||||
<Skel className="w-5" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function PickSkel() {
|
||||
return (
|
||||
<View className="mx-3 mt-3 flex-row items-center gap-3.5 rounded-3xl border-b-[5px] border-shade bg-card p-4">
|
||||
<View className="size-16 rounded-full bg-skel" />
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="h-4 w-32" />
|
||||
<Skel className="w-4/5" />
|
||||
<Skel className="mt-1 w-36" />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function PlacesSkel() {
|
||||
return (
|
||||
<View className="flex-row gap-2.5 overflow-hidden px-4 pt-3 pb-1">
|
||||
{THREE.map((i) => (
|
||||
<View key={i} className={PLACE_CARD}>
|
||||
<View className="h-[104px] bg-skel" />
|
||||
<View className="gap-1.5 px-3 pt-2.5 pb-3">
|
||||
<Skel className="w-16" />
|
||||
<Skel className="h-4 w-24" />
|
||||
<Skel className="w-full" />
|
||||
<Skel className="w-20" />
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function EventSkel() {
|
||||
return (
|
||||
<View className={EVENT_CARD}>
|
||||
<View className="h-[84px] w-[84px] rounded-2xl bg-skel" />
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="h-4 w-40" />
|
||||
<Skel className="h-4 w-20" />
|
||||
<Skel className="w-44" />
|
||||
<Skel className="w-24" />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function EventsSkel() {
|
||||
return (
|
||||
<>
|
||||
{THREE.map((i) => (
|
||||
<EventSkel key={i} />
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function RankSkel() {
|
||||
return (
|
||||
<View className="mx-3 mt-1.5">
|
||||
{TEN.map((i) => (
|
||||
<View key={i} className="flex-row items-center gap-2.5 border-b-[1.5px] border-line px-1 py-3">
|
||||
<View className="w-[34px] items-center">
|
||||
<Skel className="w-5" />
|
||||
</View>
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="h-4 w-24" />
|
||||
<Skel className="w-40" />
|
||||
<View className="h-1.5 rounded-full bg-skel" />
|
||||
</View>
|
||||
<View className="flex-row items-center gap-1">
|
||||
<View className="size-6 rounded-full bg-skel" />
|
||||
<Skel className="w-9" />
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
@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';
|
||||
--font-batang: 'GowunBatang_400Regular';
|
||||
}
|
||||
@@ -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));
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -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<AuthApi | null>(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 <AuthContext value={api}>{children}</AuthContext>;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// 웹 b.css 의 카드 배경(.b-bg-*)·가로 띠(.b-band-*) 그라데이션. 밤은 어두운 판
|
||||
type Stops = readonly [string, string, ...string[]];
|
||||
|
||||
export const CARD_BG: Record<'day' | 'night', Record<string, Stops>> = {
|
||||
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)'] },
|
||||
};
|
||||
@@ -0,0 +1,77 @@
|
||||
// frontend/public 의 아이콘을 그대로 쓴다. Metro 는 정적 require 만 묶을 수 있어 이름마다 적는다
|
||||
export const ICONS: Record<string, number> = {
|
||||
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'),
|
||||
};
|
||||
@@ -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 } },
|
||||
});
|
||||
@@ -0,0 +1,91 @@
|
||||
import { nearestRegion } from '@nalssigak/shared/api/client/sdk.gen';
|
||||
import type { RegionData } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { DEFAULT_REGION } from '@nalssigak/shared/lib';
|
||||
import * as Location from 'expo-location';
|
||||
import * as SecureStore from 'expo-secure-store';
|
||||
import { createContext, use, useCallback, useEffect, useMemo, useState, type ReactNode } from 'react';
|
||||
|
||||
const KEY = 'nalssigak.region';
|
||||
|
||||
export type LocateStatus = 'idle' | 'locating' | 'denied' | 'error';
|
||||
|
||||
export type RegionApi = { region: RegionData; setRegion: (r: RegionData) => void; locate: (onFound?: () => void) => void; locateStatus: LocateStatus };
|
||||
|
||||
const RegionContext = createContext<RegionApi | null>(null);
|
||||
|
||||
export function useRegion() {
|
||||
const ctx = use(RegionContext);
|
||||
if (!ctx) throw new Error('useRegion must be used inside RegionProvider');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/** 위치를 못 잡으면(실내·에뮬레이터) 끝없이 기다리지 않게 웹처럼 10초에 끊는다 */
|
||||
function withTimeout<T>(p: Promise<T>, ms: number): Promise<T> {
|
||||
return Promise.race([p, new Promise<never>((_, reject) => setTimeout(() => reject(new Error('위치 찾기 시간 초과')), ms))]);
|
||||
}
|
||||
|
||||
/** 위치 권한을 받아 가장 가까운 구. 권한이 없으면 'denied' */
|
||||
async function findNearest(): Promise<RegionData | 'denied'> {
|
||||
const { status } = await Location.requestForegroundPermissionsAsync();
|
||||
if (status !== 'granted') return 'denied';
|
||||
const pos = (await Location.getLastKnownPositionAsync({ maxAge: 600000 })) ?? (await withTimeout(Location.getCurrentPositionAsync({ accuracy: Location.Accuracy.Balanced }), 10000));
|
||||
const { data } = await nearestRegion({ query: { lat: pos.coords.latitude, lon: pos.coords.longitude } });
|
||||
if (!data.region) throw new Error('가까운 구를 찾지 못함');
|
||||
return data.region;
|
||||
}
|
||||
|
||||
export function RegionProvider({ children }: { children: ReactNode }) {
|
||||
const [stored] = useState(readStored);
|
||||
const [region, setRegionState] = useState<RegionData>(stored ?? DEFAULT_REGION);
|
||||
// 처음 켠 사람은 위치로 가장 가까운 구를 찾는 동안 지역 칩을 스켈레톤으로
|
||||
const [locateStatus, setLocateStatus] = useState<LocateStatus>(stored ? 'idle' : 'locating');
|
||||
|
||||
const setRegion = useCallback((r: RegionData) => {
|
||||
setRegionState(r);
|
||||
try {
|
||||
SecureStore.setItem(KEY, JSON.stringify(r));
|
||||
} catch (e) {
|
||||
console.warn('지역을 저장하지 못함', e);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const locate = useCallback(
|
||||
(onFound?: () => void) => {
|
||||
setLocateStatus('locating');
|
||||
findNearest()
|
||||
.then((r) => {
|
||||
if (r === 'denied') return setLocateStatus('denied');
|
||||
setLocateStatus('idle');
|
||||
setRegion(r);
|
||||
onFound?.();
|
||||
})
|
||||
.catch((e: unknown) => {
|
||||
console.warn('위치로 지역을 찾지 못함', e);
|
||||
setLocateStatus('error');
|
||||
});
|
||||
},
|
||||
[setRegion],
|
||||
);
|
||||
|
||||
// 처음 켠 사람만 위치 권한을 물어 가장 가까운 구로 맞춘다. 못 찾으면 조용히 기본 구
|
||||
useEffect(() => {
|
||||
if (stored) return;
|
||||
findNearest()
|
||||
.then((r) => r !== 'denied' && setRegion(r))
|
||||
.catch((e: unknown) => console.warn('첫 위치로 지역을 찾지 못함', e))
|
||||
.finally(() => setLocateStatus('idle'));
|
||||
}, [stored, setRegion]);
|
||||
|
||||
const api = useMemo(() => ({ region, setRegion, locate, locateStatus }), [region, setRegion, locate, locateStatus]);
|
||||
return <RegionContext value={api}>{children}</RegionContext>;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import * as Sharing from 'expo-sharing';
|
||||
import type { RefObject } from 'react';
|
||||
import { Share, type View } from 'react-native';
|
||||
import { captureRef } from 'react-native-view-shot';
|
||||
|
||||
/** 보이는 화면 조각을 PNG로 찍어 공유. 이미지 공유가 안 되는 곳(웹 등)이면 글로 보낸다 */
|
||||
export async function shareView(ref: RefObject<View | null>, { title, message }: { title: string; message: string }) {
|
||||
try {
|
||||
if (ref.current && (await Sharing.isAvailableAsync())) {
|
||||
const uri = await captureRef(ref, { format: 'png', quality: 1, result: 'tmpfile' });
|
||||
await Sharing.shareAsync(uri, { mimeType: 'image/png', UTI: 'public.png', dialogTitle: title });
|
||||
return;
|
||||
}
|
||||
await Share.share({ message });
|
||||
} catch (e) {
|
||||
console.warn('공유 실패', e);
|
||||
}
|
||||
}
|
||||
@@ -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<SheetState, null>) => void; close: () => void };
|
||||
|
||||
export const SheetContext = createContext<SheetApi | null>(null);
|
||||
|
||||
export function useSheet() {
|
||||
const ctx = use(SheetContext);
|
||||
if (!ctx) throw new Error('useSheet must be used inside SheetProvider');
|
||||
return ctx;
|
||||
}
|
||||
@@ -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);
|
||||
@@ -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<SkyApi | null>(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<TimeKind | null>(null);
|
||||
const [serverKind, setServerKind] = useState<TimeKind | null>(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 <SkyContext value={api}>{children}</SkyContext>;
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// NOTE: This file is generated by uniwind and it should not be edited manually.
|
||||
/// <reference types="uniwind/types" />
|
||||
|
||||
declare module 'uniwind' {
|
||||
export interface UniwindConfig {
|
||||
themes: readonly ['light', 'dark']
|
||||
}
|
||||
}
|
||||
|
||||
export {}
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
Generated
+104
@@ -39,6 +39,7 @@
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@expo-google-fonts/bagel-fat-one": "^0.4.0",
|
||||
"@expo-google-fonts/gowun-batang": "^0.4.1",
|
||||
"@expo-google-fonts/jua": "^0.4.1",
|
||||
"@expo/ui": "~57.0.23",
|
||||
"@nalssigak/shared": "*",
|
||||
@@ -51,8 +52,10 @@
|
||||
"expo-image": "~57.0.5",
|
||||
"expo-linear-gradient": "~57.0.2",
|
||||
"expo-linking": "~57.0.12",
|
||||
"expo-location": "~57.0.21",
|
||||
"expo-router": "~57.0.26",
|
||||
"expo-secure-store": "~57.0.4",
|
||||
"expo-sharing": "~57.0.23",
|
||||
"expo-splash-screen": "~57.0.10",
|
||||
"expo-status-bar": "~57.0.1",
|
||||
"expo-symbols": "~57.0.3",
|
||||
@@ -66,6 +69,7 @@
|
||||
"react-native-safe-area-context": "~5.7.0",
|
||||
"react-native-screens": "~4.26.0",
|
||||
"react-native-svg": "15.15.4",
|
||||
"react-native-view-shot": "5.1.0",
|
||||
"react-native-web": "~0.21.0",
|
||||
"react-native-worklets": "0.10.1",
|
||||
"tailwindcss": "^4.3.3",
|
||||
@@ -1463,6 +1467,12 @@
|
||||
"integrity": "sha512-f7JwE9QxBqReG9CnHzNcpM7mDVT1NErKKvbp06FTUSyDOd28Mu6PwIIfAa7JDLFwuj0r4C1uk9ui4SS+Mzj1aQ==",
|
||||
"license": "MIT AND OFL-1.1"
|
||||
},
|
||||
"node_modules/@expo-google-fonts/gowun-batang": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@expo-google-fonts/gowun-batang/-/gowun-batang-0.4.1.tgz",
|
||||
"integrity": "sha512-d0bdZaGH7Nu3sCW1c5fbtZDufA5RpE+Ph+Laa9xi9QlvHylMKS1lohZ7elhkJSy1hmJket4JeokzS4DzjGfpYg==",
|
||||
"license": "MIT AND OFL-1.1"
|
||||
},
|
||||
"node_modules/@expo-google-fonts/jua": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@expo-google-fonts/jua/-/jua-0.4.1.tgz",
|
||||
@@ -5486,6 +5496,15 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/base64-arraybuffer": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz",
|
||||
"integrity": "sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
@@ -6151,6 +6170,15 @@
|
||||
"hyphenate-style-name": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/css-line-break": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.1.0.tgz",
|
||||
"integrity": "sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"utrie": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/css-select": {
|
||||
"version": "5.2.2",
|
||||
"resolved": "https://registry.npmjs.org/css-select/-/css-select-5.2.2.tgz",
|
||||
@@ -7550,6 +7578,18 @@
|
||||
"react-native": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/expo-location": {
|
||||
"version": "57.0.21",
|
||||
"resolved": "https://registry.npmjs.org/expo-location/-/expo-location-57.0.21.tgz",
|
||||
"integrity": "sha512-up1e2Dqo4vzhyqzVB9ssRoP3p+VlIU6wJBHqipBenCijJYwnxAJjYv4nlBN0jRGk+4CixufCIkE9y2ZLH6594g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@expo/image-utils": "^0.11.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"expo": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/expo-modules-autolinking": {
|
||||
"version": "57.0.15",
|
||||
"resolved": "https://registry.npmjs.org/expo-modules-autolinking/-/expo-modules-autolinking-57.0.15.tgz",
|
||||
@@ -7694,6 +7734,22 @@
|
||||
"node": ">=20.16.0"
|
||||
}
|
||||
},
|
||||
"node_modules/expo-sharing": {
|
||||
"version": "57.0.23",
|
||||
"resolved": "https://registry.npmjs.org/expo-sharing/-/expo-sharing-57.0.23.tgz",
|
||||
"integrity": "sha512-fN+jrqoWwOpIo+X4utiu/ayCWym23DMgvrTJUHoopkBeO6rEa79ZY4f6ApOlRxvEx2NgQgJEQX+cbPJrjOSRog==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@expo/config-plugins": "^57.0.10",
|
||||
"@expo/config-types": "^57.0.2",
|
||||
"@expo/plist": "^0.8.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"expo": "*",
|
||||
"react": "*",
|
||||
"react-native": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/expo-splash-screen": {
|
||||
"version": "57.0.10",
|
||||
"resolved": "https://registry.npmjs.org/expo-splash-screen/-/expo-splash-screen-57.0.10.tgz",
|
||||
@@ -8488,6 +8544,19 @@
|
||||
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/html2canvas": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.4.1.tgz",
|
||||
"integrity": "sha512-fPU6BHNpsyIhr8yyMpTLLxAbkaK8ArIBcmZIRiBLiDhjeqvXolaEmDGmELFuX9I4xDcaKKcJl+TKZLqruBbmWA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"css-line-break": "^2.1.0",
|
||||
"text-segmentation": "^1.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/http-errors": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
|
||||
@@ -11925,6 +11994,23 @@
|
||||
"react-native": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/react-native-view-shot": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/react-native-view-shot/-/react-native-view-shot-5.1.0.tgz",
|
||||
"integrity": "sha512-JZgElCD82aO+hejIF/leUzI7JufL9mgJ6ChzGWIcdZ2ajpaEvvSnvIcw0qD32XWkrbId8wfSbyz/4u/ulTQzQA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"html2canvas": "^1.4.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20",
|
||||
"npm": ">=10"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.0.0",
|
||||
"react-native": ">=0.76.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-native-web": {
|
||||
"version": "0.21.4",
|
||||
"resolved": "https://registry.npmjs.org/react-native-web/-/react-native-web-0.21.4.tgz",
|
||||
@@ -13223,6 +13309,15 @@
|
||||
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/text-segmentation": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.3.tgz",
|
||||
"integrity": "sha512-iOiPUo/BGnZ6+54OsWxZidGCsdU8YbE4PSpdPinp7DeMtUJNJBoJ/ouUSTJjHkh1KntHaltHl/gDs2FC4i5+Nw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"utrie": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/throat": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/throat/-/throat-5.0.0.tgz",
|
||||
@@ -13953,6 +14048,15 @@
|
||||
"node": ">= 0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/utrie": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/utrie/-/utrie-1.0.2.tgz",
|
||||
"integrity": "sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"base64-arraybuffer": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/uuid": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-7.0.3.tgz",
|
||||
|
||||
Reference in new issue
Block a user