chore: 앱에서 안 쓰는 네이티브 화면 정리 — 웹뷰 셸이 쓰지 않는 화면·컴포넌트·lib 81개 파일, 패키지 15개(이미지·SVG·화면 캡처·사진 선택·보안 저장소·react-query·shared 등), app.json 의 secure-store·image-picker 플러그인을 뺌. 경로 파일이 없으면 Expo Router 안내 화면이 떠서 앱이 죽어 빈 index.tsx 를 둠. 이벤트 문서·AGENTS.md 를 웹뷰 구조에 맞춤
This commit is contained in:
1 parent
d4f937b439
commit
016b77f234
88 files changed
+66
-9204
No files matched your search
@@ -1,18 +0,0 @@
|
||||
import { Tabs } from 'expo-router/tabs';
|
||||
|
||||
import { TabBar } from '@/components/tab-bar';
|
||||
import { TopBar } from '@/components/top-bar';
|
||||
|
||||
/** 아래 탭 다섯 개. 사주·게임 같은 화면은 탭 밖(루트 스택)에서 연다 */
|
||||
export default function TabsLayout() {
|
||||
return (
|
||||
<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>
|
||||
);
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
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, View } from 'react-native';
|
||||
import { Text } from '@/components/text';
|
||||
|
||||
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>
|
||||
);
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
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 { router, useLocalSearchParams } from 'expo-router';
|
||||
import { Fragment, useEffect, useRef, type ReactNode } from 'react';
|
||||
import { RefreshControl, ScrollView, View, type LayoutRectangle } from 'react-native';
|
||||
|
||||
import { FoliageCard } from '@/components/foliage/foliage-card';
|
||||
import { MyGakRow } from '@/components/my-gak/my-gak';
|
||||
import { isAppPost, PostCard, PostCardSkel } from '@/components/post/post-card';
|
||||
import { ShortsRail } from '@/components/shorts/rail';
|
||||
import { Composer, TalkPost } from '@/components/talk/talk';
|
||||
import { GakCard } from '@/components/today/gak-card';
|
||||
import { Hero } from '@/components/today/hero';
|
||||
import { TodayIcons } from '@/components/today/icons';
|
||||
import { SeasonBand } from '@/components/today/rails';
|
||||
import { StateBox } from '@/components/ui';
|
||||
import { track } from '@/lib/analytics';
|
||||
import { useFoliage } from '@/lib/foliage';
|
||||
import { fromShare } from '@/lib/my-gak';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
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<string, Spot>());
|
||||
const sent = useRef(new Set<string>());
|
||||
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();
|
||||
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 ?? []).filter(isAppPost);
|
||||
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 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 { inSeason } = useFoliage();
|
||||
const scroll = useRef<ScrollView>(null);
|
||||
const myGakY = useRef(0);
|
||||
const { open } = useSheet();
|
||||
const { my } = useLocalSearchParams<{ my?: string }>();
|
||||
|
||||
// 친구가 보낸 내 각 링크(?my=...)로 들어오면 내 동네 기준으로 보여 준다
|
||||
useEffect(() => {
|
||||
if (!my) return;
|
||||
router.setParams({ my: undefined });
|
||||
const g = fromShare(my);
|
||||
if (g) open({ type: 'mix', shared: g });
|
||||
}, [my, open]);
|
||||
const refresh = () => Promise.all([feed.refetch(), today.refetch(), talkList.refetch()]);
|
||||
|
||||
// 웹처럼 9번째 글 뒤에 계절 이야기 띠를 넣고, 글이 모자라면 맨 뒤에 붙인다
|
||||
const bandAt: [number, ReactNode][] = [[9, bands?.season?.length ? <SeasonBand news={bands.season} /> : null]];
|
||||
|
||||
return (
|
||||
// 지역마다 새로 그려 넘긴 슬라이드 위치가 남지 않게 한다
|
||||
<ScrollView
|
||||
ref={scroll}
|
||||
key={region.code}
|
||||
contentContainerClassName="pb-6"
|
||||
refreshControl={<RefreshControl refreshing={feed.isRefetching && !feed.isPlaceholderData} onRefresh={refresh} />}
|
||||
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)}
|
||||
>
|
||||
<Hero hero={f?.hero} post={f?.hero_post} today={today.data} ranked={stories} feedLoad={load} todayLoad={loadOf(today)} />
|
||||
<TodayIcons foliage={inSeason} onMyGak={() => scroll.current?.scrollTo({ y: myGakY.current, animated: true })} />
|
||||
<ShortsRail />
|
||||
<Composer />
|
||||
{/* 아이콘 줄 '내 각'이 여기로 내려온다 */}
|
||||
<View onLayout={(e) => (myGakY.current = e.nativeEvent.layout.y)}>
|
||||
<MyGakRow />
|
||||
</View>
|
||||
{/* 실패 안내는 여기 한 번만, 각 카드 스켈레톤과 같은 크기로 */}
|
||||
{stories.some((g) => g.active) ? (
|
||||
<GakCard items={stories} post={f?.gak_post} place={region.name.split(' ').at(-1)!} at={sloted ? `${PREVIEW[preview].label} 기준` : nowAt ? `${kst(nowAt).h}시 기준` : '오늘 기준'} />
|
||||
) : load === 'loading' ? (
|
||||
<PostCardSkel />
|
||||
) : (
|
||||
<StateBox load={load} onRetry={() => feed.refetch()} empty="오늘 계산된 각이 없어요." hold={<PostCardSkel />} 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"
|
||||
/>
|
||||
)}
|
||||
{/* 단풍철엔 단풍 지도를 포스트 맨 앞에 */}
|
||||
{load !== 'loading' && posts.length > 0 && <FoliageCard post={f?.foliage_post} />}
|
||||
{posts.map((p, i) => {
|
||||
const t = talkAt(i);
|
||||
const ev = eventNo.get(p.post_id);
|
||||
return (
|
||||
<Fragment key={p.post_id}>
|
||||
{ev ? (
|
||||
<View onLayout={(e) => seen.at('event', ev)(e.nativeEvent.layout)}>
|
||||
<PostCard post={p} />
|
||||
</View>
|
||||
) : (
|
||||
<PostCard post={p} />
|
||||
)}
|
||||
{bandAt.find(([at]) => at === i + 1)?.[1]}
|
||||
{t && (
|
||||
<View onLayout={(e) => seen.at('talk', (i + 1) / TALK_EVERY)(e.nativeEvent.layout)}>
|
||||
<TalkPost key={`${t.talk_id}:${t.liked}:${t.like_count}`} t={t} />
|
||||
</View>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
{/* 포스트가 모자라 끼울 자리가 없던 사람 글은 맨 뒤에 */}
|
||||
{feed.isSuccess &&
|
||||
talks.slice(talkFrom).map((t, n) => (
|
||||
<View key={t.talk_id} onLayout={(e) => seen.at('talk', talkFrom + n + 1)(e.nativeEvent.layout)}>
|
||||
<TalkPost t={t} />
|
||||
</View>
|
||||
))}
|
||||
{feed.isSuccess && bandAt.filter(([at]) => at > posts.length).map(([at, node]) => <Fragment key={at}>{node}</Fragment>)}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
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, View } from 'react-native';
|
||||
import { Text } from '@/components/text';
|
||||
|
||||
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 { useShare } 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 shareView = useShare();
|
||||
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>
|
||||
);
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
import { headline, md, type Kind, type Spot } from '@nalssigak/shared/lib/foliage';
|
||||
import { useLocalSearchParams } from 'expo-router';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Pressable, ScrollView, useWindowDimensions, View } from 'react-native';
|
||||
import { useCSSVariable } from 'uniwind';
|
||||
|
||||
import { FoliageMap, type FoliageMapHandle } from '@/components/foliage/foliage-map';
|
||||
import { ChosenBar, SpotList } from '@/components/foliage/spot-list';
|
||||
import { SendIcon } from '@/components/post/icons';
|
||||
import { ScreenHeader } from '@/components/screen-header';
|
||||
import { Text } from '@/components/text';
|
||||
import { Chips, Ic } from '@/components/ui';
|
||||
import { track } from '@/lib/analytics';
|
||||
import { useFoliage } from '@/lib/foliage';
|
||||
import { useShare } from '@/lib/share-image';
|
||||
import { SITE_URL } from '@/lib/site';
|
||||
|
||||
type Filter = 'all' | Kind;
|
||||
const FILTERS: [Filter, string][] = [
|
||||
['all', '전체'],
|
||||
['maple', '단풍'],
|
||||
['ginkgo', '은행'],
|
||||
];
|
||||
|
||||
/** 단풍 지도: 명소 67곳을 지도에서 확대해 보고 아래 목록으로 고른다. ?spot= 으로 열면 그 명소로 (웹 FoliagePage) */
|
||||
export default function FoliageScreen() {
|
||||
const params = useLocalSearchParams<{ spot?: string }>();
|
||||
const { today, spots } = useFoliage();
|
||||
const [filter, setFilter] = useState<Filter>('all');
|
||||
const [sel, setSel] = useState<string | null>(params.spot ?? null);
|
||||
const mapRef = useRef<FoliageMapHandle>(null);
|
||||
const shotRef = useRef<View>(null);
|
||||
const shareView = useShare();
|
||||
const ink = String(useCSSVariable('--color-ink'));
|
||||
const { width, height: winH } = useWindowDimensions();
|
||||
// 지도는 스크롤 밖에 고정: 가로만큼 정사각형, 화면이 낮으면 화면 높이의 45%까지
|
||||
const mapH = Math.max(280, Math.min(width * 1.05, winH * 0.45, 560));
|
||||
const shown = useMemo(() => spots.filter((m) => filter === 'all' || m.kind === filter), [spots, filter]);
|
||||
|
||||
useEffect(() => track('foliage_open', {}), []);
|
||||
useEffect(() => {
|
||||
if (sel) track('foliage_spot', { spot_name: sel, from: 'page' });
|
||||
}, [sel]);
|
||||
|
||||
const chosen = spots.find((m) => m.name === sel);
|
||||
const peakCount = spots.filter((m) => m.stage === 'peak').length;
|
||||
const title = headline(spots);
|
||||
const pick = (m: Spot) => {
|
||||
setSel(m.name);
|
||||
mapRef.current?.focus(m);
|
||||
};
|
||||
const share = () => void shareView(shotRef, { title: chosen ? `${chosen.name} 단풍` : '단풍 지도', message: `${title} · 날씨각 단풍 지도 ${SITE_URL}/foliage` });
|
||||
|
||||
return (
|
||||
<View className="flex-1">
|
||||
<ScreenHeader
|
||||
title="단풍 지도"
|
||||
right={
|
||||
<Pressable onPress={share} hitSlop={8} accessibilityRole="button" accessibilityLabel="단풍 지도 보내기" className="size-10 items-center justify-center">
|
||||
<SendIcon size={24} color={ink} />
|
||||
</Pressable>
|
||||
}
|
||||
/>
|
||||
<View className="px-4 pt-1 pb-2">
|
||||
<View className="flex-row items-center gap-1">
|
||||
<Ic name="maple" size={16} />
|
||||
<Text className="text-[13px] font-extrabold text-ink2">{`단풍 지도 · ${md(today)}`}</Text>
|
||||
</View>
|
||||
<Text className="mt-0.5 font-jua text-[24px] leading-tight text-ink">{title}</Text>
|
||||
</View>
|
||||
{/* 보내기는 지금 보이는 지도 그대로 찍어 보낸다 (웹은 따로 만든 공유 그림) */}
|
||||
<View ref={shotRef} collapsable={false}>
|
||||
<FoliageMap ref={mapRef} spots={shown} sel={sel} onSelect={setSel} height={mapH} />
|
||||
</View>
|
||||
<ChosenBar chosen={chosen} legendColor={ink} />
|
||||
<ScrollView className="flex-1" contentContainerClassName="pb-8">
|
||||
<Chips items={FILTERS} value={filter} onChange={setFilter} />
|
||||
<SpotList spots={shown} sel={sel} onPick={pick} />
|
||||
<Text className="px-5 pt-4 text-[11.5px] leading-relaxed font-semibold text-ink3">
|
||||
{`출처: 산림청 2026 단풍절정 예측 · 잎 절반이 물든 때를 절정으로, 그 2주 전부터 첫 단풍으로 봐요${peakCount ? ` · 지금 절정 ${peakCount}곳` : ''}`}
|
||||
</Text>
|
||||
</ScrollView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
import { getAccessToken } from '@nalssigak/shared/api/auth';
|
||||
import { router } from 'expo-router';
|
||||
import { useRef, useState } from 'react';
|
||||
import { ActivityIndicator, Linking, View } from 'react-native';
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
import { WebView, type WebViewMessageEvent } from 'react-native-webview';
|
||||
|
||||
import { ScreenHeader } from '@/components/screen-header';
|
||||
import { Text } from '@/components/text';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { SITE_URL } from '@/lib/site';
|
||||
|
||||
const SITE_ORIGIN = new URL(SITE_URL).origin;
|
||||
|
||||
/** 게임 웹뷰는 날씨각 사이트 안에서만 움직인다. 다른 주소(외부 링크)는 휴대폰 브라우저로 연다 */
|
||||
function stayOnSite(url: string) {
|
||||
if (url.startsWith(`${SITE_ORIGIN}/`) || url === SITE_ORIGIN || url === 'about:blank') return true;
|
||||
if (/^https?:/.test(url)) Linking.openURL(url).catch((e: unknown) => console.warn('[game] 외부 주소를 열지 못함', url, e));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 웹 페이지가 뜨기 전에 넣는 스크립트: 앱의 지역·로그인을 웹 저장소에 옮기고,
|
||||
* 게임 화면을 떠나는 이동(뒤로 버튼)과 '로그인하면 …' 버튼은 앱으로 알린다 (웹 구글 로그인은 앱 안 웹뷰에서 막힌다).
|
||||
* 갱신 토큰은 넘기지 않는다: 웹이 갱신하면 앱이 가진 갱신 토큰이 쓸모없어질 수 있다.
|
||||
* 날씨각 사이트에서 열렸을 때만 토큰을 넣는다 (다른 곳으로 넘어가면 아무것도 하지 않는다).
|
||||
*/
|
||||
function bridge(region: unknown, token: string | null) {
|
||||
return `(function () {
|
||||
if (location.origin !== ${JSON.stringify(SITE_ORIGIN)}) return;
|
||||
try {
|
||||
localStorage.setItem('nalssigak.b.region', ${JSON.stringify(JSON.stringify(region))});
|
||||
${token ? `localStorage.setItem('nalssigak.accessToken', ${JSON.stringify(token)});` : `localStorage.removeItem('nalssigak.accessToken');`}
|
||||
localStorage.removeItem('nalssigak.refreshToken');
|
||||
} catch (e) {}
|
||||
var post = function (t) { window.ReactNativeWebView.postMessage(t); };
|
||||
var check = function () { if (location.pathname !== '/game') post('leave'); };
|
||||
var push = history.pushState, replace = history.replaceState;
|
||||
history.pushState = function () { push.apply(this, arguments); check(); };
|
||||
history.replaceState = function () { replace.apply(this, arguments); check(); };
|
||||
window.addEventListener('popstate', check);
|
||||
document.addEventListener('click', function (e) {
|
||||
var b = e.target && e.target.closest && e.target.closest('button');
|
||||
if (b && b.textContent && b.textContent.trim().indexOf('로그인') === 0) { e.preventDefault(); e.stopPropagation(); post('login'); }
|
||||
}, true);
|
||||
})();
|
||||
true;`;
|
||||
}
|
||||
|
||||
/** 구름 합치기 게임: 웹 /game 을 그대로 띄운다 (물리 엔진·캔버스라 웹과 같은 화면, 사용자 결정 11/04) */
|
||||
export default function GameScreen() {
|
||||
const { region } = useRegion();
|
||||
const { loggedIn } = useAuth();
|
||||
const { open } = useSheet();
|
||||
const { top, bottom } = useSafeAreaInsets();
|
||||
const [failed, setFailed] = useState(false);
|
||||
const left = useRef(false);
|
||||
|
||||
const onMessage = (e: WebViewMessageEvent) => {
|
||||
if (e.nativeEvent.data === 'leave' && !left.current) {
|
||||
left.current = true;
|
||||
if (router.canGoBack()) router.back();
|
||||
else router.replace('/');
|
||||
}
|
||||
if (e.nativeEvent.data === 'login') open({ type: 'login' });
|
||||
};
|
||||
|
||||
if (failed)
|
||||
return (
|
||||
<View className="flex-1">
|
||||
<ScreenHeader title="구름 합치기" />
|
||||
<Text className="mx-6 mt-10 text-center text-[15px] font-bold text-ink2">게임을 불러오지 못했어요. 인터넷 연결을 확인하고 다시 들어와 주세요.</Text>
|
||||
</View>
|
||||
);
|
||||
|
||||
return (
|
||||
<View className="flex-1 bg-[#cfe9ff]" style={{ paddingTop: top, paddingBottom: bottom }}>
|
||||
{/* 로그인하면 토큰을 다시 넣어야 해서 로그인 여부로 새로 띄운다 */}
|
||||
<WebView
|
||||
key={`${region.code}:${loggedIn}`}
|
||||
source={{ uri: `${SITE_URL}/game` }}
|
||||
originWhitelist={[SITE_ORIGIN]}
|
||||
onShouldStartLoadWithRequest={(req) => stayOnSite(req.url)}
|
||||
injectedJavaScriptBeforeContentLoaded={bridge(region, getAccessToken())}
|
||||
onMessage={onMessage}
|
||||
onError={() => setFailed(true)}
|
||||
startInLoadingState
|
||||
renderLoading={() => <ActivityIndicator style={{ position: 'absolute', top: '45%', alignSelf: 'center' }} />}
|
||||
overScrollMode="never"
|
||||
bounces={false}
|
||||
setSupportMultipleWindows={false}
|
||||
style={{ backgroundColor: 'transparent' }}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* 화면은 _layout.tsx 의 웹 셸이 다 그린다. 이 파일은 Expo Router 가 '/' 경로를 알게 하려고 둔다.
|
||||
* 경로 파일이 하나도 없으면 Expo Router 가 우리 _layout 대신 자기 안내 화면(_sitemap)을 띄우다 앱이 죽는다.
|
||||
*/
|
||||
export default function Index() {
|
||||
return null;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
import { useLocalSearchParams } from 'expo-router';
|
||||
import { useMemo, useRef, useState } from 'react';
|
||||
import { ScrollView, View } from 'react-native';
|
||||
|
||||
import { BirthForm } from '@/components/saju/birth-form';
|
||||
import { OpenTarget } from '@/components/saju/parts';
|
||||
import { Reading } from '@/components/saju/reading';
|
||||
import { ScreenHeader } from '@/components/screen-header';
|
||||
import { Text } from '@/components/text';
|
||||
import { useAccountBirth, useBirth } from '@/lib/saju-birth';
|
||||
|
||||
type Pos = { base: number | null; panel: number | null; done: boolean };
|
||||
|
||||
function tryScroll(p: Pos, view: ScrollView | null) {
|
||||
if (p.done || p.base == null || p.panel == null || !view) return;
|
||||
p.done = true;
|
||||
view.scrollTo({ y: Math.max(0, p.base + p.panel - 12), animated: true });
|
||||
}
|
||||
|
||||
/** 날씨 사주(/saju): 오늘 점수와 할 일, 내 기운, 레벨로 열리는 칸. ?open=saju_love 처럼 열면 그 칸으로 내려간다 (웹 SajuPage, #hash) */
|
||||
export default function SajuScreen() {
|
||||
const params = useLocalSearchParams<{ open?: string }>();
|
||||
const birth = useBirth();
|
||||
const loading = useAccountBirth();
|
||||
const [editing, setEditing] = useState(false);
|
||||
const scroll = useRef<ScrollView>(null);
|
||||
// 결과 묶음의 위치와 그 안에서 연 칸의 위치를 둘 다 알아야 내려갈 수 있다 (어느 쪽이 먼저 잡힐지 모른다)
|
||||
const pos = useRef<Pos>({ base: null, panel: null, done: false });
|
||||
const target = useMemo(
|
||||
() => ({
|
||||
id: params.open,
|
||||
onLayout: (y: number) => {
|
||||
pos.current.panel = y;
|
||||
tryScroll(pos.current, scroll.current);
|
||||
},
|
||||
}),
|
||||
[params.open],
|
||||
);
|
||||
|
||||
return (
|
||||
<View className="flex-1">
|
||||
<ScreenHeader title="날씨 사주" />
|
||||
<ScrollView ref={scroll} contentContainerClassName="pb-8" keyboardShouldPersistTaps="handled">
|
||||
{loading && !birth ? (
|
||||
<Text className="px-4 py-16 text-center font-semibold text-ink2">내 생년월일을 불러오는 중이에요…</Text>
|
||||
) : !birth || editing ? (
|
||||
<BirthForm initial={birth} onDone={() => setEditing(false)} onCancel={birth ? () => setEditing(false) : undefined} />
|
||||
) : (
|
||||
<View
|
||||
onLayout={(e) => {
|
||||
pos.current.base = e.nativeEvent.layout.y;
|
||||
tryScroll(pos.current, scroll.current);
|
||||
}}
|
||||
>
|
||||
<OpenTarget value={target}>
|
||||
<Reading birth={birth} onEdit={() => setEditing(true)} />
|
||||
</OpenTarget>
|
||||
</View>
|
||||
)}
|
||||
</ScrollView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
import { listShortsOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import type { ShortItem } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { Image } from 'expo-image';
|
||||
import { router, useLocalSearchParams } from 'expo-router';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { FlatList, Pressable, View, type ViewToken } from 'react-native';
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
import Svg, { Path } from 'react-native-svg';
|
||||
|
||||
import { ShortPlayer, type PlayerHandle } from '@/components/shorts/player';
|
||||
import { thumb } from '@/components/shorts/rail';
|
||||
import { Text } from '@/components/text';
|
||||
import { track } from '@/lib/analytics';
|
||||
|
||||
const BAR = 48;
|
||||
|
||||
/** 쇼츠 화면: 그 영상부터 위아래로 넘겨 본다. 보이는 영상과 앞뒤만 소리 없이 미리 띄우고, 누르면 소리 켜기·끄기 (웹 ShortsPage) */
|
||||
export default function ShortsScreen() {
|
||||
const { id } = useLocalSearchParams<{ id?: string }>();
|
||||
const q = useQuery(listShortsOptions());
|
||||
const { top, bottom } = useSafeAreaInsets();
|
||||
// 처음 들어온 영상만 시작점으로 쓴다
|
||||
const [firstId] = useState(id);
|
||||
const listed = q.data?.items ?? [];
|
||||
const items: ShortItem[] = firstId && listed.length && !listed.some((s) => s.id === firstId) ? [{ id: firstId, title: '' }, ...listed] : listed;
|
||||
const start = Math.max(0, items.findIndex((s) => s.id === firstId));
|
||||
const [at, setAt] = useState(start);
|
||||
const [sound, setSound] = useState(false);
|
||||
const [ready, setReady] = useState<ReadonlySet<number>>(new Set());
|
||||
const [box, setBox] = useState({ w: 0, h: 0 });
|
||||
const players = useRef(new Map<number, PlayerHandle>());
|
||||
const soundRef = useRef(false);
|
||||
const atRef = useRef(start);
|
||||
|
||||
useEffect(() => {
|
||||
if (firstId) track('shorts_open', { video_id: firstId });
|
||||
}, [firstId]);
|
||||
|
||||
// 넘어온 영상만 처음부터 다시 틀고 소리를 맞춘다. 앞뒤는 소리만 끈다 (멈추면 유튜브 버튼이 떠서 멈추지 않는다)
|
||||
useEffect(() => {
|
||||
for (const [i, p] of players.current) {
|
||||
if (i === at) {
|
||||
p.command('seekTo', [0, true]);
|
||||
p.command(soundRef.current ? 'unMute' : 'mute');
|
||||
p.command('playVideo');
|
||||
} else p.command('mute');
|
||||
}
|
||||
}, [at]);
|
||||
|
||||
// FlatList 는 이 함수가 바뀌면 안 되어 처음 한 번만 만든다
|
||||
const [onViewable] = useState(() => ({ viewableItems }: { viewableItems: ViewToken<ShortItem>[] }) => {
|
||||
const i = viewableItems[0]?.index;
|
||||
if (i == null || i === atRef.current) return;
|
||||
atRef.current = i;
|
||||
setAt(i);
|
||||
const s = viewableItems[0].item;
|
||||
track('shorts_view', { video_id: s.id, index: i });
|
||||
});
|
||||
|
||||
const toggleSound = () => {
|
||||
const on = !soundRef.current;
|
||||
soundRef.current = on;
|
||||
setSound(on);
|
||||
track('shorts_sound', { on });
|
||||
players.current.get(at)?.command(on ? 'unMute' : 'mute');
|
||||
};
|
||||
|
||||
const close = () => (router.canGoBack() ? router.back() : router.replace('/'));
|
||||
// 9:16 을 칸 안에 맞춘다
|
||||
const w = Math.min(box.w, (box.h * 9) / 16);
|
||||
const h = (w * 16) / 9;
|
||||
|
||||
return (
|
||||
<View className="flex-1 bg-[#1d2233]" style={{ paddingTop: top, paddingBottom: bottom }}>
|
||||
{!!items[at] && <Image source={{ uri: thumb(items[at].id) }} style={{ position: 'absolute', inset: 0, opacity: 0.7, transform: [{ scale: 1.25 }] }} blurRadius={40} contentFit="cover" />}
|
||||
<View className="absolute inset-0 bg-black/35" />
|
||||
<View className="flex-row items-center justify-between px-3" style={{ height: BAR }}>
|
||||
<Pressable onPress={close} hitSlop={8} accessibilityRole="button" accessibilityLabel="닫기" className="size-9 items-center justify-center rounded-full bg-white/15">
|
||||
<Svg viewBox="0 0 24 24" width={18} height={18} fill="none" stroke="#fff" strokeWidth={2.4} strokeLinecap="round">
|
||||
<Path d="M6 6l12 12M18 6L6 18" />
|
||||
</Svg>
|
||||
</Pressable>
|
||||
<Pressable onPress={toggleSound} accessibilityRole="button" accessibilityState={{ selected: sound }} className="h-9 justify-center rounded-full bg-white/15 px-3.5">
|
||||
<Text className="text-[13px] font-bold text-white">{sound ? '소리 끄기' : '소리 켜기'}</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
<View className="flex-1" onLayout={(e) => setBox({ w: e.nativeEvent.layout.width, h: e.nativeEvent.layout.height })}>
|
||||
{box.h > 0 && items.length > 0 && (
|
||||
<FlatList
|
||||
data={items}
|
||||
keyExtractor={(s) => s.id}
|
||||
pagingEnabled
|
||||
showsVerticalScrollIndicator={false}
|
||||
initialScrollIndex={start}
|
||||
getItemLayout={(_, i) => ({ length: box.h, offset: box.h * i, index: i })}
|
||||
onViewableItemsChanged={onViewable}
|
||||
viewabilityConfig={{ itemVisiblePercentThreshold: 60 }}
|
||||
windowSize={3}
|
||||
renderItem={({ item: s, index: i }) => (
|
||||
<View style={{ height: box.h }} className="items-center justify-center">
|
||||
<View style={{ width: w, height: h }}>
|
||||
<Image source={{ uri: thumb(s.id) }} style={{ position: 'absolute', inset: 0 }} contentFit="cover" />
|
||||
{/* 릴스처럼 앞뒤 영상을 소리 없이 미리 받아 둔다. 첫 장면 전엔 표지가 보이게 숨긴다 */}
|
||||
{Math.abs(i - at) <= 1 && (
|
||||
<View pointerEvents="none" style={{ position: 'absolute', inset: 0, opacity: ready.has(i) ? 1 : 0 }}>
|
||||
<ShortPlayer
|
||||
id={s.id}
|
||||
ref={(p) => {
|
||||
if (p) players.current.set(i, p);
|
||||
else players.current.delete(i);
|
||||
}}
|
||||
onPlaying={() => setReady((r) => (r.has(i) ? r : new Set(r).add(i)))}
|
||||
/>
|
||||
</View>
|
||||
)}
|
||||
{/* 누르면 소리 켜기·끄기, 위아래로 밀면 목록이 넘어간다 */}
|
||||
<Pressable onPress={toggleSound} accessibilityLabel={sound ? '소리 끄기' : '소리 켜기'} style={{ position: 'absolute', inset: 0 }} />
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
// 아이콘 줄 '쇼츠'(/shorts)는 첫 영상부터
|
||||
export { default } from './[id]';
|
||||
@@ -1,71 +0,0 @@
|
||||
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 = (
|
||||
<View>
|
||||
<Sec title="동네 사람들 글" sub="가까운 동네 글부터 보여요" />
|
||||
<View accessibilityRole="tablist" accessibilityLabel="글 주제">
|
||||
<ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerClassName="gap-1.5 px-4 pb-1">
|
||||
{tabs.map(([k, label]) => (
|
||||
<Pressable key={label} onPress={() => go(k)} accessibilityRole="tab" accessibilityState={{ selected: tab === k }} className={`rounded-full px-3 py-1.5 ${tab === k ? 'bg-ink-btn' : 'bg-card'}`}>
|
||||
<Text className={`text-[13px] font-extrabold ${tab === k ? 'text-white' : 'text-ink2'}`}>{label}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</ScrollView>
|
||||
</View>
|
||||
<Composer />
|
||||
{tab === 'mine' && !loggedIn ? (
|
||||
<Text className="mx-4 mt-6 text-center text-[14px] font-semibold text-ink3">
|
||||
로그인하면 내가 쓴 글을 모아 볼 수 있어요.{' '}
|
||||
<Text onPress={() => open({ type: 'login' })} className="font-extrabold text-orange">
|
||||
로그인
|
||||
</Text>
|
||||
</Text>
|
||||
) : (
|
||||
loaded && !talks.length && <Text className="mx-4 mt-6 text-center text-[14px] font-semibold text-ink3">{tab === 'mine' ? '아직 쓴 글이 없어요. 위 칸에서 첫 글을 써 주세요.' : '아직 이 주제 글이 없어요. 위 칸에서 첫 글을 써 주세요.'}</Text>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
|
||||
return (
|
||||
<View className="flex-1">
|
||||
<ScreenHeader title="동네 이야기" />
|
||||
<FlatList
|
||||
data={talks}
|
||||
keyExtractor={(t) => `${t.talk_id}:${t.liked}:${t.like_count}`}
|
||||
renderItem={({ item }) => <TalkCard t={item} />}
|
||||
ListHeaderComponent={head}
|
||||
contentContainerClassName="pb-8"
|
||||
keyboardShouldPersistTaps="handled"
|
||||
// 목록 끝이 가까워지면 다음 쪽을 받는다 (글이 많아도 버튼 없이 이어서)
|
||||
onEndReached={() => more && loadMore()}
|
||||
onEndReachedThreshold={1}
|
||||
refreshControl={tab !== 'mine' ? <RefreshControl refreshing={topicList.refetching} onRefresh={() => topicList.refetch()} /> : undefined}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user