From c15f045c64de8787274157ab31c495e298ad66fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=84=B1=EA=B2=BD?= Date: Wed, 4 Nov 2026 17:35:23 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=95=B1=20=EB=8F=99=EB=84=A4=20?= =?UTF-8?q?=EC=9D=B4=EC=95=BC=EA=B8=B0=20=E2=80=94=20/talk=20=EC=A3=BC?= =?UTF-8?q?=EC=A0=9C=EB=B3=84=20=EA=B8=80=C2=B7=EB=82=B4=20=EA=B8=80,=20?= =?UTF-8?q?=EC=98=A4=EB=8A=98=20=ED=94=BC=EB=93=9C=20=EC=93=B0=EA=B8=B0=20?= =?UTF-8?q?=EC=B9=B8=EA=B3=BC=20=ED=8F=AC=EC=8A=A4=ED=8A=B8=20=EB=91=90=20?= =?UTF-8?q?=EC=9E=A5=EB=A7=88=EB=8B=A4=20=EC=82=AC=EB=9E=8C=20=EA=B8=80,?= =?UTF-8?q?=20=EC=82=AC=EC=A7=84=20=EC=98=AC=EB=A6=AC=EA=B8=B0(expo-image-?= =?UTF-8?q?picker,=20=EC=B9=B4=EB=A9=94=EB=9D=BC=C2=B7=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=ED=81=AC=20=EA=B6=8C=ED=95=9C=20=EC=97=86=EC=9D=8C),=20?= =?UTF-8?q?=EC=9D=B4=EC=95=BC=EA=B8=B0=20=EB=8C=93=EA=B8=80=C2=B7=EC=A2=8B?= =?UTF-8?q?=EC=95=84=EC=9A=94=C2=B7=EC=8B=A0=EA=B3=A0=C2=B7=EC=95=88=20?= =?UTF-8?q?=EB=B3=B4=EA=B8=B0=C2=B7=EC=A7=80=EC=9A=B0=EA=B8=B0,=20?= =?UTF-8?q?=EB=82=B4=20=EC=A0=95=EB=B3=B4=20=EB=82=B4=20=EA=B8=80.=20?= =?UTF-8?q?=EA=B8=B0=EB=85=90=EC=9D=BC=20=EB=AA=A9=EB=A1=9D=EC=9D=84=20sha?= =?UTF-8?q?red=EB=A1=9C=20(GA=20talk=5Fpost=C2=B7talk=5Fcomment=C2=B7feed?= =?UTF-8?q?=5Fitem=5Fview,=20like=C2=B7report=C2=B7block=20talk)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- docs/이벤트_추적.md | 2 +- frontend/src/b/holiday.ts | 105 +----- mobile/app.json | 10 +- mobile/package.json | 1 + mobile/src/app/(tabs)/index.tsx | 94 ++++- mobile/src/app/talk.tsx | 71 ++++ mobile/src/components/post/icons.tsx | 11 +- mobile/src/components/screen-header.tsx | 31 ++ mobile/src/components/sheets/comments.tsx | 86 +++-- mobile/src/components/sheets/index.tsx | 2 +- mobile/src/components/sheets/me.tsx | 2 + mobile/src/components/talk/talk.tsx | 426 ++++++++++++++++++++++ mobile/src/lib/sheet.ts | 4 +- mobile/src/lib/talk.ts | 75 ++++ package-lock.json | 215 +++-------- shared/lib/holiday.ts | 106 ++++++ 16 files changed, 941 insertions(+), 300 deletions(-) create mode 100644 mobile/src/app/talk.tsx create mode 100644 mobile/src/components/screen-header.tsx create mode 100644 mobile/src/components/talk/talk.tsx create mode 100644 mobile/src/lib/talk.ts create mode 100644 shared/lib/holiday.ts diff --git a/docs/이벤트_추적.md b/docs/이벤트_추적.md index 141b4c0..f3b2bc1 100644 --- a/docs/이벤트_추적.md +++ b/docs/이벤트_추적.md @@ -78,7 +78,7 @@ GA4 태그(`gtag.js`, 측정 ID `G-D378J4X373`)를 `index.html`에 심고, 화 - 앱도 같은 이벤트 이름·값으로 `track()`을 부른다 (`mobile/src/lib/analytics.ts`). 모든 이벤트에 `platform: 'app'`이 붙는다. - **아직 GA4로 보내지 않는다 (2026-11-04).** Firebase Analytics(`google-services.json`)를 붙이면 앱 시작 때 `setAnalyticsSender`로 보내는 함수를 단다. 그 전까지 `track()`은 아무것도 보내지 않는다. 개발 빌드(`__DEV__`)는 붙인 뒤에도 보내지 않는다. -- 앱에서 부르는 곳: `sheet_open`(`components/sheets/index.tsx`), `view_gak`(`sheets/gak.tsx`), `select_content`(`sheets/article.tsx`), `login`·`sign_up`(`sheets/login.tsx`, 구글만), `region_change`(`sheets/region.tsx`·`lib/region.tsx`), `like`(`post/post-card.tsx` 글, `sheets/comments.tsx` 댓글), `comment`·`report`·`block`·`terms_agree`(`sheets/comments.tsx`), `share`(`lib/share-image.ts`), `hero_day_switch`(`today/hero.tsx`), `like`의 `hero_post`·`gak_post`(`lib/pinned-like.ts`). 레벨 창·레벨업 창은 `sheet_open`(`level`·`levelUp`)으로 잡힌다. +- 앱에서 부르는 곳: `sheet_open`(`components/sheets/index.tsx`), `view_gak`(`sheets/gak.tsx`), `select_content`(`sheets/article.tsx`), `login`·`sign_up`(`sheets/login.tsx`, 구글만), `region_change`(`sheets/region.tsx`·`lib/region.tsx`), `like`(`post/post-card.tsx` 글, `sheets/comments.tsx` 댓글), `comment`·`report`·`block`·`terms_agree`(`sheets/comments.tsx`), `share`(`lib/share-image.ts`), `hero_day_switch`(`today/hero.tsx`), `like`의 `hero_post`·`gak_post`(`lib/pinned-like.ts`). 레벨 창·레벨업 창은 `sheet_open`(`level`·`levelUp`)으로 잡힌다. 동네 이야기: `talk_post`(`components/talk/talk.tsx` `Composer`), `like`·`report`·`block`의 `talk`(`talk/talk.tsx`), `talk_comment`(`sheets/comments.tsx`), `feed_item_view`(`app/(tabs)/index.tsx` `useSeen`, 화면에 반쯤 보일 때). - 앱 `share`의 `ratio`는 `'card'` — 보이는 카드를 그대로 찍어 보내 비율을 고르지 않는다. ## GA4 설정 diff --git a/frontend/src/b/holiday.ts b/frontend/src/b/holiday.ts index b876b4f..bd11f04 100644 --- a/frontend/src/b/holiday.ts +++ b/frontend/src/b/holiday.ts @@ -1,100 +1,7 @@ -import { TalkTopic } from '@nalssigak/shared/api/client/types.gen' -import { kst } from '@nalssigak/shared/lib' +import { HOLIDAYS, holidayOn, type Holiday } from '@nalssigak/shared/lib/holiday' -/** 게임 8단계 그림을 바꾼다. 작은 것부터 큰 것 순서, 크기·색은 원래 단계 그대로 */ -type GamePiece = { icon: string; name: string } - -/** - * 기념일 꾸밈. 기간(KST, 양 끝 포함) 안에만 켜진다. 'MM-DD' 는 해마다, 'YYYY-MM-DD' 는 그해만(음력 기념일). - * 새 기념일: 여기에 한 줄 + TalkTopic(backend/common/enums.py) + 게임 그림(public/b/icons, lib.ts OWN) + 소품 그림(public/b/holiday, 투명 배경, b.css) - */ -export type Holiday = { - key: 'halloween' | 'pepero' | 'christmas' | 'chuseok' - name: string - ranges: readonly (readonly [string, string])[] - topic: TalkTopic - /** 글만 있는 사람 글 배경 (b.css b-bg-*) */ - bg: string - game: readonly GamePiece[] -} - -export const HOLIDAYS: readonly Holiday[] = [ - { - key: 'halloween', - name: '할로윈', - ranges: [['10-30', '11-01']], - topic: TalkTopic.HALLOWEEN, - bg: 'night', - game: [ - { icon: 'candy', name: '사탕' }, - { icon: 'lollipop', name: '막대사탕' }, - { icon: 'spider', name: '거미' }, - { icon: 'spider_web', name: '거미줄' }, - { icon: 'bat', name: '박쥐' }, - { icon: 'ghost', name: '유령' }, - { icon: 'skull', name: '해골' }, - { icon: 'jack_o_lantern', name: '호박등' }, - ], - }, - { - key: 'pepero', - name: '빼빼로데이', - ranges: [['11-11', '11-11']], - topic: TalkTopic.PEPERO, - bg: 'peach', - game: [ - { icon: 'pepero_choco', name: '초코' }, - { icon: 'pepero_almond', name: '아몬드' }, - { icon: 'pepero_strawberry', name: '딸기' }, - { icon: 'pepero_nude', name: '누드' }, - { icon: 'pepero_pair', name: '한 쌍' }, - { icon: 'pepero_bundle', name: '다발' }, - { icon: 'pepero_box', name: '한 상자' }, - { icon: 'pepero_basket', name: '바구니' }, - ], - }, - { - key: 'christmas', - name: '크리스마스', - ranges: [['12-24', '12-25']], - topic: TalkTopic.CHRISTMAS, - bg: 'mint', - game: [ - { icon: 'xmas_candy_cane', name: '캔디케인' }, - { icon: 'xmas_ornament', name: '장식볼' }, - { icon: 'xmas_gingerbread', name: '진저쿠키' }, - { icon: 'xmas_santa_hat', name: '산타 모자' }, - { icon: 'xmas_stocking', name: '양말' }, - { icon: 'xmas_wreath', name: '리스' }, - { icon: 'xmas_santa', name: '산타' }, - { icon: 'christmas_tree', name: '트리' }, - ], - }, - { - key: 'chuseok', - name: '추석', - ranges: [['2027-09-14', '2027-09-16']], - topic: TalkTopic.CHUSEOK, - bg: 'butter', - game: [ - { icon: 'chestnut', name: '밤' }, - { icon: 'pear', name: '배' }, - { icon: 'apple', name: '사과' }, - { icon: 'dango', name: '떡' }, - { icon: 'rabbit', name: '토끼' }, - { icon: 'maple', name: '단풍' }, - { icon: 'moon_viewing', name: '달맞이' }, - { icon: 'full_moon', name: '보름달' }, - ], - }, -] - -const pad = (n: number) => String(n).padStart(2, '0') - -function inRange([from, to]: readonly [string, string], y: number, md: string) { - const day = from.length === 10 ? `${y}-${md}` : md - return from <= day && day <= to -} +// 기념일 목록·기간은 앱과 같이 쓴다 (shared/lib/holiday.ts) +export { HOLIDAYS, holidayByTopic, type Holiday } from '@nalssigak/shared/lib/holiday' /** 미리 보기 기념일: 주소의 ?holiday= 를 탭이 닫힐 때까지 기억 */ function previewKey() { @@ -107,9 +14,5 @@ function previewKey() { export function currentHoliday(now = new Date()): Holiday | undefined { const preview = previewKey() if (preview) return HOLIDAYS.find((h) => h.key === preview) - const { y, mo, d } = kst(now) - const md = `${pad(mo)}-${pad(d)}` - return HOLIDAYS.find((h) => h.ranges.some((r) => inRange(r, y, md))) + return holidayOn(now) } - -export const holidayByTopic = (t?: number) => HOLIDAYS.find((h) => h.topic === t) diff --git a/mobile/app.json b/mobile/app.json index c3567df..6d9e452 100644 --- a/mobile/app.json +++ b/mobile/app.json @@ -55,7 +55,15 @@ "locationWhenInUsePermission": "가장 가까운 동네 날씨를 보여 드리려고 위치를 써요." } ], - "@react-native-google-signin/google-signin" + "@react-native-google-signin/google-signin", + [ + "expo-image-picker", + { + "photosPermission": "동네 이야기에 사진을 붙이려고 사진 앨범을 써요.", + "cameraPermission": false, + "microphonePermission": false + } + ] ], "experiments": { "typedRoutes": true, diff --git a/mobile/package.json b/mobile/package.json index 9d86f31..9e34aa5 100644 --- a/mobile/package.json +++ b/mobile/package.json @@ -16,6 +16,7 @@ "expo-font": "~57.0.4", "expo-glass-effect": "~57.0.4", "expo-image": "~57.0.5", + "expo-image-picker": "~57.0.20", "expo-linear-gradient": "~57.0.2", "expo-linking": "~57.0.12", "expo-location": "~57.0.21", diff --git a/mobile/src/app/(tabs)/index.tsx b/mobile/src/app/(tabs)/index.tsx index c4e02d6..5b90df7 100644 --- a/mobile/src/app/(tabs)/index.tsx +++ b/mobile/src/app/(tabs)/index.tsx @@ -1,17 +1,53 @@ import { getFeedOptions, getWeatherTodayOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'; +import { PostType } from '@nalssigak/shared/api/client/types.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 { Fragment, useRef, type ReactNode } from 'react'; +import { RefreshControl, ScrollView, View, type LayoutRectangle } from 'react-native'; import { isAppPost, PostCard, PostCardSkel } from '@/components/post/post-card'; +import { Composer, TalkPost } from '@/components/talk/talk'; import { GakCard } from '@/components/today/gak-card'; import { Hero } from '@/components/today/hero'; import { SeasonBand } from '@/components/today/rails'; import { StateBox } from '@/components/ui'; +import { track } from '@/lib/analytics'; import { useRegion } from '@/lib/region'; import { useSky } from '@/lib/sky'; +import { useTopicTalks } from '@/lib/talk'; + +// 사람 글은 포스트 두 장마다 한 장씩 최신순으로 끼운다 +const TALK_EVERY = 2; + +type Spot = { item: 'talk' | 'event'; position: number; y: number; h: number }; + +/** 피드에 섞인 사람 글·행사 포스트가 처음 반쯤 보일 때 한 번 GA 로 보낸다 (웹 Seen) */ +function useSeen() { + const spots = useRef(new Map()); + const sent = useRef(new Set()); + const view = useRef({ y: 0, h: 0 }); + const check = () => { + const { y, h } = view.current; + if (!h) return; + for (const [key, s] of spots.current) { + if (sent.current.has(key) || !s.h) continue; + const shown = Math.min(y + h, s.y + s.h) - Math.max(y, s.y); + if (shown < s.h / 2) continue; + sent.current.add(key); + track('feed_item_view', { item_type: s.item, position: s.position }); + } + }; + const at = (item: Spot['item'], position: number) => (l: LayoutRectangle) => { + spots.current.set(`${item}:${position}`, { item, position, y: l.y, h: l.height }); + check(); + }; + const onScroll = (y: number, h: number) => { + view.current = { y, h }; + check(); + }; + return { at, onScroll }; +} export default function TodayScreen() { const { region } = useRegion(); @@ -25,15 +61,31 @@ export default function TodayScreen() { const bands = f?.bands; const nowAt = f?.hero?.now_at; const load = loadOf(feed); - const refresh = () => Promise.all([feed.refetch(), today.refetch()]); + const talkList = useTopicTalks(); + const talks = talkList.talks; + const talkAt = (i: number) => ((i + 1) % TALK_EVERY === 0 ? talks[(i + 1) / TALK_EVERY - 1] : undefined); + const talkFrom = Math.floor(posts.length / TALK_EVERY); + const eventNo = new Map(posts.filter((p) => p.post_type === PostType.EVENT).map((p, n) => [p.post_id, n + 1])); + const seen = useSeen(); + const refresh = () => Promise.all([feed.refetch(), today.refetch(), talkList.refetch()]); // 웹처럼 9번째 글 뒤에 계절 이야기 띠를 넣고, 글이 모자라면 맨 뒤에 붙인다 const bandAt: [number, ReactNode][] = [[9, bands?.season?.length ? : null]]; return ( // 지역마다 새로 그려 넘긴 슬라이드 위치가 남지 않게 한다 - } style={{ opacity: feed.isPlaceholderData ? 0.6 : 1 }}> + } + style={{ opacity: feed.isPlaceholderData ? 0.6 : 1 }} + keyboardShouldPersistTaps="handled" + scrollEventThrottle={200} + onLayout={(e) => seen.onScroll(0, e.nativeEvent.layout.height)} + onScroll={(e) => seen.onScroll(e.nativeEvent.contentOffset.y, e.nativeEvent.layoutMeasurement.height)} + > + {/* 실패 안내는 여기 한 번만, 각 카드 스켈레톤과 같은 크기로 */} {stories.some((g) => g.active) ? ( @@ -62,12 +114,34 @@ export default function TodayScreen() { boxClassName="inset-x-3 top-3.5" /> )} - {posts.map((p, i) => ( - - - {bandAt.find(([at]) => at === i + 1)?.[1]} - - ))} + {posts.map((p, i) => { + const t = talkAt(i); + const ev = eventNo.get(p.post_id); + return ( + + {ev ? ( + seen.at('event', ev)(e.nativeEvent.layout)}> + + + ) : ( + + )} + {bandAt.find(([at]) => at === i + 1)?.[1]} + {t && ( + seen.at('talk', (i + 1) / TALK_EVERY)(e.nativeEvent.layout)}> + + + )} + + ); + })} + {/* 포스트가 모자라 끼울 자리가 없던 사람 글은 맨 뒤에 */} + {feed.isSuccess && + talks.slice(talkFrom).map((t, n) => ( + seen.at('talk', talkFrom + n + 1)(e.nativeEvent.layout)}> + + + ))} {feed.isSuccess && bandAt.filter(([at]) => at > posts.length).map(([at, node]) => {node})} ); diff --git a/mobile/src/app/talk.tsx b/mobile/src/app/talk.tsx new file mode 100644 index 0000000..a53a2dd --- /dev/null +++ b/mobile/src/app/talk.tsx @@ -0,0 +1,71 @@ +import type { TalkTopic } from '@nalssigak/shared/api/client/types.gen'; +import { router, useLocalSearchParams } from 'expo-router'; +import { FlatList, Pressable, RefreshControl, ScrollView, View } from 'react-native'; + +import { ScreenHeader } from '@/components/screen-header'; +import { Composer, TalkCard } from '@/components/talk/talk'; +import { Text } from '@/components/text'; +import { Sec } from '@/components/ui'; +import { useAuth } from '@/lib/auth'; +import { useSheet } from '@/lib/sheet'; +import { openTopics, TOPICS, useMyTalks, useTopicTalks } from '@/lib/talk'; + +type Tab = TalkTopic | 'all' | 'mine'; + +/** 주제별 사람 글: 위 주제 탭(한 줄 가로로 밀기, 끝에 '내 글'), 아래 글 목록. ?topic= · ?mine=1 로 연다 (웹 TalkPage) */ +export default function TalkScreen() { + const params = useLocalSearchParams<{ topic?: string; mine?: string }>(); + const { loggedIn } = useAuth(); + const { open } = useSheet(); + const raw = Number(params.topic); + const tab: Tab = params.mine ? 'mine' : TOPICS.some(([k]) => k === raw) ? (raw as TalkTopic) : 'all'; + const topicList = useTopicTalks(tab === 'all' || tab === 'mine' ? undefined : tab); + const mineList = useMyTalks(tab === 'mine' && loggedIn); + const { talks, loaded, more, loadMore } = tab === 'mine' ? mineList : topicList; + const tabs: (readonly [Tab, string])[] = [['all', '전체'], ...openTopics(), ['mine', '내 글']]; + const go = (k: Tab) => router.setParams(k === 'mine' ? { mine: '1', topic: undefined } : k === 'all' ? { mine: undefined, topic: undefined } : { mine: undefined, topic: String(k) }); + + const head = ( + + + + + {tabs.map(([k, label]) => ( + go(k)} accessibilityRole="tab" accessibilityState={{ selected: tab === k }} className={`rounded-full px-3 py-1.5 ${tab === k ? 'bg-ink-btn' : 'bg-card'}`}> + {label} + + ))} + + + + {tab === 'mine' && !loggedIn ? ( + + 로그인하면 내가 쓴 글을 모아 볼 수 있어요.{' '} + open({ type: 'login' })} className="font-extrabold text-orange"> + 로그인 + + + ) : ( + loaded && !talks.length && {tab === 'mine' ? '아직 쓴 글이 없어요. 위 칸에서 첫 글을 써 주세요.' : '아직 이 주제 글이 없어요. 위 칸에서 첫 글을 써 주세요.'} + )} + + ); + + return ( + + + `${t.talk_id}:${t.liked}:${t.like_count}`} + renderItem={({ item }) => } + ListHeaderComponent={head} + contentContainerClassName="pb-8" + keyboardShouldPersistTaps="handled" + // 목록 끝이 가까워지면 다음 쪽을 받는다 (글이 많아도 버튼 없이 이어서) + onEndReached={() => more && loadMore()} + onEndReachedThreshold={1} + refreshControl={tab !== 'mine' ? topicList.refetch()} /> : undefined} + /> + + ); +} diff --git a/mobile/src/components/post/icons.tsx b/mobile/src/components/post/icons.tsx index e651879..dacc6d1 100644 --- a/mobile/src/components/post/icons.tsx +++ b/mobile/src/components/post/icons.tsx @@ -1,4 +1,4 @@ -import Svg, { Path } from 'react-native-svg'; +import Svg, { Circle, 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'; @@ -27,3 +27,12 @@ export function SendIcon({ size, color }: P) { ); } + +export function CameraIcon({ size, color }: P) { + return ( + + + + + ); +} diff --git a/mobile/src/components/screen-header.tsx b/mobile/src/components/screen-header.tsx new file mode 100644 index 0000000..1f55e7e --- /dev/null +++ b/mobile/src/components/screen-header.tsx @@ -0,0 +1,31 @@ +import { router } from 'expo-router'; +import { Pressable, View } from 'react-native'; +import { useSafeAreaInsets } from 'react-native-safe-area-context'; +import Svg, { Path } from 'react-native-svg'; +import { useCSSVariable } from 'uniwind'; + +import { Text } from '@/components/text'; +import { useSky } from '@/lib/sky'; + +/** 탭 밖 화면(사주·이야기·게임 등) 머리줄: 뒤로 가기와 제목. 뒤로 갈 곳이 없으면(링크로 바로 열림) 오늘 탭으로 */ +export function ScreenHeader({ title, right }: { title: string; right?: React.ReactNode }) { + const { top } = useSafeAreaInsets(); + const { kind } = useSky(); + const ink = String(useCSSVariable('--color-ink')); + const back = () => (router.canGoBack() ? router.back() : router.replace('/')); + return ( + + + + + + + + + {title} + + {right} + + + ); +} diff --git a/mobile/src/components/sheets/comments.tsx b/mobile/src/components/sheets/comments.tsx index 551f01c..f7c44b3 100644 --- a/mobile/src/components/sheets/comments.tsx +++ b/mobile/src/components/sheets/comments.tsx @@ -1,5 +1,6 @@ import { addCommentMutation, + addTalkCommentMutation, agreeTermsMutation, blockAuthorMutation, deleteCommentMutation, @@ -8,6 +9,8 @@ import { listBlockedQueryKey, listCommentsInfiniteOptions, listCommentsInfiniteQueryKey, + listTalkCommentsInfiniteOptions, + listTalkCommentsInfiniteQueryKey, meQueryKey, reportCommentMutation, unlikeCommentMutation, @@ -24,7 +27,7 @@ import { Avatar, Skel, StateBox } from '@/components/ui'; import { track } from '@/lib/analytics'; import { useAuth } from '@/lib/auth'; import { useRegion } from '@/lib/region'; -import { useSheet } from '@/lib/sheet'; +import { useSheet, type CommentTarget } from '@/lib/sheet'; import { SITE_URL } from '@/lib/site'; import { Body, ErrorLine, Field, HeartIcon, useSoft } from './parts'; @@ -38,7 +41,13 @@ const REPORT_REASONS = [ [ReportReason.PRIVACY, '개인정보 노출'], [ReportReason.OTHER, '기타'], ] as const; -export const isCommentList = (q: { queryKey: readonly unknown[] }) => (q.queryKey[0] as { _id?: string } | undefined)?._id === 'listComments'; +export const isCommentList = (q: { queryKey: readonly unknown[] }) => ['listComments', 'listTalkComments'].includes((q.queryKey[0] as { _id?: string } | undefined)?._id ?? ''); +const isTalkList = (q: { queryKey: readonly unknown[] }) => (q.queryKey[0] as { _id?: string } | undefined)?._id === 'listTalks'; + +/** 댓글 목록 캐시 키: 지우기·신고 뒤 다시 받을 때 쓴다 */ +function commentListKey(to: CommentTarget) { + return 'talkId' in to ? listTalkCommentsInfiniteQueryKey({ path: { talk_id: to.talkId } }) : listCommentsInfiniteQueryKey({ path: { post_id: to.postId } }); +} function Chip({ label, onPress, disabled, danger }: { label: string; onPress: () => void; disabled?: boolean; danger?: boolean }) { const s = useSoft(); @@ -50,7 +59,7 @@ function Chip({ label, onPress, disabled, danger }: { label: string; onPress: () } /** 남의 댓글: ⋯ → 신고하기(이유 고르기) / 이 사람 차단하기(한 번 더 묻기). 끝나면 목록을 다시 받아 그 댓글이 빠진다 */ -function CommentMenu({ c, postId, onNotice }: { c: CommentData; postId: number; onNotice: (text: string) => void }) { +function CommentMenu({ c, to, onNotice }: { c: CommentData; to: CommentTarget; onNotice: (text: string) => void }) { const { loggedIn } = useAuth(); const { open } = useSheet(); const queryClient = useQueryClient(); @@ -73,7 +82,7 @@ function CommentMenu({ c, postId, onNotice }: { c: CommentData; postId: number; }); const go = (next: typeof step) => { setFailed(false); - if (next !== 'closed' && !loggedIn) return open({ type: 'login', then: { type: 'comments', postId } }); + if (next !== 'closed' && !loggedIn) return open({ type: 'login', then: { type: 'comments', ...to } }); setStep(next); }; @@ -128,7 +137,7 @@ function CommentsSkel() { ); } -function CommentRow({ c, postId, onNotice }: { c: CommentData; postId: number; onNotice: (text: string) => void }) { +function CommentRow({ c, to, onNotice }: { c: CommentData; to: CommentTarget; onNotice: (text: string) => void }) { const { region } = useRegion(); const queryClient = useQueryClient(); const [heart, ink3] = useCSSVariable(['--color-heart', '--color-ink3']).map(String); @@ -163,7 +172,7 @@ function CommentRow({ c, postId, onNotice }: { c: CommentData; postId: number; o } revert(); // 그 사이 지워진 댓글이면 알림 없이 목록을 다시 받아 사라지게 한다 - if (res.result?.code === NOT_FOUND) queryClient.invalidateQueries({ queryKey: listCommentsInfiniteQueryKey({ path: { post_id: postId } }) }); + if (res.result?.code === NOT_FOUND) queryClient.invalidateQueries({ queryKey: commentListKey(to) }); else setLikeFailed(true); }, onError: () => { @@ -182,13 +191,14 @@ function CommentRow({ c, postId, onNotice }: { c: CommentData; postId: number; o { onSuccess: async (res) => { if (!res.result?.success) return setRemoveFailed(true); - const key = listCommentsInfiniteQueryKey({ path: { post_id: postId } }); + const key = commentListKey(to); await queryClient.cancelQueries({ queryKey: key }); queryClient.setQueryData>(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 } }) }); + if ('talkId' in to) queryClient.invalidateQueries({ predicate: isTalkList }); + else queryClient.invalidateQueries({ queryKey: getFeedQueryKey({ query: { region: region.code } }) }); }, onError: () => setRemoveFailed(true), }, @@ -221,7 +231,7 @@ function CommentRow({ c, postId, onNotice }: { c: CommentData; postId: number; o )} {/* 날씨각 캐릭터 댓글은 운영 문구라 신고·차단 메뉴가 없다 */} - {!c.mine && !c.official && } + {!c.mine && !c.official && } @@ -231,16 +241,31 @@ function CommentRow({ c, postId, onNotice }: { c: CommentData; postId: number; o ); } -export function CommentsSheet({ postId, draft }: { postId: number; draft?: string }) { +/** 포스트 댓글, 또는 사람 글 댓글(로그인한 사람만 쓴다) */ +export function CommentsSheet({ to, draft }: { to: CommentTarget; draft?: string }) { const { region } = useRegion(); const { me } = useAuth(); + const { open } = useSheet(); const queryClient = useQueryClient(); - const list = useInfiniteQuery({ - ...listCommentsInfiniteOptions({ path: { post_id: postId } }), - initialPageParam: { path: { post_id: postId } }, + const talkId = 'talkId' in to ? to.talkId : undefined; + const postId = 'postId' in to ? to.postId : undefined; + // 둘 중 하나만 받는다 + const postList = useInfiniteQuery({ + ...listCommentsInfiniteOptions({ path: { post_id: postId ?? 0 } }), + initialPageParam: { path: { post_id: postId ?? 0 } }, getNextPageParam: (last) => last.next_cursor ?? undefined, + enabled: postId != null, }); - const add = useMutation(addCommentMutation()); + const talkList = useInfiniteQuery({ + ...listTalkCommentsInfiniteOptions({ path: { talk_id: talkId ?? 0 } }), + initialPageParam: { path: { talk_id: talkId ?? 0 } }, + getNextPageParam: (last) => last.next_cursor ?? undefined, + enabled: talkId != null, + }); + const list = talkId != null ? talkList : postList; + const addPost = useMutation(addCommentMutation()); + const addTalk = useMutation(addTalkCommentMutation()); + const add = { isPending: addPost.isPending || addTalk.isPending }; const agree = useMutation(agreeTermsMutation()); const s = useSoft(); const [addFailed, setAddFailed] = useState(false); @@ -260,25 +285,30 @@ export function CommentsSheet({ postId, draft }: { postId: number; draft?: strin const body = text.trim(); if (!body || add.isPending) return; setAddFailed(false); - add.mutate( - { path: { post_id: postId }, body: { body, region: region.code } }, - { - onSuccess: (res) => { - if (res.result?.desc === 'TERMS_REQUIRED') return setAskTerms(true); - setAddFailed(!res.result?.success); - if (!res.result?.success) return; + const handlers = { + onSuccess: (res: { result?: { success?: boolean; desc?: string } }) => { + if (res.result?.desc === 'TERMS_REQUIRED') return setAskTerms(true); + setAddFailed(!res.result?.success); + if (!res.result?.success) return; + setText(''); + queryClient.invalidateQueries({ queryKey: commentListKey(to) }); + if (talkId != null) { + track('talk_comment', { talk_id: talkId }); + queryClient.invalidateQueries({ predicate: isTalkList }); + } else if (postId != null) { track('comment', { post_id: postId }); - setText(''); - queryClient.invalidateQueries({ queryKey: listCommentsInfiniteQueryKey({ path: { post_id: postId } }) }); queryClient.invalidateQueries({ queryKey: getFeedQueryKey({ query: { region: region.code } }) }); - }, - onError: () => setAddFailed(true), + } }, - ); + onError: () => setAddFailed(true), + }; + if (talkId != null) addTalk.mutate({ path: { talk_id: talkId }, body: { body } }, handlers); + else if (postId != null) addPost.mutate({ path: { post_id: postId }, body: { body, region: region.code } }, handlers); }; // 댓글은 로그인 없이 '○○구 익명'으로 쓴다. 로그인했으면 약관에 동의해야 쓸 수 있고, 동의하면 쓰던 댓글을 바로 올린다 const submit = () => { + if (talkId != null && !me) return open({ type: 'login', then: { type: 'comments', ...to, draft: text } }); if (me && !me.terms_agreed) return setAskTerms(true); send(); }; @@ -306,7 +336,7 @@ export function CommentsSheet({ postId, draft }: { postId: number; draft?: strin <> {/* 다시 받은 좋아요 상태(로그인 바뀜 등)가 행에 반영되도록 key 에 넣는다 */} {comments.map((c) => ( - + ))} {list.hasNextPage && ( list.fetchNextPage()} disabled={list.isFetchingNextPage} className="my-2 disabled:opacity-50"> @@ -352,7 +382,7 @@ export function CommentsSheet({ postId, draft }: { postId: number; draft?: strin {addFailed ? : {notice}} - + {add.isPending ? '올리는 중…' : '게시'} diff --git a/mobile/src/components/sheets/index.tsx b/mobile/src/components/sheets/index.tsx index 450738d..3240f72 100644 --- a/mobile/src/components/sheets/index.tsx +++ b/mobile/src/components/sheets/index.tsx @@ -90,7 +90,7 @@ function SheetHost({ state: next, onClose }: { state: SheetState; onClose: () => {state.type === 'gak' && } {state.type === 'article' && } {state.type === 'seasonWeek' && } - {state.type === 'comments' && } + {state.type === 'comments' && } {state.type === 'login' && open(then) : onClose} why={state.why} />} {state.type === 'me' && } {state.type === 'region' && } diff --git a/mobile/src/components/sheets/me.tsx b/mobile/src/components/sheets/me.tsx index bdb6af4..db4e49b 100644 --- a/mobile/src/components/sheets/me.tsx +++ b/mobile/src/components/sheets/me.tsx @@ -8,6 +8,7 @@ import { Pressable, View } from 'react-native'; import { Text } from '@/components/text'; import { Avatar, Ic } from '@/components/ui'; +import { MyTalks } from '@/components/talk/talk'; import { useAuth } from '@/lib/auth'; import { isCommentList } from './comments'; @@ -202,6 +203,7 @@ export function MeSheet({ onDone }: { onDone: () => void }) { {saving ? (saving.nickname == null ? '저장 중…' : '') : error} + { logout(); diff --git a/mobile/src/components/talk/talk.tsx b/mobile/src/components/talk/talk.tsx new file mode 100644 index 0000000..b577601 --- /dev/null +++ b/mobile/src/components/talk/talk.tsx @@ -0,0 +1,426 @@ +import { addTalkMutation, blockTalkAuthorMutation, deleteTalkMutation, likeTalkMutation, reportTalkMutation, unlikeTalkMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'; +import { uploadTalkImage } from '@nalssigak/shared/api/client/sdk.gen'; +import { TalkReport, TalkTopic, type TalkData } from '@nalssigak/shared/api/client/types.gen'; +import { holidayByTopic } from '@nalssigak/shared/lib/holiday'; +import { useMutation } from '@tanstack/react-query'; +import { Image } from 'expo-image'; +import * as ImagePicker from 'expo-image-picker'; +import { LinearGradient } from 'expo-linear-gradient'; +import { useRef, useState } from 'react'; +import { Pressable, TextInput, View } from 'react-native'; +import { useCSSVariable } from 'uniwind'; + +import { CameraIcon, CommentIcon, HeartIcon, SendIcon } from '@/components/post/icons'; +import { useSoft } from '@/components/sheets/parts'; +import { Text } from '@/components/text'; +import { Avatar } from '@/components/ui'; +import { track } from '@/lib/analytics'; +import { useAuth } from '@/lib/auth'; +import { CARD_BG } from '@/lib/colors'; +import { useRegion } from '@/lib/region'; +import { useShare } from '@/lib/share-image'; +import { useSheet } from '@/lib/sheet'; +import { SITE_URL } from '@/lib/site'; +import { openTopics, talkImage, talkMeta, useMyTalks, useRefreshTalks } from '@/lib/talk'; + +const BODY_MAX = 100; +const PHOTO_MAX = 10 * 1024 * 1024; + +// 서버 ErrorType 이름 → 안내 +const WRITE_ERRORS: Record = { + LINK_NOT_ALLOWED: '링크나 전화번호는 쓸 수 없어요.', + DAILY_LIMIT: '오늘은 더 쓸 수 없어요. 하루 5개까지예요.', + INVALID_INPUT: '100자 안으로 써 주세요.', +}; + +const REASONS = [ + [TalkReport.ABUSE, '욕설·비하'], + [TalkReport.SPAM, '광고·도배'], + [TalkReport.PRIVACY, '개인정보 노출'], + [TalkReport.ETC, '기타'], +] as const; + +type Photo = { uri: string; name: string; type: string }; + +/** 고른 사진을 올려 주소를 받는다. 앱의 사진은 Blob 이 아니라 {uri} 라서 FormData 를 직접 만든다 */ +async function uploadPhoto(photo: Photo) { + const form = new FormData(); + form.append('file', photo as unknown as Blob); + const { data } = await uploadTalkImage({ body: { file: photo as unknown as Blob }, bodySerializer: () => form }); + if (!data.result?.success || !data.image) throw new Error(data.result?.desc ?? 'upload'); + return data.image; +} + +/** 이야기 쓰는 칸: 로그인해야 쓴다. 주제·사진(하나)을 붙여 올린다 */ +export function Composer() { + const { region } = useRegion(); + const { loggedIn, me } = useAuth(); + const { open } = useSheet(); + const s = useSoft(); + const [ink2] = useCSSVariable(['--color-ink2']).map(String); + const refresh = useRefreshTalks(); + const add = useMutation(addTalkMutation()); + const [text, setText] = useState(''); + const [topic, setTopic] = useState(TalkTopic.LOCAL); + const [error, setError] = useState(null); + const [photo, setPhoto] = useState(null); + const [uploading, setUploading] = useState(false); + const busy = add.isPending || uploading; + const place = region.name.split(' ').at(-1); + + const pick = async () => { + if (!loggedIn) return open({ type: 'login' }); + try { + const res = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ['images'], quality: 0.85 }); + const a = res.canceled ? undefined : res.assets[0]; + if (!a) return; + if (a.fileSize && a.fileSize > PHOTO_MAX) return setError('사진은 10MB까지 올릴 수 있어요.'); + setError(null); + setPhoto({ uri: a.uri, name: a.fileName ?? 'photo.jpg', type: a.mimeType ?? 'image/jpeg' }); + } catch (e) { + console.error('[talk] pick photo', e); + setError('사진을 고르지 못했어요. 다시 해 주세요.'); + } + }; + + const submit = async () => { + if (!loggedIn) return open({ type: 'login' }); + const body = text.trim(); + if (!body || busy) return; + setError(null); + let image: string | undefined; + if (photo) { + setUploading(true); + try { + image = await uploadPhoto(photo); + } catch (e) { + console.error('[talk] photo upload', e); + return setError('사진을 올리지 못했어요. 사진 파일인지 확인해 주세요.'); + } finally { + setUploading(false); + } + } + add.mutate( + { body: { region_code: region.code, body, image, topic } }, + { + onSuccess: (res) => { + if (!res.result?.success) return setError(WRITE_ERRORS[res.result?.desc ?? ''] ?? '글을 올리지 못했어요. 다시 해 주세요.'); + track('talk_post', { topic, with_image: !!image }); + setText(''); + setPhoto(null); + setTopic(TalkTopic.LOCAL); + refresh(); + }, + onError: () => setError('글을 올리지 못했어요. 다시 해 주세요.'), + }, + ); + }; + + return ( + + {/* 로그인 전엔 칸을 눌러도 키보드 대신 로그인 창 */} + open({ type: 'login' })}> + + + {photo && ( + + + setPhoto(null)} accessibilityRole="button" accessibilityLabel="사진 빼기" className="absolute -top-1.5 -right-1.5 size-6 items-center justify-center rounded-full bg-ink-btn"> + × + + + )} + + {openTopics().map(([k, label]) => ( + setTopic(k)} accessibilityRole="radio" accessibilityState={{ checked: topic === k }} className={`rounded-full px-2.5 py-1 ${topic === k ? 'bg-ink-btn' : ''}`} style={topic === k ? undefined : { backgroundColor: s.soft }}> + {label} + + ))} + + + {/* 주제 칩과 헷갈리지 않게 글자 대신 카메라 아이콘 */} + + + + + {me ? `${me.nickname} · ${place} · 지금 날씨가 함께 올라가요` : '로그인하면 쓸 수 있어요'} + + + {text.length}/{BODY_MAX} + + + {busy ? '올리는 중…' : '올리기'} + + + {!!error && ( + + {error} + + )} + + ); +} + +type Menu = 'closed' | 'open' | 'confirm' | 'report' | 'done'; + +/** 좋아요: 로그인 없이 된다. 화면을 먼저 바꾸고, 실패하면 되돌린다 */ +function useTalkLike(t: TalkData) { + const [liked, setLiked] = useState(t.liked); + const [count, setCount] = useState(t.like_count); + const like = useMutation(likeTalkMutation()); + const unlike = useMutation(unlikeTalkMutation()); + const toggle = () => { + if (like.isPending || unlike.isPending) return; + const next = !liked; + setLiked(next); + setCount((n) => n + (next ? 1 : -1)); + const revert = () => { + setLiked(!next); + setCount(t.like_count); + }; + (next ? like : unlike).mutate( + { path: { talk_id: t.talk_id } }, + { + onSuccess: (res) => { + if (!res.result?.success || res.like_count == null) return revert(); + if (next) track('like', { content_type: 'talk', item_id: t.talk_id }); + setCount(res.like_count); + }, + onError: revert, + }, + ); + }; + return { liked, count, toggle }; +} + +function Chip({ label, danger, onPress, disabled }: { label: string; danger?: boolean; onPress: () => void; disabled?: boolean }) { + return ( + + {label} + + ); +} + +/** 글 메뉴(⋯)를 눌렀을 때 나오는 버튼 줄: 내 글은 지우기, 남의 글은 안 보기·신고 */ +function TalkMenu({ t, menu, setMenu, className }: { t: TalkData; menu: Menu; setMenu: (m: Menu) => void; className?: string }) { + const { loggedIn } = useAuth(); + const { open } = useSheet(); + const refresh = useRefreshTalks(); + const remove = useMutation(deleteTalkMutation()); + const report = useMutation(reportTalkMutation()); + const block = useMutation(blockTalkAuthorMutation()); + const [failed, setFailed] = useState(false); + + // 메뉴의 동작은 끝나면 목록을 다시 받아 숨긴 글·안 보기로 한 사람의 글이 빠지게 한다 + const after = (done?: () => void) => ({ + onSuccess: (res: { result?: { success?: boolean } }) => { + if (!res.result?.success) return setFailed(true); + done?.(); + setMenu('done'); + refresh(); + }, + onError: () => setFailed(true), + }); + const guard = (run: () => void) => (loggedIn ? run() : open({ type: 'login' })); + + return ( + + {menu === 'done' ? ( + 처리했어요 + ) : t.mine && menu === 'confirm' ? ( + <> + 지울까요? + remove.mutate({ path: { talk_id: t.talk_id } }, after())} /> + setMenu('closed')} /> + + ) : t.mine ? ( + setMenu('confirm')} /> + ) : menu === 'report' ? ( + REASONS.map(([reason, label]) => report.mutate({ path: { talk_id: t.talk_id }, body: { reason } }, after(() => track('report', { content_type: 'talk', reason })))} />) + ) : ( + <> + guard(() => block.mutate({ path: { talk_id: t.talk_id } }, after(() => track('block', { content_type: 'talk' }))))} /> + guard(() => setMenu('report'))} /> + + )} + {failed && 못 했어요. 다시 해 주세요} + + ); +} + +function MenuButton({ menu, setMenu }: { menu: Menu; setMenu: (m: Menu) => void }) { + return ( + setMenu(menu === 'closed' ? 'open' : 'closed')} hitSlop={12} accessibilityRole="button" accessibilityState={{ expanded: menu !== 'closed' }} accessibilityLabel="글 메뉴"> + ⋯ + + ); +} + +function MineBadge() { + return ( + + {' 내 글 '} + + ); +} + +/** 한 줄 글: 목록·내 정보의 내 글 */ +function TalkRow({ t, last }: { t: TalkData; last?: boolean }) { + const { liked, count, toggle } = useTalkLike(t); + const [menu, setMenu] = useState('closed'); + const [heart, ink3] = useCSSVariable(['--color-heart', '--color-ink3']).map(String); + const src = talkImage(t); + + return ( + + + + + {t.nickname} + {t.mine && ( + <> + {' '} + + )} + {talkMeta(t)} + + {t.body} + {!!src && } + + {t.ago} · 좋아요 {count}개 + + {menu !== 'closed' && } + + {/* 글 메뉴(⋯)는 하트 옆 오른쪽 위에: 아래 줄 끝에 두면 말줄임표처럼 읽힌다 */} + + + + + + + + ); +} + +// 사진 없는 글을 크게 띄울 때 주제별 바탕 +const TOPIC_BG: Partial> = { [TalkTopic.SKY]: 'peach', [TalkTopic.RAIN]: 'sky', [TalkTopic.FOLIAGE]: 'butter', [TalkTopic.OUTFIT]: 'lilac' }; + +/** 오늘 피드에 끼우는 사람 글: 운영 포스트와 같은 틀. 사진이 없으면 글을 4:5 칸에 크게. 두 번 누르면 좋아요 */ +export function TalkPost({ t }: { t: TalkData }) { + const { open } = useSheet(); + const { liked, count, toggle } = useTalkLike(t); + const [menu, setMenu] = useState('closed'); + const [ink, heart] = useCSSVariable(['--color-ink', '--color-heart']).map(String); + const shot = useRef(null); + const lastTap = useRef(0); + const shareView = useShare(); + const src = talkImage(t); + const bg = (t.topic && (TOPIC_BG[t.topic] ?? holidayByTopic(t.topic)?.bg)) || 'mint'; + const title = `${t.nickname}의 글`; + const share = () => void shareView(shot, { title, message: `${t.body} · 날씨각 ${SITE_URL}` }); + const comments = () => open({ type: 'comments', talkId: t.talk_id }); + const onTap = () => { + const now = Date.now(); + if (now - lastTap.current < 320 && !liked) toggle(); + lastTap.current = now; + }; + + return ( + + + + + + {t.nickname} + {t.mine && ( + <> + {' '} + + + )} + + + {talkMeta(t)} + + + + + {menu !== 'closed' && } + + + {src ? ( + + ) : ( + // 포스트 안은 밤에도 낮 색 (웹 b-day) + + + {t.body} + + )} + + + + + + + + + + + + + + 좋아요 {count.toLocaleString()}개 + {!!src && ( + + {t.nickname} + {t.body} + + )} + + {t.comment_count ? `댓글 ${t.comment_count}개 모두 보기` : '첫 댓글 남기기'} + + {t.ago} + + ); +} + +/** 이야기 탭 목록의 글 한 장 */ +export function TalkCard({ t }: { t: TalkData }) { + return ( + + + + ); +} + +/** 내 정보 창의 내가 쓴 글 */ +export function MyTalks() { + const { talks, loaded, more, loadMore } = useMyTalks(); + const s = useSoft(); + if (!loaded) return null; + return ( + + 내 글 + {talks.length ? talks.map((t, i) => ) : 아직 쓴 글이 없어요} + {more && ( + loadMore()} className="mt-1 rounded-[14px] py-2.5" style={{ backgroundColor: s.soft }}> + 더 보기 + + )} + + ); +} diff --git a/mobile/src/lib/sheet.ts b/mobile/src/lib/sheet.ts index ecf884b..59b9488 100644 --- a/mobile/src/lib/sheet.ts +++ b/mobile/src/lib/sheet.ts @@ -2,7 +2,9 @@ import { createContext, use } from 'react'; import type { WeatherWhyPayload } from '@/components/sheets/weather-why'; -type CommentsState = { type: 'comments'; postId: number; draft?: string }; +/** 댓글이 달린 곳: 운영 포스트 또는 사람 글 */ +export type CommentTarget = { postId: number } | { talkId: number }; +type CommentsState = { type: 'comments'; draft?: string } & CommentTarget; export type SheetState = | { type: 'gak'; indexId: number } diff --git a/mobile/src/lib/talk.ts b/mobile/src/lib/talk.ts new file mode 100644 index 0000000..882b713 --- /dev/null +++ b/mobile/src/lib/talk.ts @@ -0,0 +1,75 @@ +import { listMyTalksInfiniteOptions, listTalksInfiniteOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'; +import { TalkTopic, type TalkData } from '@nalssigak/shared/api/client/types.gen'; +import { kst } from '@nalssigak/shared/lib'; +import { HOLIDAYS, holidayOn } from '@nalssigak/shared/lib/holiday'; +import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query'; + +import { useRegion } from '@/lib/region'; +import { apiUri } from '@/lib/site'; + +// 글 주제와 이름 (웹 talkState.ts) +export const TOPICS = [ + [TalkTopic.LOCAL, '동네 이야기'], + [TalkTopic.SKY, '하늘·노을'], + [TalkTopic.RAIN, '비·눈'], + [TalkTopic.FOLIAGE, '단풍·꽃'], + [TalkTopic.OUTFIT, '오늘 옷차림'], + ...HOLIDAYS.map((h) => [h.topic, h.name] as const), +] as const; +export const topicName = (t?: number) => TOPICS.find(([k]) => k === t)?.[1] ?? '동네 이야기'; + +/** 지금 고를 수 있는 주제: 기념일 주제는 그 기간에만 */ +export function openTopics() { + const on = holidayOn()?.topic; + return TOPICS.filter(([k]) => !HOLIDAYS.some((h) => h.topic === k) || k === on); +} + +/** 주제별 글 페이지 목록 (topic 없으면 전체) */ +export function useTopicTalks(topic?: TalkTopic) { + const { region } = useRegion(); + const list = useInfiniteQuery({ + ...listTalksInfiniteOptions({ query: { region: region.code, ...(topic ? { topic } : {}) } }), + initialPageParam: {}, + getNextPageParam: (last) => last.next_cursor ?? undefined, + }); + return { + talks: list.data?.pages.flatMap((p) => p.talks ?? []) ?? [], + loaded: list.isSuccess, + more: list.hasNextPage && !list.isFetchingNextPage, + loadMore: list.fetchNextPage, + refetch: list.refetch, + refetching: list.isRefetching, + }; +} + +/** 내가 쓴 글 (최신순) */ +export function useMyTalks(enabled = true) { + const list = useInfiniteQuery({ + ...listMyTalksInfiniteOptions(), + enabled, + initialPageParam: {}, + getNextPageParam: (last) => last.next_cursor ?? undefined, + }); + return { + talks: list.data?.pages.flatMap((p) => p.talks ?? []) ?? [], + loaded: list.isSuccess, + more: list.hasNextPage && !list.isFetchingNextPage, + loadMore: list.fetchNextPage, + }; +} + +export function useRefreshTalks() { + const queryClient = useQueryClient(); + return () => queryClient.invalidateQueries({ predicate: (q) => ['listTalks', 'listMyTalks'].includes((q.queryKey[0] as { _id?: string } | undefined)?._id ?? '') }); +} + +/** 쓴 시각을 시간대로만: 정확한 시각은 동선이 드러나서 뭉갠다 */ +function slotWord(iso: string) { + const h = kst(iso).h; + return h < 6 ? '새벽' : h < 10 ? '아침' : h < 17 ? '낮' : h < 21 ? '저녁' : '밤'; +} + +export const talkMeta = (t: TalkData) => [t.region_name, slotWord(t.created_at), t.weather, t.topic && t.topic !== TalkTopic.LOCAL ? topicName(t.topic) : null].filter(Boolean).join(' · '); + +/** 올린 사진은 API 서버 경로(/v1/talk/image/...) */ +export const talkImage = (t: TalkData) => (t.image ? apiUri(t.image) : undefined); diff --git a/package-lock.json b/package-lock.json index be8c3cd..88c8136 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,6 +54,7 @@ "expo-font": "~57.0.4", "expo-glass-effect": "~57.0.4", "expo-image": "~57.0.5", + "expo-image-picker": "~57.0.20", "expo-linear-gradient": "~57.0.2", "expo-linking": "~57.0.12", "expo-location": "~57.0.21", @@ -101,6 +102,7 @@ "resolved": "https://registry.npmjs.org/react/-/react-19.2.3.tgz", "integrity": "sha512-Ku/hhYbVjOQnXDZFv2+RibmLFGwFdeeKHFcOTlrt7xplBnya5OGn/hIRDsqDiSUcfORsDC7MPxwork8jBwsIWA==", "license": "MIT", + "peer": true, "engines": { "node": ">=0.10.0" } @@ -211,6 +213,7 @@ "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.29.7.tgz", "integrity": "sha512-RgHBCvtjbOK2gXSNBNIkNoEc9qoVEtau3hj8gEqKQuL3HZAibKarWFEI3Lfm6EYKkLalOh8eSrj9b+ch9H/VBA==", "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.29.7", "@babel/generator": "^7.29.7", @@ -1095,7 +1098,6 @@ "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.29.7.tgz", "integrity": "sha512-TL0hMc9xzy86VD31nUiwzd5otRAcyEPcsegCxolO0PvcXuH1v0kECe/UIznYFihpkvU5wg/jk4v0TTEFfm53fw==", "license": "MIT", - "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.29.7" }, @@ -1111,7 +1113,6 @@ "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.29.7.tgz", "integrity": "sha512-06IyK09H3wi4cGbhDBwp5gUGo0IKtnYa8tyTiephirPCK6fbobVGiXMMI5zLQ4aKEYP3wZ3ArU44o+8KMrSG/Q==", "license": "MIT", - "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.29.7" }, @@ -1143,7 +1144,6 @@ "resolved": "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.29.8.tgz", "integrity": "sha512-0UpIXPtdDtMXfnV2OJAVMLpj3H/92vmkA6lpSRakmycJvj3VUy6Xs1dM8tXRugupykr5WB+LpiVl0J8LMVg2mg==", "license": "MIT", - "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.29.7" }, @@ -1397,27 +1397,6 @@ "node": ">=0.8.0" } }, - "node_modules/@emnapi/core": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.10.0.tgz", - "integrity": "sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==", - "license": "MIT", - "optional": true, - "dependencies": { - "@emnapi/wasi-threads": "1.2.1", - "tslib": "^2.4.0" - } - }, - "node_modules/@emnapi/runtime": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.10.0.tgz", - "integrity": "sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==", - "license": "MIT", - "optional": true, - "dependencies": { - "tslib": "^2.4.0" - } - }, "node_modules/@emnapi/wasi-threads": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz", @@ -2734,9 +2713,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -2754,9 +2730,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -2774,9 +2747,6 @@ "ppc64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -2794,9 +2764,6 @@ "riscv64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -2814,9 +2781,6 @@ "riscv64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -2834,9 +2798,6 @@ "s390x" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -2854,9 +2815,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -2874,9 +2832,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3504,7 +3459,6 @@ "resolved": "https://registry.npmjs.org/@react-native/babel-preset/-/babel-preset-0.86.3.tgz", "integrity": "sha512-/eqs/Hy9RZRcjdcs4wj3Cqmxvtb3NM5g+Uuh1RIvsjynMO8PRsrVWWLWgBcZL/jYUo+ogXd2NFB0W8L5Bg89xw==", "license": "MIT", - "peer": true, "dependencies": { "@babel/core": "^7.25.2", "@babel/plugin-proposal-export-default-from": "^7.24.7", @@ -3552,7 +3506,6 @@ "resolved": "https://registry.npmjs.org/babel-plugin-syntax-hermes-parser/-/babel-plugin-syntax-hermes-parser-0.36.0.tgz", "integrity": "sha512-LhD0xdoedDw7ansQgXbB2DADLZIK/LRXuWNBPuVzMc5S2WK5GyT89tCM+cQzxFGO0mGyLK6D5TrVOJJzAoDy8Q==", "license": "MIT", - "peer": true, "dependencies": { "hermes-parser": "0.36.0" } @@ -3561,15 +3514,13 @@ "version": "0.36.0", "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.36.0.tgz", "integrity": "sha512-A1+8zn5oss2CFP7pKsOaxorQG6FNIz1WU1VDqruLPPZl3LVgeE2C5xfFg8Ow6/Ow4mSslLLtYP1J3n38eKyW9w==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@react-native/babel-preset/node_modules/hermes-parser": { "version": "0.36.0", "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.36.0.tgz", "integrity": "sha512-GdpwMmH5x6IpC1cijvcvYnlPB60Mh6kTSF/NFdYV/j56gYdi+0RIakYs+eqOV+bbO0SW7mgVVGSsTJxyPQfo3w==", "license": "MIT", - "peer": true, "dependencies": { "hermes-estree": "0.36.0" } @@ -3746,7 +3697,6 @@ "resolved": "https://registry.npmjs.org/@react-native/metro-babel-transformer/-/metro-babel-transformer-0.86.3.tgz", "integrity": "sha512-0nlwVkG0uT9o72nrGTKUz/IqDnCkM4zE0ihe4r+OJcxH93yBdDm58AXJ3EXZeSjv3osHEFXU7ceajdZiS34mTw==", "license": "MIT", - "peer": true, "dependencies": { "@babel/core": "^7.25.2", "@react-native/babel-preset": "0.86.3", @@ -3764,15 +3714,13 @@ "version": "0.36.0", "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.36.0.tgz", "integrity": "sha512-A1+8zn5oss2CFP7pKsOaxorQG6FNIz1WU1VDqruLPPZl3LVgeE2C5xfFg8Ow6/Ow4mSslLLtYP1J3n38eKyW9w==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@react-native/metro-babel-transformer/node_modules/hermes-parser": { "version": "0.36.0", "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.36.0.tgz", "integrity": "sha512-GdpwMmH5x6IpC1cijvcvYnlPB60Mh6kTSF/NFdYV/j56gYdi+0RIakYs+eqOV+bbO0SW7mgVVGSsTJxyPQfo3w==", "license": "MIT", - "peer": true, "dependencies": { "hermes-estree": "0.36.0" } @@ -3782,7 +3730,6 @@ "resolved": "https://registry.npmjs.org/@react-native/metro-config/-/metro-config-0.86.3.tgz", "integrity": "sha512-qdzDMepV2xdUhsO4XC7idnnbt8K6+Hd59AjeK9y4KS86fxSQq5oL0TAbqUuajDGR7beNQoYTuS6AowN/zP0oaQ==", "license": "MIT", - "peer": true, "dependencies": { "@react-native/js-polyfills": "0.86.3", "@react-native/metro-babel-transformer": "0.86.3", @@ -3931,9 +3878,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3950,9 +3894,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3969,9 +3910,6 @@ "cpu": [ "ppc64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3988,9 +3926,6 @@ "cpu": [ "s390x" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4007,9 +3942,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4026,9 +3958,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4230,9 +4159,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4249,9 +4175,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4268,9 +4191,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4287,9 +4207,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4389,6 +4306,7 @@ "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.104.2.tgz", "integrity": "sha512-xKmzWGhadbE5wGS/ZmXShRITnI9oItox5GO14KvFZco3+vhTAyXS1erYzJWdiY280zapAGJXFUL9nHgwP6SV/g==", "license": "MIT", + "peer": true, "dependencies": { "@tanstack/query-core": "5.104.2" }, @@ -4565,6 +4483,7 @@ "integrity": "sha512-aTtmZjp/x3gsGHkDs04/1I8kNogBJkpQaeGaN0PfiG43NzDEmW2n+OP5im9wfsvyX0yP1UZWBrAGtDBfH9jEVw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.71.2", "@typescript-eslint/types": "8.71.2", @@ -4914,9 +4833,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4931,9 +4847,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4948,9 +4861,6 @@ "loong64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4965,9 +4875,6 @@ "loong64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4982,9 +4889,6 @@ "ppc64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4999,9 +4903,6 @@ "riscv64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -5016,9 +4917,6 @@ "riscv64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -5033,9 +4931,6 @@ "s390x" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -5050,9 +4945,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -5067,9 +4959,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -5242,6 +5131,7 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.19.0.tgz", "integrity": "sha512-oJlA3XiRm7Cyk6qFD2Jn8ak9B7jSy0qy00ADO3+8dpT0LSjFihQYv4C02LFCSYJV3Q37xYwwRy5m+IpIiUzqWw==", "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -5645,6 +5535,7 @@ "resolved": "https://registry.npmjs.org/babel-plugin-react-compiler/-/babel-plugin-react-compiler-1.0.0.tgz", "integrity": "sha512-Ixm8tFfoKKIPYdCCKYTsqv+Fd4IJ0DQqMyEimo+pxUOMUR9cVPlwTrFt9Avu+3cb6Zp3mAzl+t1MrG2fxxKsxw==", "license": "MIT", + "peer": true, "dependencies": { "@babel/types": "^7.26.0" } @@ -5866,6 +5757,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.11.26", "caniuse-lite": "^1.0.30001813", @@ -6877,7 +6769,8 @@ "version": "8.6.0", "resolved": "https://registry.npmjs.org/embla-carousel/-/embla-carousel-8.6.0.tgz", "integrity": "sha512-SjWyZBHJPbqxHOzckOfo8lHisEaJWmwd23XppYFYVh10bU66/Pn5tkVkbkCMZVdbUE5eTCI2nD8OyIP4Z+uwkA==", - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/embla-carousel-react": { "version": "8.6.0", @@ -7182,6 +7075,7 @@ "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -7402,6 +7296,7 @@ "integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@rtsao/scc": "^1.1.0", "array-includes": "^3.1.9", @@ -7684,6 +7579,7 @@ "resolved": "https://registry.npmjs.org/expo/-/expo-57.0.28.tgz", "integrity": "sha512-Bh9PgT1wLdcSOi8uXvUtHYh12zz9kx3zjD8Pm7O8EAsZW0W42dVog3/UhY2qJnlOkSDpTQJTnX8jsi2J5xn2OA==", "license": "MIT", + "peer": true, "dependencies": { "@babel/runtime": "^7.20.0", "@expo/cli": "^57.0.29", @@ -7761,6 +7657,7 @@ "resolved": "https://registry.npmjs.org/expo-constants/-/expo-constants-57.0.21.tgz", "integrity": "sha512-D5fV2GELYGbNkoiEVZZp5zrUXZDaAx6ZzErDzGirm3jCjOhaE8iU/GyJiB0ZQE+K4Bg8gY82nIQ/RZR8CJLVjA==", "license": "MIT", + "peer": true, "dependencies": { "@expo/env": "~2.4.3" }, @@ -7796,6 +7693,7 @@ "resolved": "https://registry.npmjs.org/expo-font/-/expo-font-57.0.4.tgz", "integrity": "sha512-7WOMC2oA6xCfOm8bbofqWn2bIqyWFm7YLEnpc/gA1MJH0Ll0TfT/3+CqRkoW2eNRWMS8sxrz5WukUmSvmNquHA==", "license": "MIT", + "peer": true, "dependencies": { "fontfaceobserver": "^2.1.0" }, @@ -7836,6 +7734,27 @@ } } }, + "node_modules/expo-image-loader": { + "version": "57.0.1", + "resolved": "https://registry.npmjs.org/expo-image-loader/-/expo-image-loader-57.0.1.tgz", + "integrity": "sha512-uhrZKLT/cTl2mXyR28kPpVkS5O+PK9N1QA/07IFM4f5T4g0lTW1JHT3NEWwEEsGFldPmVX4j7LwUVVZxE+woug==", + "license": "MIT", + "peerDependencies": { + "expo": "*" + } + }, + "node_modules/expo-image-picker": { + "version": "57.0.20", + "resolved": "https://registry.npmjs.org/expo-image-picker/-/expo-image-picker-57.0.20.tgz", + "integrity": "sha512-plgcGuMZMWqDchjXQW6S/WepYLB5KqfbZOzwC6xe0+j5IhY4ipvVuRZcXeP/0NgKgU0Jiu/XoTK4Bi8crtZ+sQ==", + "license": "MIT", + "dependencies": { + "expo-image-loader": "~57.0.1" + }, + "peerDependencies": { + "expo": "*" + } + }, "node_modules/expo-keep-awake": { "version": "57.0.2", "resolved": "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-57.0.2.tgz", @@ -7862,6 +7781,7 @@ "resolved": "https://registry.npmjs.org/expo-linking/-/expo-linking-57.0.12.tgz", "integrity": "sha512-oKLva5FOBx4txZa9LFu6RaHGAy1lFCyoOM91uU9H+gZi1iskjuSxV12GgS9H+yGGe2aSLufh6IfwSWrjEIsOuA==", "license": "MIT", + "peer": true, "dependencies": { "expo-constants": "~57.0.21", "invariant": "^2.2.4" @@ -7942,6 +7862,7 @@ "resolved": "https://registry.npmjs.org/expo-router/-/expo-router-57.0.26.tgz", "integrity": "sha512-iSF+LEbbvGkYGA2j8qWvF1woxrA7EWHZF+SNdTPR7dmi6myPOJsDGdwfWlXA74Gns8T7AuyfuDsxIsqEJ45BhQ==", "license": "MIT", + "peer": true, "dependencies": { "@expo/log-box": "^57.0.4", "@expo/metro-runtime": "^57.0.16", @@ -8023,6 +7944,7 @@ "resolved": "https://registry.npmjs.org/expo-server/-/expo-server-57.0.3.tgz", "integrity": "sha512-aK+LdKzauHSGmsOStZtyxdzv0zWssCkxTw3m4QuOhfDSJsZaMRTd9O41d8ixU/QfELTbaJ0oRNcF7JFV/7O9YQ==", "license": "MIT", + "peer": true, "engines": { "node": ">=20.16.0" } @@ -10059,9 +9981,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -10082,9 +10001,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -10105,9 +10021,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -10128,9 +10041,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -10497,6 +10407,7 @@ "resolved": "https://registry.npmjs.org/metro-cache/-/metro-cache-0.84.5.tgz", "integrity": "sha512-WHS0n2OxQqtwEjSeQFPePNrMvEFhmQcUQM9cRJMHByWoi/GMWFBEWOf7hVkAM/0KRutAXNbDlSu/cZB6CyxgQQ==", "license": "MIT", + "peer": true, "dependencies": { "exponential-backoff": "^3.1.1", "flow-enums-runtime": "^0.0.6", @@ -12344,6 +12255,7 @@ "resolved": "https://registry.npmjs.org/react/-/react-19.3.0.tgz", "integrity": "sha512-E8LUcbtBWt20bbl2YoHfx4ZDBdxVTfOKtCZn9cDSJ4l6/nuoApcpIBcj47t2wZoVX8g2ZHuMHbiShgCR1T5Sog==", "license": "MIT", + "peer": true, "engines": { "node": ">=0.10.0" } @@ -12384,6 +12296,7 @@ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.3.0.tgz", "integrity": "sha512-JDk8dgif51OjFoDE70+OT9ICyYr+69HlmihNwp1+Nsfbna3t5sIiCa9ZJktDmQ4/1b/rn26hIAR2uYXDMr5r0Q==", "license": "MIT", + "peer": true, "dependencies": { "scheduler": "^0.28.0" }, @@ -12426,6 +12339,7 @@ "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.86.3.tgz", "integrity": "sha512-JR5s3bM9ezud+Mw24GlNXNfthqPIKwrQgPPJcam+L97t2sKjjEavhCzBn+fyqZZRcM5+XlhYxpTxVkK7e1n38Q==", "license": "MIT", + "peer": true, "dependencies": { "@react-native/assets-registry": "0.86.3", "@react-native/codegen": "0.86.3", @@ -12501,6 +12415,7 @@ "resolved": "https://registry.npmjs.org/react-native-gesture-handler/-/react-native-gesture-handler-2.32.0.tgz", "integrity": "sha512-uYIMOKlKENORq2SABE+jIjbPU+h5I/sQKcq2v16zRq848nwEp1fWRVwML4QWqijc8UcXJC25o54S8GQd4Mf2OA==", "license": "MIT", + "peer": true, "dependencies": { "@egjs/hammerjs": "^2.0.17", "@types/react-test-renderer": "^19.1.0", @@ -12527,6 +12442,7 @@ "resolved": "https://registry.npmjs.org/react-native-reanimated/-/react-native-reanimated-4.5.1.tgz", "integrity": "sha512-RnMvtDuR+68ig864gAvZCOdZehqhC5rFmMo0kn+ARfgVSTvFeF6IFLBVgMPUu0KwihaapEyW24WRi6nEyy1kSA==", "license": "MIT", + "peer": true, "dependencies": { "react-native-is-edge-to-edge": "^1.3.1", "semver": "^7.7.3" @@ -12542,6 +12458,7 @@ "resolved": "https://registry.npmjs.org/react-native-safe-area-context/-/react-native-safe-area-context-5.7.0.tgz", "integrity": "sha512-/9/MtQz8ODphjsLdZ+GZAIcC/RtoqW9EeShf7Uvnfgm/pzYrJ75y3PV/J1wuAV1T5Dye5ygq4EAW20RoBq0ABQ==", "license": "MIT", + "peer": true, "peerDependencies": { "react": "*", "react-native": "*" @@ -12598,6 +12515,7 @@ "resolved": "https://registry.npmjs.org/react-native-web/-/react-native-web-0.21.4.tgz", "integrity": "sha512-77B6KlalB4osNIck91TNFixPkYPsTbuNEvw8P7IV+4v4/5wZSBRKZnw0Zhx6YjuauDTz71gc8IW+fVhcBMjr5A==", "license": "MIT", + "peer": true, "dependencies": { "@babel/runtime": "^7.18.6", "@react-native/normalize-colors": "^0.74.1", @@ -12630,6 +12548,7 @@ "resolved": "https://registry.npmjs.org/react-native-worklets/-/react-native-worklets-0.10.1.tgz", "integrity": "sha512-62mRM19bDpfpdI8HLkEErcdOsrAPDtE9lA/sw+5lLRpzBHNhxaoj9QyY2KjXqUmirelxkX4zuPGTC3VdA0feJA==", "license": "MIT", + "peer": true, "dependencies": { "@babel/plugin-transform-arrow-functions": "^7.27.1", "@babel/plugin-transform-class-properties": "^7.28.6", @@ -12710,6 +12629,7 @@ "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.2.tgz", "integrity": "sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==", "license": "MIT", + "peer": true, "engines": { "node": ">=0.10.0" } @@ -13872,7 +13792,8 @@ "version": "4.3.3", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.3.3.tgz", "integrity": "sha512-gOhV3P7ufE62QDGg1zVaTgCR+EtPv92k2nIhVcVKcLmxT1sUBsQGhnZj175j+MqRt4zLF7ic+sCYjfhxMxj7YQ==", - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/tapable": { "version": "2.3.3", @@ -13908,6 +13829,7 @@ "resolved": "https://registry.npmjs.org/terser/-/terser-5.51.2.tgz", "integrity": "sha512-bWnjSNscmuI+GJze6ZupnHP8G/cTcsJF+bXCeQknk2SHQsgbNJnLrqiH9jZ2W4STPVXH2mDKKRX3iwPhc9Cn/Q==", "license": "BSD-2-Clause", + "peer": true, "dependencies": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.15.0", @@ -14171,6 +14093,7 @@ "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "devOptional": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -14417,9 +14340,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -14440,9 +14360,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -14463,9 +14380,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -14486,9 +14400,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -14768,6 +14679,7 @@ "resolved": "https://registry.npmjs.org/vite/-/vite-8.3.4.tgz", "integrity": "sha512-IftLE8phJhdNRIGNEV4JCCvfNScoZQVfcXaN8TQropWGJtOHcu+iAB9pHcuGvmEb/kddw0LBe/jS8ztdC6xdiQ==", "license": "MIT", + "peer": true, "dependencies": { "lightningcss": "^1.33.0", "picomatch": "^4.0.7", @@ -14976,9 +14888,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -14999,9 +14908,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -15022,9 +14928,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -15045,9 +14948,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -15332,6 +15232,7 @@ "resolved": "https://registry.npmjs.org/ws/-/ws-8.22.0.tgz", "integrity": "sha512-Ydggc987+RO0AnWtZ/7Wq9FtNvcrL1b/RO0ud9mWjUPgDrsAAwQSF51sm2hm1XofbU/4jkpGEsLFsZZxU+1DOg==", "license": "MIT", + "peer": true, "engines": { "node": ">=10.0.0" }, @@ -15445,6 +15346,7 @@ "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz", "integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==", "license": "ISC", + "peer": true, "bin": { "yaml": "bin.mjs" }, @@ -15501,6 +15403,7 @@ "integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==", "dev": true, "license": "MIT", + "peer": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } diff --git a/shared/lib/holiday.ts b/shared/lib/holiday.ts new file mode 100644 index 0000000..0f8833d --- /dev/null +++ b/shared/lib/holiday.ts @@ -0,0 +1,106 @@ +import { TalkTopic } from '../api/client/types.gen' +import { kst } from '.' + +/** 게임 8단계 그림을 바꾼다. 작은 것부터 큰 것 순서, 크기·색은 원래 단계 그대로 */ +type GamePiece = { icon: string; name: string } + +/** + * 기념일 꾸밈. 기간(KST, 양 끝 포함) 안에만 켜진다. 'MM-DD' 는 해마다, 'YYYY-MM-DD' 는 그해만(음력 기념일). + * 새 기념일: 여기에 한 줄 + TalkTopic(backend/common/enums.py) + 게임 그림(public/b/icons, lib.ts OWN) + 소품 그림(public/b/holiday, 투명 배경, b.css) + */ +export type Holiday = { + key: 'halloween' | 'pepero' | 'christmas' | 'chuseok' + name: string + ranges: readonly (readonly [string, string])[] + topic: TalkTopic + /** 글만 있는 사람 글 배경 (b.css b-bg-*) */ + bg: string + game: readonly GamePiece[] +} + +export const HOLIDAYS: readonly Holiday[] = [ + { + key: 'halloween', + name: '할로윈', + ranges: [['10-30', '11-01']], + topic: TalkTopic.HALLOWEEN, + bg: 'night', + game: [ + { icon: 'candy', name: '사탕' }, + { icon: 'lollipop', name: '막대사탕' }, + { icon: 'spider', name: '거미' }, + { icon: 'spider_web', name: '거미줄' }, + { icon: 'bat', name: '박쥐' }, + { icon: 'ghost', name: '유령' }, + { icon: 'skull', name: '해골' }, + { icon: 'jack_o_lantern', name: '호박등' }, + ], + }, + { + key: 'pepero', + name: '빼빼로데이', + ranges: [['11-11', '11-11']], + topic: TalkTopic.PEPERO, + bg: 'peach', + game: [ + { icon: 'pepero_choco', name: '초코' }, + { icon: 'pepero_almond', name: '아몬드' }, + { icon: 'pepero_strawberry', name: '딸기' }, + { icon: 'pepero_nude', name: '누드' }, + { icon: 'pepero_pair', name: '한 쌍' }, + { icon: 'pepero_bundle', name: '다발' }, + { icon: 'pepero_box', name: '한 상자' }, + { icon: 'pepero_basket', name: '바구니' }, + ], + }, + { + key: 'christmas', + name: '크리스마스', + ranges: [['12-24', '12-25']], + topic: TalkTopic.CHRISTMAS, + bg: 'mint', + game: [ + { icon: 'xmas_candy_cane', name: '캔디케인' }, + { icon: 'xmas_ornament', name: '장식볼' }, + { icon: 'xmas_gingerbread', name: '진저쿠키' }, + { icon: 'xmas_santa_hat', name: '산타 모자' }, + { icon: 'xmas_stocking', name: '양말' }, + { icon: 'xmas_wreath', name: '리스' }, + { icon: 'xmas_santa', name: '산타' }, + { icon: 'christmas_tree', name: '트리' }, + ], + }, + { + key: 'chuseok', + name: '추석', + ranges: [['2027-09-14', '2027-09-16']], + topic: TalkTopic.CHUSEOK, + bg: 'butter', + game: [ + { icon: 'chestnut', name: '밤' }, + { icon: 'pear', name: '배' }, + { icon: 'apple', name: '사과' }, + { icon: 'dango', name: '떡' }, + { icon: 'rabbit', name: '토끼' }, + { icon: 'maple', name: '단풍' }, + { icon: 'moon_viewing', name: '달맞이' }, + { icon: 'full_moon', name: '보름달' }, + ], + }, +] + +const pad = (n: number) => String(n).padStart(2, '0') + +function inRange([from, to]: readonly [string, string], y: number, md: string) { + const day = from.length === 10 ? `${y}-${md}` : md + return from <= day && day <= to +} + +/** 그날(KST) 켜진 기념일 */ +export function holidayOn(now = new Date()): Holiday | undefined { + const { y, mo, d } = kst(now) + const md = `${pad(mo)}-${pad(d)}` + return HOLIDAYS.find((h) => h.ranges.some((r) => inRange(r, y, md))) +} + +export const holidayByTopic = (t?: number) => HOLIDAYS.find((h) => h.topic === t)