feat: 앱 나머지 화면 이전 — 게시물 카드·시트·각/노을/주말/계절 탭·움직임
- 게시물 카드 슬라이드 7종, 좋아요·댓글, 텍스트 공유 - 시트 7종(RN Modal), 위 막대 지역·계절·로그인/아바타 - 각·노을·주말·행사·계절·상식 탭, 당겨서 새로고침 - 히어로 해·구름·비·눈 움직임, 스켈레톤 깜빡임, 첫 로딩 덮개, 하늘색 전환
This commit is contained in:
1 parent
28ff032160
commit
f71dd2cebb
33 files changed
+2786
-75
No files matched your search
@@ -11,6 +11,7 @@ import { View } from 'react-native';
|
||||
import '@/global.css';
|
||||
import { SkyBg } from '@/components/sky-bg';
|
||||
import { TabBar } from '@/components/tab-bar';
|
||||
import { FirstLoad } from '@/components/first-load';
|
||||
import { SheetProvider } from '@/components/sheets';
|
||||
import { TopBar } from '@/components/top-bar';
|
||||
import { AuthProvider } from '@/lib/auth';
|
||||
@@ -34,6 +35,7 @@ function Shell() {
|
||||
<Tabs.Screen name="week" />
|
||||
<Tabs.Screen name="season" />
|
||||
</Tabs>
|
||||
<FirstLoad />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
+62
-3
@@ -1,5 +1,64 @@
|
||||
import { ComingSoon } from '@/components/coming-soon';
|
||||
import { listArticlesOptions, listIndicesOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { ArticleCategory, IndexCategory } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { kst, loadOf, seasonOf } from '@nalssigak/shared/lib';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useState } from 'react';
|
||||
import { Pressable, RefreshControl, ScrollView, Text, View } from 'react-native';
|
||||
|
||||
export default function Screen() {
|
||||
return <ComingSoon title="오늘의 각" />;
|
||||
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위를 아직 못 정했어요." />}
|
||||
<Chips items={CATS} value={cat} onChange={setCat} />
|
||||
{load === 'loading' ? (
|
||||
<GridSkel />
|
||||
) : !items.length ? (
|
||||
// 실패 안내·다시 시도는 위 받침대 자리에 한 번만
|
||||
<StateBox load="ready" empty={load === 'ready' ? '이 분야는 오늘 계산된 각이 없어요.' : '각 목록을 불러오지 못했어요.'} />
|
||||
) : (
|
||||
<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>
|
||||
);
|
||||
}
|
||||
@@ -2,8 +2,10 @@ import { getFeedOptions, getWeatherTodayOptions } from '@nalssigak/shared/api/cl
|
||||
import { kst, loadOf } from '@nalssigak/shared/lib';
|
||||
import { atSlot, PREVIEW } from '@nalssigak/shared/lib/today';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { Fragment, type ReactNode } from 'react';
|
||||
import { RefreshControl, ScrollView } from 'react-native';
|
||||
|
||||
import { PostCard, PostCardSkel } from '@/components/post/post-card';
|
||||
import { Hero } from '@/components/today/hero';
|
||||
import { EventsBand, SeasonBand, Stories, StoriesSkel, TopBand } from '@/components/today/rails';
|
||||
import { Sec, StateBox } from '@/components/ui';
|
||||
@@ -16,6 +18,7 @@ export default function TodayScreen() {
|
||||
const today = useQuery(getWeatherTodayOptions({ query: { region: region.code } }));
|
||||
const { preview } = useSky();
|
||||
const f = feed.data;
|
||||
const posts = f?.posts ?? [];
|
||||
const stories = atSlot(f?.stories ?? [], preview);
|
||||
const sloted = preview != null && stories !== f?.stories;
|
||||
const bands = f?.bands;
|
||||
@@ -23,14 +26,33 @@ export default function TodayScreen() {
|
||||
const load = loadOf(feed);
|
||||
const refresh = () => Promise.all([feed.refetch(), today.refetch()]);
|
||||
|
||||
// 웹처럼 3·6·9번째 글 뒤에 띠를 넣고, 글이 모자라면 남은 띠는 맨 뒤에 붙인다
|
||||
const bandAt: [number, ReactNode][] = [
|
||||
[3, bands?.events?.length ? <EventsBand events={bands.events} /> : null],
|
||||
[6, bands?.top5?.length ? <TopBand items={sloted ? stories.filter((g) => g.active) : bands.top5} sub={sloted ? `${PREVIEW[preview].label} 기준` : nowAt ? `${kst(nowAt).h}시 기준` : '오늘 기준'} /> : null],
|
||||
[9, bands?.season?.length ? <SeasonBand news={bands.season} /> : null],
|
||||
];
|
||||
|
||||
return (
|
||||
// 지역마다 새로 그려 넘긴 슬라이드 위치가 남지 않게 한다
|
||||
<ScrollView key={region.code} contentContainerClassName="pb-6" refreshControl={<RefreshControl refreshing={feed.isRefetching && !feed.isPlaceholderData} onRefresh={refresh} />} style={{ opacity: feed.isPlaceholderData ? 0.6 : 1 }}>
|
||||
<Hero hero={f?.hero} today={today.data} ranked={stories} feedLoad={load} todayLoad={loadOf(today)} />
|
||||
<Sec title="오늘의 각" sub="누르면 계산 근거를 보여 줘요" more="/gak" />
|
||||
{stories.length ? <Stories items={stories} /> : load === 'loading' ? <StoriesSkel /> : <StateBox load={load} onRetry={() => feed.refetch()} empty="오늘 계산된 각이 없어요." />}
|
||||
{!!bands?.events?.length && <EventsBand events={bands.events} />}
|
||||
{!!bands?.top5?.length && <TopBand items={sloted ? stories.filter((g) => g.active) : bands.top5} sub={sloted ? `${PREVIEW[preview].label} 기준` : nowAt ? `${kst(nowAt).h}시 기준` : '오늘 기준'} />}
|
||||
{!!bands?.season?.length && <SeasonBand news={bands.season} />}
|
||||
{load === 'loading' && (
|
||||
<>
|
||||
<PostCardSkel />
|
||||
<PostCardSkel />
|
||||
</>
|
||||
)}
|
||||
{load !== 'loading' && !posts.length && <StateBox load={load === 'ready' ? 'ready' : load} onRetry={() => feed.refetch()} empty="오늘 올라온 글이 아직 없어요." />}
|
||||
{posts.map((p, i) => (
|
||||
<Fragment key={p.post_id}>
|
||||
<PostCard post={p} />
|
||||
{bandAt.find(([at]) => at === i + 1)?.[1]}
|
||||
</Fragment>
|
||||
))}
|
||||
{feed.isSuccess && bandAt.filter(([at]) => at > posts.length).map(([at, node]) => <Fragment key={at}>{node}</Fragment>)}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,45 @@
|
||||
import { ComingSoon } from '@/components/coming-soon';
|
||||
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';
|
||||
|
||||
export default function Screen() {
|
||||
return <ComingSoon title="계절·상식" />;
|
||||
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="이번 주 특집이 아직 없어요." />}
|
||||
<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="읽을거리가 아직 없어요." />}
|
||||
{list.map((a) => (
|
||||
<ArticleRow key={a.article_id} article={a} onPress={() => open({ type: 'article', articleId: a.article_id })} />
|
||||
))}
|
||||
</View>
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
+79
-3
@@ -1,5 +1,81 @@
|
||||
import { ComingSoon } from '@/components/coming-soon';
|
||||
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';
|
||||
|
||||
export default function Screen() {
|
||||
return <ComingSoon title="노을" />;
|
||||
import { DayTiles, Li, LiSkel, ScoreHelp, SkyHero, Timeline } from '@/components/sky/parts';
|
||||
import { Sec, StateBox } from '@/components/ui';
|
||||
import { useRegion } from '@/lib/region';
|
||||
|
||||
const THREE = [0, 1, 2];
|
||||
const RANK_SKELS = Array.from({ length: 8 }, (_, i) => i);
|
||||
|
||||
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="오늘 노을 정보가 없어요." />
|
||||
</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' ? '노을 시간 정보가 없어요.' : '노을 시간을 불러오지 못했어요.'} />}
|
||||
{!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' ? '근처에 등록된 노을 명소가 없어요.' : '명소 정보를 불러오지 못했어요.'} />
|
||||
)}
|
||||
<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="순위가 아직 없어요." />
|
||||
)}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
+132
-3
@@ -1,5 +1,134 @@
|
||||
import { ComingSoon } from '@/components/coming-soon';
|
||||
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 { useState } from 'react';
|
||||
import { Pressable, RefreshControl, ScrollView, Share, Text, View } from 'react-native';
|
||||
|
||||
export default function Screen() {
|
||||
return <ComingSoon title="주말·행사" />;
|
||||
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 { 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 sendPlan = () => {
|
||||
if (!sel) return;
|
||||
const message = [`${sel.weekday}요일 일정 · ${region.name}`, sel.headline, sel.summary, sel.pick, `날씨각 ${SITE_URL}`].filter(Boolean).join('\n');
|
||||
Share.share({ message }).catch((e: unknown) => console.warn('일정 공유 실패', e));
|
||||
};
|
||||
|
||||
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="날씨가 아직 없어요." />
|
||||
)}
|
||||
{sel && <PickCard day={sel} />}
|
||||
{(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 안에 데이트 명소가 아직 없어요.' : '날씨를 불러오면 명소를 골라 드려요.'} />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<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="주말 예보가 아직 없어요." />
|
||||
)}
|
||||
<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 안에 열리는 행사가 아직 없어요. 다른 지역을 골라 보세요." />
|
||||
)}
|
||||
{/* 행사 수가 정해진 뒤에 붙여 목록이 늘어날 때 밀리지 않게 */}
|
||||
{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,11 +0,0 @@
|
||||
import { Text, View } from 'react-native';
|
||||
|
||||
/** 아직 옮기지 않은 탭 */
|
||||
export function ComingSoon({ title }: { title: string }) {
|
||||
return (
|
||||
<View className="flex-1 items-center justify-center gap-2">
|
||||
<Text className="font-jua text-[22px] text-ink">{title}</Text>
|
||||
<Text className="text-[13.5px] font-semibold text-ink2">앱으로 옮기는 중이에요</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import type { TimeKind } from '@nalssigak/shared/lib';
|
||||
import { useIsFetching } from '@tanstack/react-query';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { StyleSheet, Text, View } from 'react-native';
|
||||
import Animated, { cancelAnimation, Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withRepeat, withSequence, withTiming } from 'react-native-reanimated';
|
||||
|
||||
import { Ic } from '@/components/ui';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
// 덮개 색: 시간대별 하늘 맨 위 색을 반쯤 비치게
|
||||
const COVER: Record<TimeKind, string> = {
|
||||
morning: 'rgb(255 230 207 / 0.72)',
|
||||
day: 'rgb(214 235 255 / 0.72)',
|
||||
sunset: 'rgb(255 216 194 / 0.72)',
|
||||
night: 'rgb(14 20 51 / 0.72)',
|
||||
};
|
||||
|
||||
/** 캐릭터가 통통 뛴다 (웹 b-hop) */
|
||||
function Hop({ name }: { name: string }) {
|
||||
const reduce = useReducedMotion();
|
||||
const t = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
if (reduce) return;
|
||||
const ease = Easing.bezier(0.3, 0, 0.4, 1);
|
||||
t.value = withRepeat(withSequence(withTiming(1, { duration: 405, easing: ease }), withTiming(0, { duration: 495, easing: ease })), -1);
|
||||
return () => cancelAnimation(t);
|
||||
}, [reduce, t]);
|
||||
const style = useAnimatedStyle(() => ({
|
||||
transform: [{ translateY: -22 * t.value }, { scaleX: 1.06 - 0.09 * t.value }, { scaleY: 0.94 + 0.09 * t.value }],
|
||||
transformOrigin: 'bottom',
|
||||
}));
|
||||
return (
|
||||
<Animated.View style={style}>
|
||||
<Ic name={name} size={88} />
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 처음 들어올 때만: 첫 데이터를 다 받을 때까지 하늘 위에 캐릭터와 '날씨 불러오는 중…'. 한 번 사라지면 다시 안 뜬다 */
|
||||
export function FirstLoad() {
|
||||
const fetching = useIsFetching();
|
||||
const { kind } = useSky();
|
||||
const [started, setStarted] = useState(false);
|
||||
const [done, setDone] = useState(false);
|
||||
const [gone, setGone] = useState(false);
|
||||
// 받기 시작했다가 받는 게 없어지면 끝 (렌더 중에 바로 맞춘다)
|
||||
if (fetching > 0 && !started) setStarted(true);
|
||||
if (fetching === 0 && started && !done) setDone(true);
|
||||
// 느린 망에서도 10초 넘게 막지 않는다 (그 뒤는 화면 안 스켈레톤이 맡는다)
|
||||
useEffect(() => {
|
||||
const id = setTimeout(() => setDone(true), 10000);
|
||||
return () => clearTimeout(id);
|
||||
}, []);
|
||||
const shown = useSharedValue(1);
|
||||
useEffect(() => {
|
||||
if (!done) return;
|
||||
shown.value = withTiming(0, { duration: 400 });
|
||||
const id = setTimeout(() => setGone(true), 400);
|
||||
return () => clearTimeout(id);
|
||||
}, [done, shown]);
|
||||
const fade = useAnimatedStyle(() => ({ opacity: shown.value }));
|
||||
if (gone) return null;
|
||||
return (
|
||||
<Animated.View pointerEvents={done ? 'none' : 'auto'} accessibilityRole="progressbar" accessibilityLabel="날씨 불러오는 중" style={[StyleSheet.absoluteFill, { zIndex: 50, backgroundColor: COVER[kind] }, fade]}>
|
||||
<View className="flex-1 items-center justify-center gap-3">
|
||||
<Hop name={kind === 'night' ? 'bear' : 'rabbit'} />
|
||||
<Text className="font-jua text-[19px] text-ink">날씨 불러오는 중…</Text>
|
||||
</View>
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import type { IndexSummary } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { Ic, Skel } from '@/components/ui';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
|
||||
const CELL = 'w-[32%] items-center rounded-[22px] border-b-[5px] border-shade bg-card px-1.5 pt-3 pb-2.5';
|
||||
const SKELS = Array.from({ length: 9 }, (_, i) => i);
|
||||
|
||||
export function GridSkel() {
|
||||
return (
|
||||
<View className="flex-row flex-wrap justify-between gap-y-2 p-3">
|
||||
{SKELS.map((i) => (
|
||||
<View key={i} className={`${CELL} gap-1.5`}>
|
||||
<View className="size-[50px] rounded-full bg-skel" />
|
||||
<Skel className="w-14" />
|
||||
<Skel className="h-5 w-8" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 3칸 바둑판. 지금 시간대가 아니거나 제철이 아닌 각은 흐리게 */
|
||||
export function GakGrid({ items, dim }: { items: IndexSummary[]; dim: boolean }) {
|
||||
const { open } = useSheet();
|
||||
return (
|
||||
<View className="flex-row flex-wrap gap-y-2 p-3" style={{ columnGap: '2%', opacity: dim ? 0.6 : 1 }}>
|
||||
{items.map((g) => (
|
||||
<Pressable
|
||||
key={g.index_id}
|
||||
onPress={() => open({ type: 'gak', indexId: g.index_id })}
|
||||
accessibilityLabel={g.active ? `${g.rank}위 ${g.name} ${g.score}점` : `${g.name}, ${g.in_season === false ? '제철 아님' : '지금 시간대 아님'}`}
|
||||
className={`${CELL} ${g.active ? '' : 'opacity-55'}`}
|
||||
>
|
||||
{g.active && <Text className="absolute top-[7px] left-[9px] font-jua text-[13px] text-ink3">{g.rank}</Text>}
|
||||
{g.season && <Text className="absolute top-2 right-2 text-[10.5px] font-extrabold text-[#1f9d62]">{g.season}</Text>}
|
||||
<Ic name={g.icon} size={50} />
|
||||
<Text numberOfLines={1} className="mt-1 font-jua text-[15px] text-ink">
|
||||
{g.name}
|
||||
</Text>
|
||||
{g.active ? (
|
||||
<Text className={`font-bagel text-[22px] leading-[24px] ${g.score < 50 ? 'text-ink3' : 'text-orange'}`}>{g.score}</Text>
|
||||
) : (
|
||||
<Text className="py-1 text-[12px] leading-[14px] font-extrabold text-ink3">{g.in_season === false ? '제철 아님' : '지금 아님'}</Text>
|
||||
)}
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import type { IndexSummary } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { MEDALS } from '@nalssigak/shared/lib';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { Ic, Skel } from '@/components/ui';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
// 가운데가 높은 3칸: 2위 · 1위 · 3위
|
||||
const ORDER = [1, 0, 2] as const;
|
||||
const FLEX = [1.15, 1, 1];
|
||||
|
||||
/** 1~3위 받침대와 같은 칸의 스켈레톤 */
|
||||
export function PodiumSkel() {
|
||||
return (
|
||||
<View className="flex-row gap-1.5 px-3 pt-3">
|
||||
{ORDER.map((k) => (
|
||||
<View key={k} style={{ flex: FLEX[k] }} className={`items-center gap-1.5 rounded-3xl border-b-[6px] border-shade bg-card px-1.5 ${k === 0 ? 'py-4' : 'mt-6 py-3'}`}>
|
||||
<View className={`aspect-square rounded-full bg-skel ${k === 0 ? 'w-20' : 'w-[62px]'}`} />
|
||||
<Skel className="w-16" />
|
||||
<Skel className="h-6 w-10" />
|
||||
<Skel className="w-full" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function Podium({ top, dim }: { top: IndexSummary[]; dim: boolean }) {
|
||||
const { open } = useSheet();
|
||||
const { kind } = useSky();
|
||||
return (
|
||||
<View className="flex-row gap-1.5 px-3 pt-3" style={{ opacity: dim ? 0.6 : 1 }}>
|
||||
{ORDER.map((k) => {
|
||||
const g = top[k];
|
||||
return (
|
||||
<Pressable key={g.index_id} style={{ flex: FLEX[k] }} onPress={() => open({ type: 'gak', indexId: g.index_id })} className={`items-center overflow-hidden rounded-3xl border-b-[6px] border-shade bg-card px-1.5 ${k === 0 ? 'py-4' : 'mt-6 py-3'}`}>
|
||||
{k === 0 && kind !== 'night' && <LinearGradient colors={['#fff1c4', '#ffffff']} style={{ position: 'absolute', inset: 0 }} />}
|
||||
<View>
|
||||
<Ic name={g.icon} size={k === 0 ? 80 : 62} />
|
||||
<Ic name={MEDALS[k]} size={28} style={{ position: 'absolute', top: -6, left: -12 }} />
|
||||
</View>
|
||||
<View className="mt-1.5 flex-1 justify-center">
|
||||
<Text className="text-center font-jua text-base text-ink">
|
||||
{k + 1}위 {g.name}
|
||||
</Text>
|
||||
</View>
|
||||
<Text className="font-bagel text-[30px] leading-[32px] text-orange">{g.score}</Text>
|
||||
{g.summary && <Text className="text-center text-[11.5px] font-semibold text-ink2">{g.summary}</Text>}
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import Svg, { Path } from 'react-native-svg';
|
||||
|
||||
export const HEART = 'M12 20.5s-8-4.9-8-11A4.6 4.6 0 0 1 12 6.8a4.6 4.6 0 0 1 8 2.7c0 6.1-8 11-8 11z';
|
||||
|
||||
type P = { size: number; color: string };
|
||||
|
||||
export function HeartIcon({ size, color, filled }: P & { filled: boolean }) {
|
||||
return (
|
||||
<Svg viewBox="0 0 24 24" width={size} height={size} fill={filled ? color : 'none'} stroke={color} strokeWidth={1.9}>
|
||||
<Path d={HEART} />
|
||||
</Svg>
|
||||
);
|
||||
}
|
||||
|
||||
export function CommentIcon({ size, color }: P) {
|
||||
return (
|
||||
<Svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke={color} strokeWidth={1.9} strokeLinejoin="round">
|
||||
<Path d="M20.5 12a8.5 8.5 0 0 1-12.6 7.4L3.5 20.5l1.2-4.2A8.5 8.5 0 1 1 20.5 12z" />
|
||||
</Svg>
|
||||
);
|
||||
}
|
||||
|
||||
export function SendIcon({ size, color }: P) {
|
||||
return (
|
||||
<Svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke={color} strokeWidth={1.9} strokeLinecap="round" strokeLinejoin="round">
|
||||
<Path d="M21 3 10 14M21 3l-6.5 18-4-7.5L3 9.5z" />
|
||||
</Svg>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { ScrollView, View, type NativeScrollEvent, type NativeSyntheticEvent } from 'react-native';
|
||||
|
||||
/** 옆으로 한 장씩 넘기는 슬라이드 (웹 Embla 캐러셀 대신 가로 paging ScrollView) */
|
||||
export function Pager({ width, height, onIndex, children }: { width: number; height: number; onIndex: (i: number) => void; children: ReactNode[] }) {
|
||||
const onEnd = (e: NativeSyntheticEvent<NativeScrollEvent>) => onIndex(Math.round(e.nativeEvent.contentOffset.x / width));
|
||||
return (
|
||||
<ScrollView horizontal pagingEnabled showsHorizontalScrollIndicator={false} scrollEnabled={children.length > 1} onMomentumScrollEnd={onEnd} style={{ width, height }}>
|
||||
{children.map((c, i) => (
|
||||
<View key={i} style={{ width, height }}>
|
||||
{c}
|
||||
</View>
|
||||
))}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
/** 슬라이드 위치 점 */
|
||||
export function Dots({ n, index }: { n: number; index: number }) {
|
||||
if (n < 2) return null;
|
||||
const items = Array.from({ length: n }, (_, i) => i);
|
||||
return (
|
||||
<View className="flex-row justify-center gap-1.5 pt-2" accessibilityElementsHidden>
|
||||
{items.map((i) => (
|
||||
<View key={i} className={`h-1.5 rounded-full ${i === index ? 'w-4 bg-orange' : 'w-1.5 bg-ink3/40'}`} />
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
import { likePostMutation, unlikePostMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { PostType, type PostData, type ResFeed } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Animated, Pressable, Share, Text, View } from 'react-native';
|
||||
import Svg, { Path } from 'react-native-svg';
|
||||
import { useCSSVariable } from 'uniwind';
|
||||
|
||||
import { CommentIcon, HEART, HeartIcon, SendIcon } from '@/components/post/icons';
|
||||
import { Dots, Pager } from '@/components/post/pager';
|
||||
import { slideBg, SlideView } from '@/components/post/slides';
|
||||
import { Ic, Skel } from '@/components/ui';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { SITE_URL } from '@/lib/site';
|
||||
|
||||
const ACCOUNTS: Record<PostType, readonly [string, string]> = {
|
||||
[PostType.WEATHER]: ['오늘 날씨', 'sun'],
|
||||
[PostType.GAK]: ['오늘의 각', 'rabbit'],
|
||||
[PostType.SUNSET]: ['노을', 'sunset'],
|
||||
[PostType.SEASON]: ['계절 소식', 'maple'],
|
||||
[PostType.EVENT]: ['가까운 행사', 'fireworks'],
|
||||
[PostType.TIP]: ['날씨 상식', 'bulb'],
|
||||
[PostType.WEEK]: ['주말 예보', 'calendar'],
|
||||
[PostType.ALERT]: ['생활 알림', 'umbrella'],
|
||||
[PostType.TOMORROW]: ['내일 미리보기', 'moon'],
|
||||
[PostType.QUOTE]: ['오늘의 한 문장', 'letter'],
|
||||
[PostType.WEEKEND_PLAN]: ['주말 플랜', 'calendar'],
|
||||
[PostType.AIR]: ['미세먼지', 'vent'],
|
||||
[PostType.DAY_TRIP]: ['당일치기', 'picnic'],
|
||||
[PostType.MOON]: ['오늘 밤 달', 'moon'],
|
||||
[PostType.UV]: ['자외선', 'glasses'],
|
||||
};
|
||||
|
||||
type PostProps = { post: PostData };
|
||||
|
||||
/** 받아 둔 피드 데이터에도 좋아요를 반영한다. 안 하면 다른 탭에 다녀왔을 때 예전 값으로 다시 그려진다 */
|
||||
function patchFeed(queryClient: QueryClient, postId: number, patch: Partial<PostData>) {
|
||||
queryClient.setQueriesData<ResFeed>({ predicate: (q) => (q.queryKey[0] as { _id?: string } | undefined)?._id === 'getFeed' }, (feed) =>
|
||||
feed?.posts ? { ...feed, posts: feed.posts.map((p) => (p.post_id === postId ? { ...p, ...patch } : p)) } : feed,
|
||||
);
|
||||
}
|
||||
|
||||
/** 한 줄 카드 (흐린 날 노을처럼 큰 그림이 필요 없는 소식) */
|
||||
function LineCard({ post }: PostProps) {
|
||||
const [account, avatar] = ACCOUNTS[post.post_type];
|
||||
return (
|
||||
<View className="mx-3 mt-3.5 flex-row items-center gap-3 rounded-[22px] border-b-4 border-shade bg-card px-4 py-3" accessibilityLabel={post.title}>
|
||||
<Ic name={post.icon || avatar} size={40} />
|
||||
<View className="flex-1">
|
||||
<Text className="text-xs font-bold text-ink3">{account}</Text>
|
||||
<Text className="text-sm text-ink2">
|
||||
<Text className="font-jua text-base text-ink">{post.title}</Text> {post.caption}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 인스타식 게시물: 옆으로 넘기는 슬라이드, 두 번 눌러 좋아요 */
|
||||
export function PostCard({ post }: PostProps) {
|
||||
return post.size === 'line' ? <LineCard post={post} /> : <FullCard post={post} />;
|
||||
}
|
||||
|
||||
/** FullCard 와 같은 틀(머리줄·4:5 그림·버튼줄·글 한 줄)의 스켈레톤 */
|
||||
export function PostCardSkel() {
|
||||
return (
|
||||
<View className="mt-3.5 border-y border-line bg-card" accessibilityElementsHidden>
|
||||
<View className="flex-row items-center gap-2.5 px-3 py-2.5">
|
||||
<View className="size-[34px] rounded-full bg-skel" />
|
||||
<View className="gap-1.5">
|
||||
<Skel className="w-12" />
|
||||
<Skel className="w-16" />
|
||||
</View>
|
||||
</View>
|
||||
<View className="aspect-[4/5] bg-skel" />
|
||||
<View className="flex-row gap-3.5 px-3 pt-2.5 pb-1">
|
||||
<View className="size-7 rounded-full bg-skel" />
|
||||
<View className="size-7 rounded-full bg-skel" />
|
||||
<View className="size-7 rounded-full bg-skel" />
|
||||
</View>
|
||||
<View className="gap-2 px-3 pt-1 pb-3">
|
||||
<Skel className="w-20" />
|
||||
<Skel className="w-4/5" />
|
||||
<Skel className="w-32" />
|
||||
<Skel className="w-8" />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 좋아요 때 가운데에 커졌다 사라지는 하트 */
|
||||
function HeartPop() {
|
||||
const [v] = useState(() => new Animated.Value(0));
|
||||
useEffect(() => {
|
||||
Animated.timing(v, { toValue: 1, duration: 800, useNativeDriver: true }).start();
|
||||
}, [v]);
|
||||
const opacity = v.interpolate({ inputRange: [0, 0.25, 0.6, 1], outputRange: [0, 1, 1, 0] });
|
||||
const scale = v.interpolate({ inputRange: [0, 0.25, 0.6, 1], outputRange: [0.3, 1.1, 1, 1] });
|
||||
return (
|
||||
<Animated.View pointerEvents="none" className="absolute inset-0 items-center justify-center" style={{ opacity, transform: [{ scale }] }}>
|
||||
<Svg viewBox="0 0 24 24" width={112} height={112} fill="#ff3b5c">
|
||||
<Path d={HEART} />
|
||||
</Svg>
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
function FullCard({ post }: PostProps) {
|
||||
const { open } = useSheet();
|
||||
const { loggedIn } = useAuth();
|
||||
const [ink, heart] = useCSSVariable(['--color-ink', '--color-heart']).map(String);
|
||||
const liked = !!post.liked;
|
||||
const likeCount = post.like_count;
|
||||
const queryClient = useQueryClient();
|
||||
const like = useMutation(likePostMutation());
|
||||
const unlike = useMutation(unlikePostMutation());
|
||||
const [width, setWidth] = useState(0);
|
||||
const [index, setIndex] = useState(0);
|
||||
const [pop, setPop] = useState(0);
|
||||
const [likeFailed, setLikeFailed] = useState(0);
|
||||
const lastTap = useRef(0);
|
||||
const [account, avatar] = ACCOUNTS[post.post_type];
|
||||
const n = post.slides.length;
|
||||
const patch = (values: Partial<PostData>) => patchFeed(queryClient, post.post_id, values);
|
||||
const comments = () => open({ type: 'comments', postId: post.post_id });
|
||||
const share = () => {
|
||||
Share.share({ message: `${post.title} · 날씨각 ${SITE_URL}` }).catch((e: unknown) => console.warn('공유 실패', e));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!likeFailed) return;
|
||||
const t = setTimeout(() => setLikeFailed(0), 2500);
|
||||
return () => clearTimeout(t);
|
||||
}, [likeFailed]);
|
||||
|
||||
// 화면을 먼저 바꾸고, 실패하면 되돌린다 (서버는 실패도 200 + result.success=false 로 준다)
|
||||
const setLike = (on: boolean) => {
|
||||
if (!loggedIn) return open({ type: 'login' });
|
||||
if (on === liked || like.isPending || unlike.isPending) return;
|
||||
if (on) setPop((p) => p + 1);
|
||||
setLikeFailed(0);
|
||||
patch({ liked: on, like_count: likeCount + (on ? 1 : -1) });
|
||||
const revert = () => {
|
||||
patch({ liked, like_count: likeCount });
|
||||
setLikeFailed(Date.now());
|
||||
};
|
||||
(on ? like : unlike).mutate(
|
||||
{ path: { post_id: post.post_id } },
|
||||
{
|
||||
onSuccess: (res) => (res.result?.success ? patch({ liked: res.liked ?? on, ...(res.like_count != null ? { like_count: res.like_count } : {}) }) : revert()),
|
||||
onError: revert,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const onTap = () => {
|
||||
const now = Date.now();
|
||||
if (now - lastTap.current < 320) {
|
||||
if (liked && loggedIn) setPop((p) => p + 1);
|
||||
else setLike(true);
|
||||
}
|
||||
lastTap.current = now;
|
||||
};
|
||||
|
||||
return (
|
||||
<View className="mt-3.5 border-y border-line bg-card" accessibilityLabel={post.title}>
|
||||
<View className="flex-row items-center gap-2.5 px-3 py-2.5">
|
||||
<View className="size-[34px] rounded-full p-0.5">
|
||||
<LinearGradient colors={['#ff7a45', '#ffc86e', '#8fcaff']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={{ position: 'absolute', inset: 0, borderRadius: 17 }} />
|
||||
<View className="flex-1 items-center justify-center rounded-full bg-card">
|
||||
<Ic name={avatar} size={22} />
|
||||
</View>
|
||||
</View>
|
||||
<View>
|
||||
<Text className="text-sm leading-tight font-extrabold text-ink">날씨각</Text>
|
||||
<Text className="text-xs font-semibold text-ink2">{account}</Text>
|
||||
</View>
|
||||
</View>
|
||||
<Pressable onPress={onTap} onLayout={(e) => setWidth(e.nativeEvent.layout.width)} className="aspect-[4/5] overflow-hidden" accessibilityLabel={n > 1 ? `슬라이드 ${n}장, 옆으로 넘겨 보세요` : undefined}>
|
||||
{width > 0 && (
|
||||
<Pager width={width} height={(width * 5) / 4} onIndex={setIndex}>
|
||||
{post.slides.map((s, i) => (
|
||||
<SlideView key={i} slide={s} bg={slideBg(post, s)} />
|
||||
))}
|
||||
</Pager>
|
||||
)}
|
||||
{n > 1 && (
|
||||
<View pointerEvents="none" className="absolute top-3 right-3 z-[2] rounded-full bg-[rgb(30_36_56/0.55)] px-[9px] py-[3px]">
|
||||
<Text className="text-xs font-extrabold text-white">
|
||||
{index + 1}/{n}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
{pop > 0 && <HeartPop key={pop} />}
|
||||
{likeFailed > 0 && (
|
||||
<View pointerEvents="none" className="absolute inset-x-0 bottom-4 items-center px-4" accessibilityRole="alert">
|
||||
<Text className="overflow-hidden rounded-full bg-[rgb(30_36_56/0.82)] px-3.5 py-2 text-[13px] font-bold text-white">{liked ? '좋아요를 취소하지 못했어요' : '좋아요를 반영하지 못했어요'}. 다시 해 주세요.</Text>
|
||||
</View>
|
||||
)}
|
||||
</Pressable>
|
||||
<Dots n={n} index={index} />
|
||||
<View className="flex-row items-center gap-3.5 px-3 pt-2.5 pb-1">
|
||||
<Pressable onPress={() => setLike(!liked)} hitSlop={8} accessibilityRole="button" accessibilityState={{ selected: liked }} accessibilityLabel="좋아요">
|
||||
<HeartIcon size={26} color={liked ? heart : ink} filled={liked} />
|
||||
</Pressable>
|
||||
<Pressable onPress={comments} hitSlop={8} accessibilityRole="button" accessibilityLabel="댓글 보기">
|
||||
<CommentIcon size={26} color={ink} />
|
||||
</Pressable>
|
||||
<Pressable onPress={share} hitSlop={8} accessibilityRole="button" accessibilityLabel="보내기">
|
||||
<SendIcon size={26} color={ink} />
|
||||
</Pressable>
|
||||
</View>
|
||||
<Text className="px-3 py-0.5 text-sm font-extrabold text-ink">좋아요 {likeCount.toLocaleString()}개</Text>
|
||||
<Text className="px-3 py-0.5 text-sm text-ink">
|
||||
<Text className="font-extrabold">날씨각 </Text>
|
||||
{post.caption}
|
||||
</Text>
|
||||
<Pressable onPress={comments}>
|
||||
<Text className="px-3 pt-[3px] text-sm font-semibold text-ink3">{post.comment_count ? `댓글 ${post.comment_count}개 모두 보기` : '첫 댓글 남기기'}</Text>
|
||||
</Pressable>
|
||||
<Text className="px-3 pt-1 pb-3 text-[11.5px] font-semibold text-ink3">오늘</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
import type { GakSlide, HoursSlide, PlanSlide, PostData, RowsSlide, SunsetSlide, WeekSlide } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { PostType, SlotTone } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { cardBg, clockShort } from '@nalssigak/shared/lib';
|
||||
import type { SlideBg } from '@nalssigak/shared/lib/types';
|
||||
import { deg } from '@nalssigak/shared/lib/weatherText';
|
||||
import { Image } from 'expo-image';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import type { ReactNode } from 'react';
|
||||
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
||||
import Svg, { Polygon } from 'react-native-svg';
|
||||
|
||||
import { Credit, Ic, Rows, Thumb } from '@/components/ui';
|
||||
import { CARD_BG } from '@/lib/colors';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { imageUri } from '@/lib/site';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
export type Slide = HoursSlide | RowsSlide | GakSlide | SunsetSlide | WeekSlide | PlanSlide;
|
||||
|
||||
type Stops = readonly [string, string, ...string[]];
|
||||
|
||||
const GAK_BG: SlideBg[] = ['butter', 'peach', 'lilac'];
|
||||
const ROW_ICON_BG: Record<string, SlideBg> = { umbrella: 'lilac', vent: 'mint', sunset: 'peach', thermo: 'sky', maple: 'peach', moon: 'lilac', glasses: 'butter' };
|
||||
const DARK = new Set<SlideBg>(['dusk', 'night']);
|
||||
|
||||
// 노을 하늘 상황(1 가려짐 2 낮은 구름 3 물들 구름 적음 4 넓게 물듦 5 두꺼움)별 하늘, 시간 칸 색 (웹 .b-sit-*, .b-cut-*)
|
||||
const SIT_BG: Record<number, { colors: Stops; locations: readonly [number, number, ...number[]] }> = {
|
||||
1: { colors: ['#6f7690', '#9aa0b4', '#b9b4c0'], locations: [0, 0.55, 1] },
|
||||
2: { colors: ['#7a7f9c', '#a7a3bb', '#c9b8b8'], locations: [0, 0.55, 1] },
|
||||
3: { colors: ['#4b5aa8', '#7f86c6', '#e9b9a8', '#ffb27a', '#ff8a4c'], locations: [0, 0.38, 0.68, 0.86, 1] },
|
||||
4: { colors: ['#5b3f9e', '#c2559a', '#ff7a6a', '#ffb35c'], locations: [0, 0.4, 0.68, 1] },
|
||||
5: { colors: ['#6a6aa0', '#a98fb4', '#e3b1a0'], locations: [0, 0.55, 1] },
|
||||
};
|
||||
const CUT_BG: Stops[] = [
|
||||
['#9fd0ff', '#ffd79a', '#ff9a5c'],
|
||||
['#8f7cf0', '#ff6f8e', '#ff8a4c'],
|
||||
['#34306e', '#7a5cc8'],
|
||||
];
|
||||
// 건물 실루엣 (웹 .b-skyline clip-path)
|
||||
const SKYLINE = '0,55 8,55 8,30 15,30 15,50 22,50 22,10 28,10 28,45 36,45 36,25 44,25 44,55 52,55 52,35 60,35 60,5 66,5 66,40 74,40 74,20 82,20 82,50 90,50 90,30 100,30 100,100 0,100';
|
||||
|
||||
const HOUR_TONE: Record<string, { bg: string; edge: string }> = {
|
||||
[SlotTone.NIGHT]: { bg: '#e3e7ff', edge: '#c7cff5' },
|
||||
[SlotTone.SUNSET]: { bg: '#ffe3d2', edge: '#ffc19f' },
|
||||
};
|
||||
|
||||
/** 배경색은 API에 없어 글 종류·아이콘으로 고른다 */
|
||||
export function slideBg(post: PostData, slide: Slide): SlideBg {
|
||||
if (slide.kind === 'hours') return 'sky';
|
||||
if (slide.kind === 'sunset') return 'dusk';
|
||||
if (slide.kind === 'week') return 'mint';
|
||||
if (slide.kind === 'plan') return slide.eyebrow.startsWith('일') ? 'peach' : 'butter';
|
||||
if (slide.kind === 'gak') return GAK_BG[post.post_id % GAK_BG.length];
|
||||
if (post.post_type === PostType.EVENT) return 'night';
|
||||
if (post.post_type === PostType.TIP) return 'sky';
|
||||
if (post.post_type === PostType.AIR) return slide.icon === 'vent' ? 'mint' : 'lilac';
|
||||
if (post.post_type === PostType.DAY_TRIP) return slide.image ? 'night' : 'mint';
|
||||
return (ROW_ICON_BG[slide.icon] ?? cardBg(slide.icon, post.post_id)) as SlideBg;
|
||||
}
|
||||
|
||||
function Base({ colors, locations, children }: { colors: Stops; locations?: readonly [number, number, ...number[]]; children: ReactNode }) {
|
||||
return (
|
||||
<View className="flex-1 px-5 py-[22px]">
|
||||
<LinearGradient colors={colors} locations={locations} style={StyleSheet.absoluteFill} />
|
||||
{children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function Eyebrow({ children, light, className }: { children: ReactNode; light?: boolean; className?: string }) {
|
||||
return <Text className={`text-[13px] font-extrabold opacity-75 ${light ? 'text-white' : 'text-ink'} ${className ?? ''}`}>{children}</Text>;
|
||||
}
|
||||
|
||||
function Big({ children, light, className }: { children: ReactNode; light?: boolean; className?: string }) {
|
||||
return <Text className={`mt-1.5 font-jua text-[29px] leading-tight ${light ? 'text-white' : 'text-ink'} ${className ?? ''}`}>{children}</Text>;
|
||||
}
|
||||
|
||||
function Pic({ name, widthPct = 42 }: { name: string; widthPct?: number }) {
|
||||
return (
|
||||
<View pointerEvents="none" className="absolute top-[30%] right-3.5 aspect-square" style={{ width: `${widthPct}%` }}>
|
||||
<Ic name={name} size={0} style={{ width: '100%', height: '100%' }} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
|
||||
const { open } = useSheet();
|
||||
const { kind } = useSky();
|
||||
const palette = CARD_BG[kind === 'night' ? 'night' : 'day'];
|
||||
const colors = palette[bg] ?? palette.sky;
|
||||
const light = DARK.has(bg);
|
||||
|
||||
if (slide.kind === 'hours') {
|
||||
const temps = slide.hours.flatMap((h) => (h.temp_c == null ? [] : [h.temp_c]));
|
||||
const lo = Math.min(...temps);
|
||||
const span = Math.max(...temps) - lo || 1;
|
||||
return (
|
||||
<Base colors={palette.sky}>
|
||||
<Eyebrow>{slide.eyebrow}</Eyebrow>
|
||||
<Big>{slide.line}</Big>
|
||||
<View className="mt-3.5 flex-1 flex-row gap-2">
|
||||
{slide.hours.map((h) => {
|
||||
const tone = HOUR_TONE[h.tone ?? ''];
|
||||
return (
|
||||
<View key={h.label} className={`flex-1 items-center justify-between overflow-hidden rounded-[18px] px-1 pt-2.5 pb-[9px] ${tone ? '' : 'border-b-[5px] border-shade bg-card'}`} style={tone ? { backgroundColor: tone.bg, borderBottomWidth: 5, borderColor: tone.edge } : undefined}>
|
||||
{h.temp_c != null && <LinearGradient colors={['rgba(255,122,69,0.1)', 'rgba(255,122,69,0.34)']} style={{ position: 'absolute', left: 0, right: 0, bottom: 0, height: `${20 + ((h.temp_c - lo) / span) * 70}%` }} />}
|
||||
<Text className={`text-xs font-bold ${tone ? 'text-[#5a6380]' : 'text-ink2'}`}>{h.label}</Text>
|
||||
<Ic name={h.icon} size={34} />
|
||||
<Text className={`font-bagel text-[21px] ${tone ? 'text-[#28304a]' : 'text-ink'}`}>{deg(h.temp_c)}</Text>
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
</Base>
|
||||
);
|
||||
}
|
||||
if (slide.kind === 'gak')
|
||||
return (
|
||||
<Base colors={colors}>
|
||||
<Eyebrow>오늘의 각 · {slide.rank}위</Eyebrow>
|
||||
<Big>{slide.line}</Big>
|
||||
<Pic name={slide.code} />
|
||||
<Text className="mt-auto font-bagel text-[82px] leading-[82px] text-orange">{slide.score}</Text>
|
||||
<Text className="font-jua text-[29px] leading-tight text-ink">{slide.name}</Text>
|
||||
<Eyebrow className="mt-1">{slide.summary}</Eyebrow>
|
||||
<Pressable onPress={() => open({ type: 'gak', indexId: slide.index_id })} className="mt-3 self-start rounded-full border-b-[5px] border-orange-deep bg-orange px-4 py-[9px]">
|
||||
<Text className="font-jua text-[15px] text-white">계산 근거 보기</Text>
|
||||
</Pressable>
|
||||
</Base>
|
||||
);
|
||||
if (slide.kind === 'sunset') {
|
||||
const sit = slide.situation ? SIT_BG[slide.situation] : undefined;
|
||||
return (
|
||||
<Base colors={sit?.colors ?? palette.dusk} locations={sit?.locations}>
|
||||
<Eyebrow light>{slide.eyebrow}</Eyebrow>
|
||||
{/* 노을 탭 히어로와 같은 순서: 결론 → 가장 붉을 때 → 쉬운 이유 */}
|
||||
<Big light>{slide.headline ?? slide.grade_label}</Big>
|
||||
{slide.line && <Text className="mt-0.5 font-jua text-[18px] text-white">{slide.line}</Text>}
|
||||
<View className="mt-3 flex-1 gap-2">
|
||||
{slide.cuts.map((c, i) => (
|
||||
<View key={c.kind} className="flex-1 overflow-hidden rounded-2xl px-3 py-2">
|
||||
<LinearGradient colors={CUT_BG[Math.min(i, 2)]} style={StyleSheet.absoluteFill} />
|
||||
<Svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', left: 0, right: 0, bottom: 0, height: '32%' }}>
|
||||
<Polygon points={SKYLINE} fill="#2d2440" />
|
||||
</Svg>
|
||||
<Text className="font-bagel text-[21px] text-white">
|
||||
{clockShort(c.at)}
|
||||
<Text className="font-jua text-sm"> {c.label}</Text>
|
||||
</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</Base>
|
||||
);
|
||||
}
|
||||
if (slide.kind === 'week')
|
||||
return (
|
||||
<Base colors={palette.mint}>
|
||||
<Eyebrow>{slide.eyebrow}</Eyebrow>
|
||||
<Big>{slide.line}</Big>
|
||||
{/* 칸은 제목 바로 아래, 팁만 맨 아래로 */}
|
||||
<View className="mt-4 flex-row flex-wrap gap-2.5">
|
||||
{slide.days.map((d) => (
|
||||
<View key={d.day} className="grow basis-[45%] gap-0.5 rounded-[18px] border-b-[5px] border-shade bg-card/85 px-3 py-2.5">
|
||||
<Ic name={d.icon} size={34} />
|
||||
<Text className="font-jua text-lg text-ink">
|
||||
{d.weekday} {d.day.split('-').slice(1).map(Number).join('.')}
|
||||
</Text>
|
||||
<Text className="font-jua text-[22px] text-ink">
|
||||
<Text className="text-rain">{deg(d.temp_min_c)}</Text> → <Text className="text-orange">{deg(d.temp_max_c)}</Text>
|
||||
</Text>
|
||||
<Text className="text-xs font-bold text-ink2">
|
||||
비 {d.rain_prob ?? '?'}%{d.temp_min_c != null && d.temp_max_c != null && ` · 일교차 ${Math.round(d.temp_max_c - d.temp_min_c)}°`}
|
||||
</Text>
|
||||
{d.gaks && d.gaks.length > 0 && (
|
||||
<View className="mt-2 gap-1.5 border-t border-shade pt-2" accessibilityLabel={`${d.weekday}요일 대표 각`}>
|
||||
<Text className="text-[11px] font-extrabold text-ink2">이날 할 만한 각</Text>
|
||||
{d.gaks.map((g) => (
|
||||
<View key={g.index_id} className="flex-row items-center gap-1.5">
|
||||
<Ic name={g.icon} size={26} />
|
||||
<Text numberOfLines={1} className="flex-1 text-[14px] font-bold text-ink">
|
||||
{g.name}
|
||||
</Text>
|
||||
<Text className="font-bagel text-[16px] text-orange">{g.score}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
{slide.tip && <Text className="mt-auto overflow-hidden rounded-[14px] bg-ink-btn px-3 py-2.5 text-[13px] leading-snug font-bold text-white">{slide.tip}</Text>}
|
||||
</Base>
|
||||
);
|
||||
if (slide.kind === 'plan') {
|
||||
const credits = [...new Set(slide.steps.flatMap((st) => (st.image && st.image_credit ? [st.image_credit] : [])))];
|
||||
return (
|
||||
<Base colors={colors}>
|
||||
<Eyebrow>{slide.eyebrow}</Eyebrow>
|
||||
<Big className="text-[24px]">{slide.line}</Big>
|
||||
<View className="mt-auto gap-2">
|
||||
{slide.steps.map((st, i) => (
|
||||
<View key={i} className="flex-row items-center gap-1.5 rounded-[14px] bg-card/80 px-2 py-1.5">
|
||||
<Text className="w-[52px] font-jua text-sm text-ink2">{st.time}</Text>
|
||||
<Ic name={st.icon} size={22} />
|
||||
<View className="ml-1 flex-1">
|
||||
<Text numberOfLines={1} className="text-[13.5px] font-bold text-ink">
|
||||
{st.title}
|
||||
</Text>
|
||||
<Text numberOfLines={1} className="text-[11.5px] font-semibold text-ink2">
|
||||
{st.sub}
|
||||
</Text>
|
||||
</View>
|
||||
{st.image && <Thumb image={st.image} icon={st.icon} iconSize={26} className="size-[46px] rounded-[10px]" />}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
{credits.length > 0 && <Text className="mt-1.5 text-right text-[10px] font-semibold text-ink2">사진 {credits.join(' · ')}</Text>}
|
||||
</Base>
|
||||
);
|
||||
}
|
||||
if (slide.kind === 'rows' && slide.image)
|
||||
return (
|
||||
<View className="flex-1 justify-end">
|
||||
<Image source={{ uri: imageUri(slide.image) }} style={StyleSheet.absoluteFill} contentFit="cover" />
|
||||
{slide.image_credit && <Credit text={slide.image_credit} className="top-2.5 right-2.5" />}
|
||||
<View className="px-5 pt-20 pb-3.5">
|
||||
<LinearGradient colors={['rgba(16,20,34,0)', 'rgba(16,20,34,0.55)', 'rgba(16,20,34,0.85)']} locations={[0, 0.35, 1]} style={StyleSheet.absoluteFill} />
|
||||
<Eyebrow light>{slide.eyebrow}</Eyebrow>
|
||||
<Big light>{slide.line}</Big>
|
||||
<Rows rows={slide.rows ?? []} dark />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
return (
|
||||
<Base colors={colors}>
|
||||
<Eyebrow light={light} className={light ? 'opacity-85' : undefined}>
|
||||
{slide.eyebrow}
|
||||
</Eyebrow>
|
||||
<Big light={light} className="z-[1]">
|
||||
{slide.line}
|
||||
</Big>
|
||||
<Pic name={slide.icon} widthPct={36} />
|
||||
<Rows rows={slide.rows ?? []} dark={light} />
|
||||
</Base>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import type { ArticleSummary, ResSeasonWeek } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { ARTICLE_LABEL, cardBg, dateRange, shortDay } from '@nalssigak/shared/lib';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { Credit, Ic, Skel, Thumb } from '@/components/ui';
|
||||
import { CARD_BG } from '@/lib/colors';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
const HEAD_BOX = 'mx-3 mt-3 min-h-[250px] overflow-hidden rounded-[28px] p-5';
|
||||
const ROW = 'flex-row items-center gap-3 border-b-[1.5px] border-line px-4 py-3.5';
|
||||
const ROW_SKELS = [0, 1, 2, 3];
|
||||
|
||||
// 분류 글자색 (웹 ARTICLE_CAT). 밤엔 밝게
|
||||
const CAT_COLOR: Record<number, [string, string]> = { 1: ['#1f9d62', '#4fd39a'], 2: ['#7a5cd6', '#b9a6ff'], 3: ['#ff7a45', '#ff8a57'] };
|
||||
|
||||
/** 특집 상자와 같은 틀: 머리말 · 제목 두 줄 · 시 한 줄 · 절기 막대 */
|
||||
export function HeadSkel() {
|
||||
return (
|
||||
<View className={`${HEAD_BOX} gap-1.5 bg-card`}>
|
||||
<Skel className="w-36" />
|
||||
<Skel className="mt-1 h-7 w-[62%]" />
|
||||
<Skel className="h-7 w-[40%]" />
|
||||
<Skel className="mt-auto h-5 w-[72%]" />
|
||||
<Skel className="mt-2.5 w-[70%]" />
|
||||
<View className="h-[7px] w-[70%] rounded-full bg-skel" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function RowsSkel() {
|
||||
return (
|
||||
<>
|
||||
{ROW_SKELS.map((i) => (
|
||||
<View key={i} className={ROW}>
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="w-12" />
|
||||
<Skel className="h-4 w-48" />
|
||||
<Skel className="w-14" />
|
||||
</View>
|
||||
<View className="h-[84px] w-[84px] rounded-[18px] bg-skel" />
|
||||
</View>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** 이번 주 특집: 제목·시·절기 막대. 누르면 이번 주 절기 창 */
|
||||
export function SeasonHead({ week: w, onPress }: { week: ResSeasonWeek; onPress: () => void }) {
|
||||
const { kind } = useSky();
|
||||
const night = kind === 'night';
|
||||
const progress = Math.round((w.progress ?? 0) * 100);
|
||||
const poem = w.poem_lines ?? [];
|
||||
return (
|
||||
<Pressable onPress={onPress} className={HEAD_BOX}>
|
||||
<LinearGradient colors={CARD_BG[night ? 'night' : 'day'].peach} style={{ position: 'absolute', inset: 0 }} />
|
||||
<Ic name="maple" size={140} style={{ position: 'absolute', top: '18%', right: 14, width: '38%' }} />
|
||||
<Text className="text-[13px] font-extrabold text-ink opacity-75">이번 주 특집{w.start && w.end ? ` · ${dateRange(w.start, w.end)}` : ''}</Text>
|
||||
<Text className="mt-1 max-w-[62%] font-jua text-[29px] leading-tight text-ink">{w.headline}</Text>
|
||||
{poem.length > 0 && <Text className="mt-auto max-w-[72%] pt-3 text-[22px] leading-[37px] text-ink">{poem.join('\n')}</Text>}
|
||||
{w.term_now && w.term_next && (
|
||||
<View className={`max-w-[70%] ${poem.length ? 'mt-2.5' : 'mt-auto'}`}>
|
||||
<View className="flex-row justify-between">
|
||||
<Text className="text-xs font-extrabold text-ink2">
|
||||
{w.term_now.name} {shortDay(w.term_now.day)}
|
||||
</Text>
|
||||
<Text className="text-xs font-extrabold text-ink2">
|
||||
{w.term_next.name} {shortDay(w.term_next.day)}
|
||||
</Text>
|
||||
</View>
|
||||
<View className="mt-1 h-[7px] overflow-hidden rounded-full bg-[rgb(40_48_74/0.1)]" accessibilityRole="image" accessibilityLabel={`다음 절기까지 ${progress}% 지났어요`}>
|
||||
<View className="h-full bg-orange" style={{ width: `${progress}%` }} />
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
export function ArticleRow({ article: a, onPress }: { article: ArticleSummary; onPress: () => void }) {
|
||||
const { kind } = useSky();
|
||||
const night = kind === 'night';
|
||||
const color = CAT_COLOR[a.category]?.[night ? 1 : 0];
|
||||
return (
|
||||
<Pressable onPress={onPress} className={ROW}>
|
||||
<View className="flex-1">
|
||||
{ARTICLE_LABEL[a.category] && (
|
||||
<Text className="text-xs font-extrabold" style={{ color }}>
|
||||
{ARTICLE_LABEL[a.category]}
|
||||
</Text>
|
||||
)}
|
||||
<Text className="mt-0.5 font-jua text-[17.5px] leading-snug text-ink">{a.title}</Text>
|
||||
<Text className="mt-1 text-xs font-semibold text-ink3">{a.read_minutes}분 읽기</Text>
|
||||
</View>
|
||||
<Thumb image={a.image} icon={a.icon} iconSize={54} className="h-[84px] w-[84px] rounded-[18px]">
|
||||
<LinearGradient colors={CARD_BG[night ? 'night' : 'day'][cardBg(a.icon, a.article_id)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
|
||||
{a.image && a.image_credit && <Credit text={a.image_credit} />}
|
||||
</Thumb>
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { getArticleOptions, getSeasonWeekOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { ARTICLE_LABEL, articleMeta, cardBg, dateRange, loadOf, shortDay } from '@nalssigak/shared/lib';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { useEffect } from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { Credit, Ic, StateBox, Thumb } from '@/components/ui';
|
||||
import { CARD_BG } from '@/lib/colors';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
import { ArticleSkel, Body } from './parts';
|
||||
|
||||
export function ArticleSheet({ articleId, onTitle }: { articleId: number; onTitle: (t: string) => void }) {
|
||||
const q = useQuery(getArticleOptions({ path: { article_id: articleId } }));
|
||||
const a = q.data?.article;
|
||||
const night = useSky().kind === 'night';
|
||||
|
||||
useEffect(() => {
|
||||
onTitle(a ? (ARTICLE_LABEL[a.category] ?? '') : '');
|
||||
}, [a, onTitle]);
|
||||
|
||||
const load = loadOf(q);
|
||||
if (!a) return <Body>{load === 'loading' ? <ArticleSkel /> : <StateBox load={load} onRetry={() => q.refetch()} empty="글을 찾지 못했어요." />}</Body>;
|
||||
return (
|
||||
<Body>
|
||||
<Thumb image={a.image} icon={a.icon} iconSize={96} className="mb-3.5 h-[150px] rounded-[20px]">
|
||||
<LinearGradient colors={CARD_BG[night ? 'night' : 'day'][cardBg(a.icon, a.article_id)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
|
||||
{a.image && a.image_credit && <Credit text={a.image_credit} />}
|
||||
</Thumb>
|
||||
<Text className="text-[13px] font-extrabold text-ink2">{articleMeta(a)}</Text>
|
||||
<Text className="mt-1.5 mb-2.5 font-jua text-2xl leading-tight text-ink">{a.title}</Text>
|
||||
{(q.data?.body ?? []).map((t) => (
|
||||
<Text key={t} className="mb-2.5 text-[15px] leading-[1.7] text-ink">
|
||||
{t}
|
||||
</Text>
|
||||
))}
|
||||
</Body>
|
||||
);
|
||||
}
|
||||
|
||||
export function SeasonWeekSheet() {
|
||||
const { open } = useSheet();
|
||||
const night = useSky().kind === 'night';
|
||||
const q = useQuery(getSeasonWeekOptions());
|
||||
const w = q.data;
|
||||
const load = loadOf(q);
|
||||
if (!w?.headline) return <Body>{load === 'loading' ? <ArticleSkel /> : <StateBox load={load} onRetry={() => q.refetch()} empty="이번 주 특집이 아직 없어요." />}</Body>;
|
||||
return (
|
||||
<Body>
|
||||
<View className="mb-3.5 h-[150px] items-center justify-center overflow-hidden rounded-[20px]">
|
||||
<LinearGradient colors={CARD_BG[night ? 'night' : 'day'].peach} style={{ position: 'absolute', inset: 0 }} />
|
||||
<Ic name="maple" size={96} />
|
||||
</View>
|
||||
<Text className="text-[13px] font-extrabold text-ink2">{w.start && w.end ? dateRange(w.start, w.end) : '이번 주'}</Text>
|
||||
<Text className="mt-1.5 mb-2.5 font-jua text-2xl leading-tight text-ink">{w.headline}</Text>
|
||||
{(w.poem_lines ?? []).length > 0 && (
|
||||
<View className="mb-2.5">
|
||||
<Text className="text-[17px] leading-[1.7] text-ink" style={{ fontFamily: 'serif' }}>
|
||||
{w.poem_lines?.join(' ')}
|
||||
</Text>
|
||||
{w.author && <Text className="text-xs font-semibold text-ink3">{w.author}</Text>}
|
||||
</View>
|
||||
)}
|
||||
{w.term_now && w.term_next && (
|
||||
<Text className="mb-2.5 text-[15px] leading-[1.7] text-ink">
|
||||
지금 절기는 {w.term_now.name}({shortDay(w.term_now.day)}), 다음 절기는 {w.term_next.name}({shortDay(w.term_next.day)})예요.
|
||||
</Text>
|
||||
)}
|
||||
{(w.news ?? []).map((n) => (
|
||||
<Pressable key={n.code} onPress={() => open({ type: 'article', articleId: n.article_id })} className="flex-row items-center gap-2.5 border-b-[1.5px] border-line py-2.5">
|
||||
<Ic name={n.icon} size={32} />
|
||||
<Text className="flex-1 font-jua text-base text-ink">{n.title}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</Body>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
import {
|
||||
addCommentMutation,
|
||||
deleteCommentMutation,
|
||||
getFeedQueryKey,
|
||||
likeCommentMutation,
|
||||
listCommentsInfiniteOptions,
|
||||
listCommentsInfiniteQueryKey,
|
||||
unlikeCommentMutation,
|
||||
} from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import type { CommentData, ResCommentList } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { ago, loadOf } from '@nalssigak/shared/lib';
|
||||
import { useInfiniteQuery, useMutation, useQueryClient, type InfiniteData } from '@tanstack/react-query';
|
||||
import { useRef, useState } from 'react';
|
||||
import { Pressable, Text, TextInput, View } from 'react-native';
|
||||
import { useCSSVariable } from 'uniwind';
|
||||
|
||||
import { Avatar, Skel, StateBox } from '@/components/ui';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
|
||||
import { Body, ErrorLine, Field, HeartIcon } from './parts';
|
||||
|
||||
const NOT_FOUND = 3001; // 서버 ErrorType.NOT_FOUND
|
||||
const EMOJIS = ['☀️', '🌂', '🍻', '🌇', '😍', '👍'];
|
||||
const N3 = [0, 1, 2];
|
||||
|
||||
function CommentsSkel() {
|
||||
return (
|
||||
<View>
|
||||
{N3.map((i) => (
|
||||
<View key={i} className="flex-row items-start gap-2.5 py-2">
|
||||
<View className="size-[34px] rounded-full bg-skel" />
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="w-3/4" />
|
||||
<Skel className="w-24" />
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function CommentRow({ c, postId }: { c: CommentData; postId: number }) {
|
||||
const { region } = useRegion();
|
||||
const { loggedIn } = useAuth();
|
||||
const { open } = useSheet();
|
||||
const queryClient = useQueryClient();
|
||||
const [heart, ink3] = useCSSVariable(['--color-heart', '--color-ink3']).map(String);
|
||||
const [liked, setLiked] = useState(c.liked);
|
||||
const [count, setCount] = useState(c.like_count);
|
||||
const like = useMutation(likeCommentMutation());
|
||||
const unlike = useMutation(unlikeCommentMutation());
|
||||
const remove = useMutation(deleteCommentMutation());
|
||||
const [removeFailed, setRemoveFailed] = useState(false);
|
||||
const [likeFailed, setLikeFailed] = useState(false);
|
||||
|
||||
const toggle = () => {
|
||||
if (!loggedIn) return open({ type: 'login' });
|
||||
if (like.isPending || unlike.isPending) return;
|
||||
const next = !liked;
|
||||
setLikeFailed(false);
|
||||
setLiked(next);
|
||||
setCount((n) => n + (next ? 1 : -1));
|
||||
const revert = () => {
|
||||
setLiked(!next);
|
||||
setCount(c.like_count);
|
||||
};
|
||||
(next ? like : unlike).mutate(
|
||||
{ path: { comment_id: c.comment_id } },
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
if (res.result?.success) {
|
||||
setLiked(!!res.liked);
|
||||
if (res.like_count != null) setCount(res.like_count);
|
||||
return;
|
||||
}
|
||||
revert();
|
||||
// 그 사이 지워진 댓글이면 알림 없이 목록을 다시 받아 사라지게 한다
|
||||
if (res.result?.code === NOT_FOUND) queryClient.invalidateQueries({ queryKey: listCommentsInfiniteQueryKey({ path: { post_id: postId } }) });
|
||||
else setLikeFailed(true);
|
||||
},
|
||||
onError: () => {
|
||||
revert();
|
||||
setLikeFailed(true);
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
// 지우는 동안은 흐리게 두고, 성공하면 다시 받기 전에 목록 캐시에서 바로 뺀다
|
||||
const del = () => {
|
||||
setRemoveFailed(false);
|
||||
remove.mutate(
|
||||
{ path: { comment_id: c.comment_id } },
|
||||
{
|
||||
onSuccess: async (res) => {
|
||||
if (!res.result?.success) return setRemoveFailed(true);
|
||||
const key = listCommentsInfiniteQueryKey({ path: { post_id: postId } });
|
||||
await queryClient.cancelQueries({ queryKey: key });
|
||||
queryClient.setQueryData<InfiniteData<ResCommentList>>(key, (data) =>
|
||||
data ? { ...data, pages: data.pages.map((p) => ({ ...p, comments: p.comments?.filter((x) => x.comment_id !== c.comment_id) })) } : data,
|
||||
);
|
||||
queryClient.invalidateQueries({ queryKey: key });
|
||||
queryClient.invalidateQueries({ queryKey: getFeedQueryKey({ query: { region: region.code } }) });
|
||||
},
|
||||
onError: () => setRemoveFailed(true),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<View className={`flex-row items-start gap-2.5 py-2 ${remove.isPending ? 'opacity-50' : ''}`}>
|
||||
<Avatar character={c.character} color={c.color} mood={c.mood} />
|
||||
<View className="flex-1">
|
||||
<Text className="text-sm text-ink">
|
||||
<Text className="font-extrabold">{c.nickname} </Text>
|
||||
{c.body}
|
||||
</Text>
|
||||
<Text className="mt-0.5 text-xs font-bold text-ink3">
|
||||
{ago(c.created_at)} · {likeFailed ? <Text className="text-heart">좋아요를 못 했어요. 잠시 뒤에 다시 눌러 주세요</Text> : `좋아요 ${count}개`}
|
||||
{c.mine && (
|
||||
<>
|
||||
{' · '}
|
||||
<Text onPress={remove.isPending ? undefined : del} className={removeFailed && !remove.isPending ? 'text-heart' : 'text-ink3'}>
|
||||
{remove.isPending ? '지우는 중…' : removeFailed ? '못 지웠어요 · 다시' : '지우기'}
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
</Text>
|
||||
</View>
|
||||
<Pressable onPress={toggle} hitSlop={12} accessibilityRole="button" accessibilityState={{ selected: liked }} accessibilityLabel="댓글 좋아요" className="pt-1">
|
||||
<HeartIcon size={16} fill={liked ? heart : 'none'} stroke={liked ? heart : ink3} />
|
||||
</Pressable>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function CommentsSheet({ postId, draft }: { postId: number; draft?: string }) {
|
||||
const { region } = useRegion();
|
||||
const { open } = useSheet();
|
||||
const { loggedIn, me } = useAuth();
|
||||
const queryClient = useQueryClient();
|
||||
const list = useInfiniteQuery({
|
||||
...listCommentsInfiniteOptions({ path: { post_id: postId } }),
|
||||
initialPageParam: { path: { post_id: postId } },
|
||||
getNextPageParam: (last) => last.next_cursor ?? undefined,
|
||||
});
|
||||
const add = useMutation(addCommentMutation());
|
||||
const [addFailed, setAddFailed] = useState(false);
|
||||
const [text, setText] = useState(draft ?? '');
|
||||
const inputRef = useRef<TextInput>(null);
|
||||
const comments = list.data?.pages.flatMap((p) => p.comments ?? []) ?? [];
|
||||
|
||||
const submit = () => {
|
||||
if (!loggedIn) return open({ type: 'login', then: { type: 'comments', postId, draft: text } });
|
||||
const body = text.trim();
|
||||
if (!body || add.isPending) return;
|
||||
setAddFailed(false);
|
||||
add.mutate(
|
||||
{ path: { post_id: postId }, body: { body } },
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
setAddFailed(!res.result?.success);
|
||||
if (!res.result?.success) return;
|
||||
setText('');
|
||||
queryClient.invalidateQueries({ queryKey: listCommentsInfiniteQueryKey({ path: { post_id: postId } }) });
|
||||
queryClient.invalidateQueries({ queryKey: getFeedQueryKey({ query: { region: region.code } }) });
|
||||
},
|
||||
onError: () => setAddFailed(true),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Body>
|
||||
{comments.length ? (
|
||||
<>
|
||||
{/* 다시 받은 좋아요 상태(로그인 바뀜 등)가 행에 반영되도록 key 에 넣는다 */}
|
||||
{comments.map((c) => (
|
||||
<CommentRow key={`${c.comment_id}:${c.liked}:${c.like_count}`} c={c} postId={postId} />
|
||||
))}
|
||||
{list.hasNextPage && (
|
||||
<Pressable onPress={() => list.fetchNextPage()} disabled={list.isFetchingNextPage} className="my-2 disabled:opacity-50">
|
||||
<Text className="text-center text-sm font-bold text-ink3">{list.isFetchingNextPage ? '불러오는 중…' : '댓글 더 보기'}</Text>
|
||||
</Pressable>
|
||||
)}
|
||||
</>
|
||||
) : loadOf(list) === 'loading' ? (
|
||||
<CommentsSkel />
|
||||
) : (
|
||||
<StateBox load={loadOf(list)} onRetry={() => list.refetch()} empty="아직 댓글이 없어요. 첫 댓글을 남겨 보세요." />
|
||||
)}
|
||||
</Body>
|
||||
<View className="flex-row justify-around pt-1" accessibilityLabel="빠른 이모지">
|
||||
{EMOJIS.map((e) => (
|
||||
<Pressable
|
||||
key={e}
|
||||
disabled={add.isPending}
|
||||
className="disabled:opacity-40"
|
||||
onPress={() => {
|
||||
setText((t) => (t + e).slice(0, 60));
|
||||
inputRef.current?.focus();
|
||||
}}
|
||||
>
|
||||
<Text className="text-[22px]">{e}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
<ErrorLine className="h-4 text-xs leading-4" text={addFailed ? '댓글을 올리지 못했어요. 다시 해 주세요.' : undefined} />
|
||||
<View className="flex-row items-center gap-2.5 border-t border-line px-3 py-2.5">
|
||||
<View className="flex-1">
|
||||
<Field ref={inputRef} round value={text} onChangeText={setText} editable={!add.isPending} maxLength={60} placeholder={me ? `${me.nickname}(으)로 댓글 달기…` : '댓글 달기…'} accessibilityLabel="댓글" returnKeyType="send" onSubmitEditing={submit} />
|
||||
</View>
|
||||
<Pressable onPress={submit} disabled={add.isPending || (loggedIn && !text.trim())} className="disabled:opacity-40">
|
||||
<Text className="font-extrabold text-rain">{add.isPending ? '올리는 중…' : '게시'}</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
import { getIndexOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import type { Factor, ResIndexDetail } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { loadOf } from '@nalssigak/shared/lib';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { useEffect } from 'react';
|
||||
import { Text, View } from 'react-native';
|
||||
import Svg, { Circle, Line, Polygon, Text as SvgText, TSpan } from 'react-native-svg';
|
||||
|
||||
import { Ic, Skel, StateBox } from '@/components/ui';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
import { Body, useSoft } from './parts';
|
||||
|
||||
const SLOT_KEYS = ['morning', 'day', 'evening', 'night'] as const;
|
||||
const SLOT_NAMES = { morning: '아침', day: '낮', evening: '저녁', night: '밤' } as const;
|
||||
const N4 = [0, 1, 2, 3];
|
||||
const N6 = [0, 1, 2, 3, 4, 5];
|
||||
|
||||
const labelLines = (label: string) => {
|
||||
const cut = label.indexOf(' ');
|
||||
return cut < 0 ? [label] : [label.slice(0, cut), label.slice(cut + 1)];
|
||||
};
|
||||
|
||||
function Radar({ name, factors, size = 250 }: { name: string; factors: Factor[]; size?: number }) {
|
||||
const night = useSky().kind === 'night';
|
||||
const c = size / 2;
|
||||
const r = size / 2 - 40;
|
||||
const n = factors.length;
|
||||
const pt = (i: number, v: number) => {
|
||||
const a = -Math.PI / 2 + (i * 2 * Math.PI) / n;
|
||||
return [c + Math.cos(a) * r * v, c + Math.sin(a) * r * v] as const;
|
||||
};
|
||||
const ring = (v: number) => factors.map((_, i) => pt(i, v).join(',')).join(' ');
|
||||
return (
|
||||
<View className="mt-2 items-center" accessibilityRole="image" accessibilityLabel={`${name} 요소별 점수`}>
|
||||
<Svg width={size} height={size} viewBox={`0 0 ${size} ${size}`}>
|
||||
{[0.25, 0.5, 0.75, 1].map((v) => (
|
||||
<Polygon key={v} points={ring(v)} fill={v === 1 ? (night ? '#222a5c' : '#f7f9fc') : 'none'} stroke={night ? 'rgba(255,255,255,0.18)' : '#d9e2ef'} strokeWidth={1.5} />
|
||||
))}
|
||||
{factors.map((f, i) => (
|
||||
<Line key={f.axis} x1={c} y1={c} x2={pt(i, 1)[0]} y2={pt(i, 1)[1]} stroke={night ? 'rgba(255,255,255,0.12)' : '#e3e9f2'} strokeWidth={1.5} />
|
||||
))}
|
||||
<Polygon points={factors.map((f, i) => pt(i, f.value / 100).join(',')).join(' ')} fill="rgba(255,122,69,0.38)" stroke="#ff7a45" strokeWidth={3} strokeLinejoin="round" />
|
||||
{factors.map((f, i) => (
|
||||
<Circle key={f.axis} cx={pt(i, f.value / 100)[0]} cy={pt(i, f.value / 100)[1]} r={4.5} fill="#fff" stroke="#ff7a45" strokeWidth={2.5} />
|
||||
))}
|
||||
{factors.map((f, i) => {
|
||||
const lines = labelLines(f.label);
|
||||
const [x, y] = pt(i, 1.24);
|
||||
return (
|
||||
<SvgText key={f.axis} x={x} y={y - (lines.length - 1) * 7} textAnchor="middle" fontFamily="Jua_400Regular" fontSize={13} fill={night ? '#eef1ff' : '#28304a'}>
|
||||
{lines.map((line, k) => (
|
||||
<TSpan key={k} x={x} dy={k === 0 ? 4 : 14}>
|
||||
{line}
|
||||
</TSpan>
|
||||
))}
|
||||
</SvgText>
|
||||
);
|
||||
})}
|
||||
</Svg>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function GakSkel() {
|
||||
const s = useSoft();
|
||||
return (
|
||||
<View>
|
||||
<View className="flex-row items-center gap-3">
|
||||
<View className="size-[58px] rounded-full bg-skel" />
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="h-6 w-28" />
|
||||
<Skel className="w-4/5" />
|
||||
</View>
|
||||
<Skel className="h-10 w-14" />
|
||||
</View>
|
||||
<View className="mt-2 aspect-square w-full max-w-[250px] self-center rounded-full bg-skel" />
|
||||
<View className="mt-2.5 flex-row gap-1.5">
|
||||
{N4.map((i) => (
|
||||
<View key={i} className="flex-1 items-center gap-1.5 rounded-2xl px-1 py-2.5" style={{ backgroundColor: s.soft }}>
|
||||
<Skel className="w-8" />
|
||||
<Skel className="h-6 w-9" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<View className="mt-3.5 gap-3">
|
||||
{N6.map((i) => (
|
||||
<View key={i} className="flex-row items-center gap-2.5">
|
||||
<Skel className="w-[70px]" />
|
||||
<View className="h-[9px] flex-1 rounded-full bg-skel" />
|
||||
<Skel className="w-10" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function GakSheet({ indexId, onTitle }: { indexId: number; onTitle: (t: string) => void }) {
|
||||
const { region } = useRegion();
|
||||
const s = useSoft();
|
||||
const q = useQuery(getIndexOptions({ path: { index_id: indexId }, query: { region: region.code } }));
|
||||
const d: ResIndexDetail | undefined = q.data;
|
||||
const g = d?.index;
|
||||
|
||||
useEffect(() => {
|
||||
onTitle(g ? `${g.rank}위 ${g.name}` : '계산 근거');
|
||||
}, [g, onTitle]);
|
||||
|
||||
const load = loadOf(q);
|
||||
if (!g) return <Body>{load === 'loading' ? <GakSkel /> : <StateBox load={load} onRetry={() => q.refetch()} empty="이 각의 계산 근거가 아직 없어요." />}</Body>;
|
||||
const factors = d.factors ?? [];
|
||||
const bands = d.bands ?? [];
|
||||
const now = bands.find((b) => b.current);
|
||||
return (
|
||||
<Body>
|
||||
<View className="flex-row items-center gap-3">
|
||||
<Ic name={g.icon} size={58} />
|
||||
<View className="flex-1">
|
||||
<Text className="font-jua text-[22px] text-ink">{g.name}</Text>
|
||||
{d.description && <Text className="mt-0.5 text-[13.5px] font-semibold text-ink2">{d.description}</Text>}
|
||||
</View>
|
||||
<Text className={`font-bagel text-[42px] ${g.active ? 'text-orange' : 'text-ink3'}`}>{g.score}</Text>
|
||||
</View>
|
||||
{!g.active && <Text className="mt-2 text-[13px] font-bold text-ink2">지금 시간대엔 해당 없어요. 점수는 오늘 가장 좋은 시간대 기준이에요.</Text>}
|
||||
{now && (
|
||||
<Text className="mt-3 overflow-hidden rounded-2xl px-3.5 py-2.5 text-[14.5px] font-bold text-ink" style={{ backgroundColor: s.warm }}>
|
||||
<Text className="font-jua text-orange">
|
||||
{now.low}~{now.high}점{' '}
|
||||
</Text>
|
||||
{now.text}
|
||||
</Text>
|
||||
)}
|
||||
{factors.length > 2 && <Radar name={g.name} factors={factors} />}
|
||||
{g.slots && g.slots.length > 0 && (
|
||||
<View className="mt-2.5 flex-row gap-1.5" accessibilityLabel="오늘 시간대별 점수">
|
||||
{SLOT_KEYS.map((k) => {
|
||||
const sl = g.slots?.find((x) => x.slot === k);
|
||||
const cur = g.active && g.slot === k;
|
||||
return (
|
||||
<View key={k} className="flex-1 items-center rounded-2xl px-1 py-2" style={{ backgroundColor: cur ? s.warm : s.soft }}>
|
||||
<Text className="text-xs font-extrabold text-ink2">
|
||||
{SLOT_NAMES[k]}
|
||||
{cur && ' · 지금'}
|
||||
</Text>
|
||||
<Text className={`font-bagel text-xl ${sl ? 'text-orange' : 'text-ink3'}`}>{sl ? sl.score : '–'}</Text>
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
)}
|
||||
{g.trend && g.trend.length > 0 && (
|
||||
<View className="mt-2.5 flex-row gap-1.5">
|
||||
{g.trend.map((t) => (
|
||||
<View key={t.day} className="flex-1 items-center rounded-2xl px-1 py-2.5" style={{ backgroundColor: s.soft }}>
|
||||
<Text numberOfLines={1} className="text-xs font-extrabold text-ink2">
|
||||
{t.label}
|
||||
</Text>
|
||||
<Text className="font-bagel text-2xl text-orange">{t.score}</Text>
|
||||
<Text className={`text-[11px] leading-4 font-extrabold text-ink2 ${t.estimated ? '' : 'opacity-0'}`}>예상</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
)}
|
||||
{bands.length > 0 && (
|
||||
<View className="mt-3.5 gap-1.5" accessibilityLabel="점수 구간별 설명">
|
||||
{bands.map((b) => (
|
||||
<View key={b.low} className={`flex-row items-start gap-2 ${b.current ? '' : 'opacity-45'}`}>
|
||||
<View className={`w-[62px] items-center rounded-full py-px ${b.current ? 'bg-orange' : 'bg-ink3'}`}>
|
||||
<Text className="font-jua text-xs text-white">
|
||||
{b.low}~{b.high}
|
||||
</Text>
|
||||
</View>
|
||||
<Text className="flex-1 text-[13px] font-semibold text-ink">{b.text}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
)}
|
||||
<View className="mt-3.5 gap-2.5">
|
||||
{factors.map((f) => (
|
||||
<View key={f.axis}>
|
||||
<View className="flex-row items-center gap-2.5">
|
||||
<Text className="w-[84px] text-[13.5px] font-bold text-ink">{f.label}</Text>
|
||||
<View className="h-[9px] flex-1 overflow-hidden rounded-full" style={{ backgroundColor: s.bar }}>
|
||||
<LinearGradient colors={['#ffc86e', '#ff7a45']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }} style={{ height: '100%', width: `${f.value}%` }} />
|
||||
</View>
|
||||
<Text className="w-[52px] text-right text-xs text-ink2">비중 {f.weight}%</Text>
|
||||
</View>
|
||||
<Text className="mt-0.5 ml-[94px] text-[12.5px] font-semibold text-ink2">{f.note}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<View className="mt-3.5 gap-1.5">
|
||||
{d.zero_reason && (
|
||||
<Text className="text-[13px] font-semibold text-ink2">
|
||||
<Text className="font-bold text-heart">오늘 걸린 조건:</Text> {d.zero_reason}
|
||||
</Text>
|
||||
)}
|
||||
{factors.length > 0 && (
|
||||
<Text className="text-[13px] font-semibold text-ink2">
|
||||
<Text className="font-bold text-ink">계산 방법:</Text> 요소 점수에 비중을 곱해 더하고, 가장 낮은 요소가 낮을수록 최대 25%까지 더 깎아요
|
||||
</Text>
|
||||
)}
|
||||
{d.zero_rules && (
|
||||
<Text className="text-[13px] font-semibold text-ink2">
|
||||
<Text className="font-bold text-ink">점수 깎이는 조건:</Text> {d.zero_rules}
|
||||
</Text>
|
||||
)}
|
||||
{d.limit && (
|
||||
<Text className="text-[13px] font-semibold text-ink2">
|
||||
<Text className="font-bold text-ink">반영 못 한 것:</Text> {d.limit}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
</Body>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,71 @@
|
||||
import { useMemo, useState, type ReactNode } from 'react';
|
||||
import { subscribeAuth } from '@nalssigak/shared/api/auth';
|
||||
import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react';
|
||||
import { KeyboardAvoidingView, Modal, Platform, Pressable, Text, View } from 'react-native';
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
|
||||
import { SheetContext, type SheetState } from '@/lib/sheet';
|
||||
import { SheetContext, useSheet, type SheetState } from '@/lib/sheet';
|
||||
|
||||
import { ArticleSheet, SeasonWeekSheet } from './article';
|
||||
import { CommentsSheet } from './comments';
|
||||
import { GakSheet } from './gak';
|
||||
import { LoginSheet } from './login';
|
||||
import { MeSheet } from './me';
|
||||
import { RegionSheet } from './region';
|
||||
|
||||
export function SheetProvider({ children }: { children: ReactNode }) {
|
||||
const [, setState] = useState<SheetState>(null);
|
||||
const api = useMemo(() => ({ open: (s: Exclude<SheetState, null>) => setState(s), close: () => setState(null) }), []);
|
||||
return <SheetContext value={api}>{children}</SheetContext>;
|
||||
const [state, setState] = useState<SheetState>(null);
|
||||
const open = useCallback((s: Exclude<SheetState, null>) => setState(s), []);
|
||||
const close = useCallback(() => setState(null), []);
|
||||
const api = useMemo(() => ({ open, close }), [open, close]);
|
||||
|
||||
// 로그인이 필요한 요청이 401을 받으면 로그인 창을 띄운다
|
||||
useEffect(() => subscribeAuth((reason) => reason === 'required' && open({ type: 'login' })), [open]);
|
||||
|
||||
return (
|
||||
<SheetContext value={api}>
|
||||
{children}
|
||||
<SheetHost state={state} onClose={close} />
|
||||
</SheetContext>
|
||||
);
|
||||
}
|
||||
|
||||
const TITLES = { article: '읽을거리', seasonWeek: '이번 주 특집', comments: '댓글', login: '로그인', me: '내 정보', region: '지역 바꾸기' } as const;
|
||||
|
||||
/** 아래에서 올라오는 창. 바깥을 누르거나 뒤로 가기(안드로이드)로 닫는다 */
|
||||
function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void }) {
|
||||
const { open } = useSheet();
|
||||
const { bottom } = useSafeAreaInsets();
|
||||
const [gakTitle, setGakTitle] = useState('');
|
||||
const [articleTitle, setArticleTitle] = useState('');
|
||||
|
||||
const then = state?.type === 'login' ? state.then : undefined;
|
||||
const title = !state ? '' : state.type === 'gak' ? gakTitle : state.type === 'article' ? articleTitle || TITLES.article : TITLES[state.type];
|
||||
|
||||
return (
|
||||
<Modal visible={state != null} transparent animationType="slide" onRequestClose={onClose} statusBarTranslucent>
|
||||
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} className="flex-1 justify-end">
|
||||
<Pressable onPress={onClose} accessibilityLabel="닫기" className="absolute inset-0 bg-[rgb(20_26_45/0.45)]" />
|
||||
{state && (
|
||||
<View accessibilityViewIsModal accessibilityLabel={title} className="max-h-[86%] w-full max-w-[440px] self-center rounded-t-[22px] bg-card" style={{ paddingBottom: bottom }}>
|
||||
<View className="border-b border-line px-4 pt-2 pb-2.5">
|
||||
<View className="mb-2.5 h-1 w-10 self-center rounded-full bg-line" />
|
||||
<Text numberOfLines={1} className="px-10 text-center text-[15px] font-extrabold text-ink">
|
||||
{title}
|
||||
</Text>
|
||||
<Pressable onPress={onClose} hitSlop={10} accessibilityRole="button" accessibilityLabel="닫기" className="absolute right-3 bottom-2 size-[30px] items-center justify-center">
|
||||
<Text className="text-xl text-ink2">×</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
{state.type === 'gak' && <GakSheet indexId={state.indexId} onTitle={setGakTitle} />}
|
||||
{state.type === 'article' && <ArticleSheet articleId={state.articleId} onTitle={setArticleTitle} />}
|
||||
{state.type === 'seasonWeek' && <SeasonWeekSheet />}
|
||||
{state.type === 'comments' && <CommentsSheet postId={state.postId} draft={state.draft} />}
|
||||
{state.type === 'login' && <LoginSheet onDone={onClose} onLoggedIn={then ? () => open(then) : onClose} />}
|
||||
{state.type === 'me' && <MeSheet onDone={onClose} />}
|
||||
{state.type === 'region' && <RegionSheet onDone={onClose} />}
|
||||
</View>
|
||||
)}
|
||||
</KeyboardAvoidingView>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { setTokens } from '@nalssigak/shared/api/auth';
|
||||
import { loginMutation, signupMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import type { ResAuth } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useState } from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { useAuth } from '@/lib/auth';
|
||||
|
||||
import { MeSheet } from './me';
|
||||
import { Body, ErrorLine, Field, useSoft } from './parts';
|
||||
|
||||
const AUTH_ERRORS: Record<string, string> = {
|
||||
AUTH_FAILED: '아이디나 비밀번호가 맞지 않아요.',
|
||||
AUTH_DUPLICATE_ID: '이미 쓰고 있는 아이디예요.',
|
||||
INVALID_INPUT: '아이디는 영어 소문자·숫자·_ 4~20자, 비밀번호는 8~64자, 닉네임은 2~12자로 써 주세요.',
|
||||
};
|
||||
|
||||
const MODES = [
|
||||
['login', '로그인'],
|
||||
['signup', '처음이에요'],
|
||||
] as const;
|
||||
|
||||
export function LoginSheet({ onDone, onLoggedIn }: { onDone: () => void; onLoggedIn: () => void }) {
|
||||
const { me } = useAuth();
|
||||
const s = useSoft();
|
||||
const [mode, setMode] = useState<'login' | 'signup'>('login');
|
||||
const [loginId, setLoginId] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [nickname, setNickname] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const login = useMutation(loginMutation());
|
||||
const signup = useMutation(signupMutation());
|
||||
const pending = login.isPending || signup.isPending;
|
||||
|
||||
const done = (res: ResAuth) => {
|
||||
if (!res.result?.success || !res.access_token) {
|
||||
setError(AUTH_ERRORS[res.result?.desc ?? ''] ?? '잠시 뒤에 다시 해 주세요.');
|
||||
return;
|
||||
}
|
||||
setTokens(res.access_token, res.refresh_token ?? null);
|
||||
onLoggedIn();
|
||||
};
|
||||
const fail = () => setError('서버에 닿지 못했어요. 잠시 뒤에 다시 해 주세요.');
|
||||
|
||||
// 웹 폼의 required·minLength 를 그대로 앞에서 확인한다
|
||||
const submit = () => {
|
||||
setError('');
|
||||
const id = loginId.trim();
|
||||
if (id.length < 4 || !password || (mode === 'signup' && (password.length < 8 || nickname.trim().length < 2))) {
|
||||
setError(AUTH_ERRORS.INVALID_INPUT);
|
||||
return;
|
||||
}
|
||||
if (mode === 'login') login.mutate({ body: { login_id: id, password } }, { onSuccess: done, onError: fail });
|
||||
else signup.mutate({ body: { login_id: id, password, nickname: nickname.trim() } }, { onSuccess: done, onError: fail });
|
||||
};
|
||||
|
||||
if (me) return <MeSheet onDone={onDone} />;
|
||||
|
||||
return (
|
||||
<Body className="gap-2.5">
|
||||
<Text className="text-center text-sm font-semibold text-ink2">좋아요·댓글은 로그인한 뒤에 할 수 있어요.</Text>
|
||||
<View className="flex-row gap-1 rounded-full p-1" style={{ backgroundColor: s.soft }} accessibilityLabel="로그인 또는 가입">
|
||||
{MODES.map(([m, l]) => (
|
||||
<Pressable key={m} accessibilityState={{ selected: mode === m }} onPress={() => setMode(m)} className={`flex-1 rounded-full py-2 ${mode === m ? 'bg-ink-btn' : ''}`}>
|
||||
<Text className={`text-center text-sm font-extrabold ${mode === m ? 'text-white' : 'text-ink2'}`}>{l}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
<Field value={loginId} onChangeText={setLoginId} autoCapitalize="none" autoCorrect={false} autoComplete="username" textContentType="username" maxLength={20} placeholder="아이디" accessibilityLabel="아이디" />
|
||||
<Field value={password} onChangeText={setPassword} secureTextEntry autoComplete={mode === 'login' ? 'current-password' : 'new-password'} textContentType={mode === 'login' ? 'password' : 'newPassword'} maxLength={64} placeholder={mode === 'signup' ? '비밀번호 (8자 이상)' : '비밀번호'} accessibilityLabel="비밀번호" onSubmitEditing={mode === 'login' ? submit : undefined} />
|
||||
{mode === 'signup' && <Field value={nickname} onChangeText={setNickname} maxLength={12} placeholder="닉네임 (2~12자)" accessibilityLabel="닉네임" onSubmitEditing={submit} />}
|
||||
<ErrorLine text={error} />
|
||||
<Pressable onPress={submit} disabled={pending} className="rounded-[14px] border-b-[5px] border-orange-deep bg-orange p-[13px] disabled:opacity-60">
|
||||
<Text className="text-center font-jua text-[17px] text-white">{mode === 'login' ? (pending ? '로그인 중…' : '로그인') : pending ? '가입하는 중…' : '가입하고 시작하기'}</Text>
|
||||
</Pressable>
|
||||
<Pressable onPress={onDone} className="rounded-[14px] p-[13px]">
|
||||
<Text className="text-center text-[15px] font-extrabold text-ink2">나중에 할게요</Text>
|
||||
</Pressable>
|
||||
</Body>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import { meQueryKey, updateMeMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { AVATAR_COLORS, CHARACTERS, MOODS } from '@nalssigak/shared/lib';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useState } from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { Avatar, Ic } from '@/components/ui';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
|
||||
import { Body, Field, useSoft } from './parts';
|
||||
|
||||
/** 내 정보: 캐릭터·배경색·기분·닉네임·로그아웃 */
|
||||
export function MeSheet({ onDone }: { onDone: () => void }) {
|
||||
const { me, logout } = useAuth();
|
||||
const s = useSoft();
|
||||
const queryClient = useQueryClient();
|
||||
const update = useMutation(updateMeMutation());
|
||||
const [nickname, setNickname] = useState(me?.nickname ?? '');
|
||||
const [error, setError] = useState('');
|
||||
if (!me) return null;
|
||||
|
||||
const save = (body: { nickname?: string; character?: string; color?: string; mood?: string }) => {
|
||||
setError('');
|
||||
update.mutate(
|
||||
{ body },
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
if (!res.result?.success) return setError(res.result?.desc === 'INVALID_INPUT' ? '닉네임은 2~12자로 써 주세요.' : '잠시 뒤에 다시 해 주세요.');
|
||||
queryClient.setQueryData(meQueryKey(), res);
|
||||
// 댓글에 보이는 내 캐릭터·닉네임도 바뀐다
|
||||
queryClient.invalidateQueries({ predicate: (q) => (q.queryKey[0] as { _id?: string } | undefined)?._id === 'listComments' });
|
||||
},
|
||||
onError: () => setError('서버에 닿지 못했어요. 잠시 뒤에 다시 해 주세요.'),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
// 저장하는 동안은 고른 값을 바로 선택으로 보여 준다. 실패하면 me 값으로 돌아간다
|
||||
const saving = update.isPending ? update.variables?.body : undefined;
|
||||
const character = saving?.character ?? me.character;
|
||||
const color = saving?.color ?? me.color;
|
||||
const mood = saving?.mood ?? me.mood;
|
||||
const nick = nickname.trim();
|
||||
|
||||
return (
|
||||
<Body className="gap-3">
|
||||
<View className="items-center gap-1.5">
|
||||
<Avatar character={me.character} color={me.color} mood={me.mood} size={64} />
|
||||
<Text className="text-center text-sm font-semibold text-ink2">{me.login_id}(으)로 로그인했어요</Text>
|
||||
</View>
|
||||
<View accessibilityLabel="내 캐릭터">
|
||||
<Text className="mb-2 text-sm font-extrabold text-ink">내 캐릭터</Text>
|
||||
<View className="flex-row flex-wrap gap-2">
|
||||
{CHARACTERS.map(([key, label]) => (
|
||||
<Pressable
|
||||
key={key}
|
||||
accessibilityRole="radio"
|
||||
accessibilityState={{ checked: character === key }}
|
||||
disabled={update.isPending}
|
||||
onPress={() => save({ character: key })}
|
||||
className={`items-center gap-1 rounded-[18px] border-2 py-2.5 ${character === key ? 'border-orange' : 'border-transparent'}`}
|
||||
style={{ width: '31.5%', backgroundColor: s.field }}
|
||||
>
|
||||
<Ic name={key} size={48} />
|
||||
<Text className={`font-jua text-[15px] ${character === key ? 'text-orange' : 'text-ink'}`}>{label}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
<View accessibilityLabel="배경색">
|
||||
<Text className="mb-2 text-sm font-extrabold text-ink">배경색</Text>
|
||||
<View className="flex-row flex-wrap gap-2.5">
|
||||
{Object.entries(AVATAR_COLORS).map(([key, hex]) => (
|
||||
<Pressable
|
||||
key={key}
|
||||
accessibilityRole="radio"
|
||||
accessibilityState={{ checked: color === key }}
|
||||
accessibilityLabel={key}
|
||||
disabled={update.isPending}
|
||||
onPress={() => save({ color: key })}
|
||||
className={`size-9 rounded-full border-[3px] ${color === key ? 'border-ink' : 'border-white'}`}
|
||||
style={{ backgroundColor: hex }}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
<View accessibilityLabel="오늘 기분">
|
||||
<Text className="mb-2 text-sm font-extrabold text-ink">오늘 기분</Text>
|
||||
<View className="flex-row flex-wrap gap-2">
|
||||
{MOODS.map(([key, emoji, label]) => (
|
||||
<Pressable
|
||||
key={key}
|
||||
accessibilityRole="radio"
|
||||
accessibilityState={{ checked: mood === key }}
|
||||
disabled={update.isPending}
|
||||
onPress={() => save({ mood: mood === key ? '' : key })}
|
||||
className={`items-center gap-0.5 rounded-[14px] border-2 py-2 ${mood === key ? 'border-orange' : 'border-transparent'}`}
|
||||
style={{ width: '23%', backgroundColor: s.field }}
|
||||
>
|
||||
<Text className="text-[22px] leading-[26px]">{emoji}</Text>
|
||||
<Text className={`text-xs font-bold ${mood === key ? 'text-orange' : 'text-ink2'}`}>{label}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
<Text className="mt-1.5 text-xs font-semibold text-ink3">한 번 더 누르면 지워져요</Text>
|
||||
</View>
|
||||
<View className="flex-row items-center gap-2">
|
||||
<View className="flex-1">
|
||||
<Field value={nickname} onChangeText={setNickname} maxLength={12} accessibilityLabel="닉네임" placeholder="닉네임 (2~12자)" onSubmitEditing={() => nick.length >= 2 && save({ nickname: nick })} />
|
||||
</View>
|
||||
<Pressable onPress={() => save({ nickname: nick })} disabled={update.isPending || nick === me.nickname || nick.length < 2} className="rounded-[14px] bg-ink-btn px-4 py-3 disabled:opacity-40">
|
||||
<Text className="text-sm font-extrabold text-white">{saving?.nickname != null ? '저장 중…' : '바꾸기'}</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
<Text className={`min-h-5 text-center text-[13px] font-bold ${saving ? 'text-ink2' : 'text-heart'}`}>{saving ? (saving.nickname == null ? '저장 중…' : '') : error}</Text>
|
||||
<Pressable
|
||||
onPress={() => {
|
||||
logout();
|
||||
onDone();
|
||||
}}
|
||||
className="rounded-[14px] p-[13px]"
|
||||
style={{ backgroundColor: s.soft }}
|
||||
>
|
||||
<Text className="text-center text-[15px] font-extrabold text-ink">로그아웃</Text>
|
||||
</Pressable>
|
||||
</Body>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { ReactNode, Ref } from 'react';
|
||||
import { ScrollView, Text, TextInput, View, type TextInputProps } from 'react-native';
|
||||
import Svg, { Path } from 'react-native-svg';
|
||||
|
||||
import { Skel } from '@/components/ui';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
/** 웹의 연한 판(#f3f6fb)·입력칸·따뜻한 판(#fff4ec)을 밤엔 어두운 판으로 */
|
||||
export function useSoft() {
|
||||
const night = useSky().kind === 'night';
|
||||
return {
|
||||
soft: night ? '#2b3470' : '#f3f6fb',
|
||||
field: night ? '#2b3470' : '#f7f9fc',
|
||||
fieldBorder: night ? 'rgba(255,255,255,0.12)' : '#dfe5ee',
|
||||
warm: night ? 'rgba(255,138,87,0.16)' : '#fff4ec',
|
||||
bar: night ? 'rgba(255,255,255,0.12)' : '#e3eaf4',
|
||||
placeholder: night ? '#a1a9db' : '#8a92aa',
|
||||
};
|
||||
}
|
||||
|
||||
export function Body({ children, className }: { children: ReactNode; className?: string }) {
|
||||
return (
|
||||
<ScrollView className="shrink" contentContainerClassName={`px-4 pt-3.5 pb-[18px] ${className ?? ''}`} keyboardShouldPersistTaps="handled">
|
||||
{children}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
/** 입력칸: 둥근 연한 판 */
|
||||
export function Field({ round = false, style, ...props }: TextInputProps & { round?: boolean; ref?: Ref<TextInput> }) {
|
||||
const s = useSoft();
|
||||
return (
|
||||
<TextInput
|
||||
placeholderTextColor={s.placeholder}
|
||||
className={`px-3.5 text-[16px] text-ink ${round ? 'rounded-full py-2.5' : 'rounded-[14px] py-3'}`}
|
||||
style={[{ backgroundColor: s.field, borderWidth: 1, borderColor: s.fieldBorder }, style]}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function HeartIcon({ size, fill, stroke }: { size: number; fill: string; stroke: string }) {
|
||||
return (
|
||||
<Svg viewBox="0 0 24 24" width={size} height={size} fill={fill} stroke={stroke} strokeWidth={2}>
|
||||
<Path d="M12 20.5s-8-4.9-8-11A4.6 4.6 0 0 1 12 6.8a4.6 4.6 0 0 1 8 2.7c0 6.1-8 11-8 11z" />
|
||||
</Svg>
|
||||
);
|
||||
}
|
||||
|
||||
const N3 = [0, 1, 2];
|
||||
|
||||
/** 읽을거리·이번 주 특집: 그림 150px · 머리말 · 제목 · 본문 */
|
||||
export function ArticleSkel() {
|
||||
return (
|
||||
<View className="gap-2.5">
|
||||
<View className="h-[150px] rounded-[20px] bg-skel" />
|
||||
<Skel className="w-24" />
|
||||
<Skel className="h-6 w-4/5" />
|
||||
{N3.map((k) => (
|
||||
<View key={k} className="gap-1.5">
|
||||
<Skel className="w-full" />
|
||||
<Skel className="w-2/3" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 빨간 안내 한 줄 (자리 높이는 그대로) */
|
||||
export function ErrorLine({ text, className }: { text?: string; className?: string }) {
|
||||
return <Text className={`min-h-5 text-center text-[13px] font-bold text-heart ${className ?? ''}`}>{text ?? ''}</Text>;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { listRegionsOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { loadOf } from '@nalssigak/shared/lib';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useDeferredValue, useState } from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
|
||||
import { Skel, StateBox } from '@/components/ui';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
|
||||
import { Body, Field } from './parts';
|
||||
|
||||
const N14 = Array.from({ length: 14 }, (_, i) => i);
|
||||
|
||||
function RegionsSkel() {
|
||||
return (
|
||||
<View className="mt-2">
|
||||
{N14.map((i) => (
|
||||
<View key={i} className="border-b-[1.5px] border-line px-1 py-3.5">
|
||||
<Skel className="w-28" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 지역 바꾸기: 구 이름으로 찾기 + 목록 */
|
||||
export function RegionSheet({ onDone }: { onDone: () => void }) {
|
||||
const { region, setRegion } = useRegion();
|
||||
const { me, logout } = useAuth();
|
||||
const { open } = useSheet();
|
||||
const [q, setQ] = useState('');
|
||||
const deferred = useDeferredValue(q.trim());
|
||||
const list = useQuery(listRegionsOptions(deferred ? { query: { q: deferred } } : undefined));
|
||||
const regions = list.data?.regions ?? [];
|
||||
const listLoad = loadOf(list);
|
||||
|
||||
return (
|
||||
<Body>
|
||||
<Field round value={q} onChangeText={setQ} placeholder="구 이름으로 찾기 (예: 마포)" accessibilityLabel="구 이름으로 찾기" />
|
||||
{listLoad === 'loading' && <RegionsSkel />}
|
||||
{listLoad !== 'loading' && !regions.length && <StateBox load={listLoad} onRetry={() => list.refetch()} empty="찾는 구가 없어요." />}
|
||||
<View className={`mt-2 ${list.isPlaceholderData ? 'opacity-60' : ''}`}>
|
||||
{regions.map((r) => {
|
||||
const here = r.code === region.code;
|
||||
return (
|
||||
<Pressable
|
||||
key={r.code}
|
||||
accessibilityState={{ selected: here }}
|
||||
onPress={() => {
|
||||
setRegion(r);
|
||||
onDone();
|
||||
}}
|
||||
className="flex-row items-center justify-between border-b-[1.5px] border-line px-1 py-3"
|
||||
>
|
||||
<Text className={`font-jua text-[17px] ${here ? 'text-orange' : 'text-ink'}`}>{r.name}</Text>
|
||||
{here && <Text className="text-xs font-extrabold text-orange">지금 보는 곳</Text>}
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
<View className="mt-4 flex-row items-center justify-center gap-2">
|
||||
<Text className="text-[13px] font-bold text-ink2">{me ? `${me.nickname}(으)로 로그인했어요` : '로그인하면 좋아요·댓글을 쓸 수 있어요'}</Text>
|
||||
<Pressable onPress={me ? logout : () => open({ type: 'login' })} hitSlop={8}>
|
||||
<Text className="text-[13px] font-extrabold text-rain">{me ? '로그아웃' : '로그인'}</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</Body>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
import type { TimeKind } from '@nalssigak/shared/lib';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { useEffect } from 'react';
|
||||
import { StyleSheet, View } from 'react-native';
|
||||
import Animated, { cancelAnimation, Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withDelay, withRepeat, withTiming } from 'react-native-reanimated';
|
||||
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
const KINDS: TimeKind[] = ['morning', 'day', 'sunset', 'night'];
|
||||
|
||||
const SKY: Record<TimeKind, { colors: readonly [string, string, string]; locations: readonly [number, number, number] }> = {
|
||||
morning: { colors: ['#ffe0c4', '#fff0e2', '#e4f2ff'], locations: [0, 0.38, 1] },
|
||||
day: { colors: ['#cde7ff', '#e9f5ff', '#f7fbff'], locations: [0, 0.45, 1] },
|
||||
@@ -11,16 +15,44 @@ const SKY: Record<TimeKind, { colors: readonly [string, string, string]; locatio
|
||||
night: { colors: ['#0e1433', '#1b2356', '#2a2e6e'], locations: [0, 0.5, 1] },
|
||||
};
|
||||
|
||||
const STARS = Array.from({ length: 46 }, (_, i) => ({ left: `${(i * 41 + 7) % 100}%`, top: `${(i * 67 + 3) % 96}%`, size: 1 + (i % 3) * 0.8, opacity: 0.4 + ((i * 7) % 6) / 10 }) as const);
|
||||
const STARS = Array.from({ length: 46 }, (_, i) => ({ left: `${(i * 41 + 7) % 100}%`, top: `${(i * 67 + 3) % 96}%`, size: 1 + (i % 3) * 0.8, period: (3 + (i % 5)) * 1000, delay: ((i * 0.7) % 6) * 1000 }) as const);
|
||||
|
||||
/** 화면 전체 하늘: 시간대별 색, 밤에는 별 */
|
||||
/** 시간대 하나의 하늘 판. 고른 시간대만 1.4초 동안 서서히 드러난다 */
|
||||
function Layer({ kind, on, reduce }: { kind: TimeKind; on: boolean; reduce: boolean }) {
|
||||
const shown = useSharedValue(on ? 1 : 0);
|
||||
useEffect(() => {
|
||||
shown.value = reduce ? (on ? 1 : 0) : withTiming(on ? 1 : 0, { duration: 1400, easing: Easing.ease });
|
||||
}, [on, reduce, shown]);
|
||||
const style = useAnimatedStyle(() => ({ opacity: shown.value }));
|
||||
return (
|
||||
<Animated.View style={[StyleSheet.absoluteFill, style]}>
|
||||
<LinearGradient {...SKY[kind]} style={StyleSheet.absoluteFill} />
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 밤 별: 제각각 주기로 반짝인다 */
|
||||
function Star({ star, reduce }: { star: (typeof STARS)[number]; reduce: boolean }) {
|
||||
const glow = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
if (reduce) return;
|
||||
glow.value = withDelay(star.delay, withRepeat(withTiming(1, { duration: star.period / 2, easing: Easing.inOut(Easing.ease) }), -1, true));
|
||||
return () => cancelAnimation(glow);
|
||||
}, [reduce, glow, star]);
|
||||
const style = useAnimatedStyle(() => ({ opacity: reduce ? 0.7 : 0.25 + glow.value * 0.75 }));
|
||||
return <Animated.View style={[{ position: 'absolute', left: star.left, top: star.top, width: star.size, height: star.size, borderRadius: star.size, backgroundColor: '#fff', boxShadow: '0 0 6px rgb(255 255 255 / 0.8)' }, style]} />;
|
||||
}
|
||||
|
||||
/** 화면 전체 하늘: 시간대별 색이 서서히 바뀌고, 밤에는 별이 반짝인다 */
|
||||
export function SkyBg() {
|
||||
const { kind } = useSky();
|
||||
const reduce = useReducedMotion();
|
||||
return (
|
||||
<View style={StyleSheet.absoluteFill} pointerEvents="none">
|
||||
<LinearGradient {...SKY[kind]} style={StyleSheet.absoluteFill} />
|
||||
{kind === 'night' &&
|
||||
STARS.map((s, i) => <View key={i} style={{ position: 'absolute', left: s.left, top: s.top, width: s.size, height: s.size, borderRadius: s.size, backgroundColor: '#fff', opacity: s.opacity }} />)}
|
||||
{KINDS.map((k) => (
|
||||
<Layer key={k} kind={k} on={k === kind} reduce={reduce} />
|
||||
))}
|
||||
{kind === 'night' && STARS.map((s, i) => <Star key={i} star={s} reduce={reduce} />)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 웹 b.css 노을 탭 그라데이션. 등급별 하늘색(히어로·3일 타일)과 시간표 막대
|
||||
type Grad = { colors: readonly [string, string, ...string[]]; locations?: readonly [number, number, ...number[]] };
|
||||
|
||||
export const GRADE_SKY: Record<string, { hero: Grad; tile: Grad }> = {
|
||||
잿빛: { hero: { colors: ['#6f7690', '#9aa0b4', '#b9b4c0'], locations: [0, 0.55, 1] }, tile: { colors: ['#8f8aa5', '#b9b0bf'] } },
|
||||
은은함: { hero: { colors: ['#4b5aa8', '#7f86c6', '#e9b9a8', '#ffb27a'], locations: [0, 0.4, 0.78, 1] }, tile: { colors: ['#7f86c6', '#e9b9a8', '#f6b07a'], locations: [0, 0.7, 1] } },
|
||||
고움: { hero: { colors: ['#5b3f9e', '#c2559a', '#ff7a6a', '#ffb35c'], locations: [0, 0.45, 0.78, 1] }, tile: { colors: ['#5b3f9e', '#c2559a', '#ff7a6a'], locations: [0, 0.55, 1] } },
|
||||
붉음: { hero: { colors: ['#4a2a8a', '#b0306a', '#ff4a3a', '#ff9a3c'], locations: [0, 0.4, 0.72, 1] }, tile: { colors: ['#4a2a8a', '#b0306a', '#ff4a3a'], locations: [0, 0.5, 1] } },
|
||||
};
|
||||
|
||||
export const skyOf = (grade?: string | null) => GRADE_SKY[grade ?? ''] ?? GRADE_SKY['은은함'];
|
||||
|
||||
export const RAIL = {
|
||||
sunset: { colors: ['#f2b84b', '#f6844e', '#e8506a', '#8c5aa6', '#2d3f8f'], locations: [0, 0.45, 0.62, 0.82, 1] },
|
||||
sunrise: { colors: ['#2d3f8f', '#8c5aa6', '#e8506a', '#f6844e', '#f2b84b'], locations: [0, 0.25, 0.45, 0.6, 1] },
|
||||
} satisfies Record<string, Grad>;
|
||||
@@ -0,0 +1,189 @@
|
||||
import type { BestTime, SkyPlanData } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { clockShort } from '@nalssigak/shared/lib';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { useState, type ReactNode } from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
import { useCSSVariable } from 'uniwind';
|
||||
|
||||
import { RAIL, skyOf } from '@/components/sky/colors';
|
||||
import { SitSun, Skyline } from '@/components/sky/skyline';
|
||||
import { MapLink, Skel } from '@/components/ui';
|
||||
|
||||
const SHADOW = { textShadowColor: 'rgb(50 25 70 / 0.35)', textShadowOffset: { width: 0, height: 2 }, textShadowRadius: 10 };
|
||||
const FOUR = [0, 1, 2, 3];
|
||||
|
||||
/** 히어로엔 답만: 노을 피크 시각과 어떻게 물드는지. 상자는 불러오는 중·실패·빈 값 모두 같은 크기 */
|
||||
export function SkyHero({ plan, children }: { plan?: SkyPlanData; children?: ReactNode }) {
|
||||
const g = skyOf(plan?.grade_label).hero;
|
||||
return (
|
||||
<View className="mx-3 mt-1 min-h-[230px] overflow-hidden rounded-[32px] px-5 pt-5 pb-14">
|
||||
<LinearGradient colors={g.colors} locations={g.locations} style={{ position: 'absolute', inset: 0 }} />
|
||||
<SitSun />
|
||||
<Skyline />
|
||||
{children ?? (
|
||||
<View>
|
||||
{plan ? (
|
||||
<Text className="font-jua text-[28px] leading-tight text-white" style={SHADOW}>
|
||||
{plan.title}
|
||||
</Text>
|
||||
) : (
|
||||
<Skel className="h-7 w-[230px]" />
|
||||
)}
|
||||
{!plan ? (
|
||||
<Skel className="mt-2 w-[180px]" />
|
||||
) : plan.situation_label ? (
|
||||
<Text className="mt-1.5 text-[15px] font-bold text-white" style={SHADOW}>
|
||||
{plan.situation_label}
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 오늘·내일·모레를 그날 예상 하늘색 타일로. 누르면 그날로 */
|
||||
export function DayTiles({ plans, day, onPick }: { plans: SkyPlanData[]; day?: string; onPick: (day: string) => void }) {
|
||||
const ink = String(useCSSVariable('--color-ink'));
|
||||
return (
|
||||
<View className="mx-3 mt-2.5 flex-row gap-2">
|
||||
{plans.map((p) => {
|
||||
const g = skyOf(p.grade_label).tile;
|
||||
const on = p.day === day;
|
||||
return (
|
||||
<Pressable key={p.day} accessibilityState={{ selected: on }} onPress={() => onPick(p.day)} className="flex-1 rounded-[18px] p-[2px]" style={{ borderWidth: 3, borderColor: on ? ink : 'transparent' }}>
|
||||
<View className="overflow-hidden rounded-2xl px-2.5 pt-2 pb-2.5">
|
||||
<LinearGradient colors={g.colors} locations={g.locations} start={{ x: 0.2, y: 0 }} end={{ x: 0.8, y: 1 }} style={{ position: 'absolute', inset: 0 }} />
|
||||
<Text className="text-[11.5px] font-extrabold text-white">{p.when}</Text>
|
||||
<Text className="font-jua text-lg leading-tight text-white">{p.best_at ? clockShort(p.best_at) : '–'}</Text>
|
||||
<Text className="text-[11.5px] font-bold text-white">
|
||||
{p.grade_label} {p.score}
|
||||
</Text>
|
||||
</View>
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function Toggle({ label, children, end }: { label: ReactNode; children: ReactNode; end?: boolean }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<View>
|
||||
<Pressable onPress={() => setOpen(!open)} accessibilityState={{ expanded: open }} className={`flex-row items-center gap-1.5 ${end ? 'justify-between' : ''}`}>
|
||||
{label}
|
||||
</Pressable>
|
||||
{open && children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const Q = ({ className = 'bg-card/80' }: { className?: string }) => (
|
||||
<View className={`size-[18px] items-center justify-center rounded-full ${className}`}>
|
||||
<Text className="text-[11px] font-extrabold text-ink">?</Text>
|
||||
</View>
|
||||
);
|
||||
|
||||
/** 노을 점수 뜻. 지금 하늘이 아니라 해 질(뜰) 무렵 예보라는 것도 */
|
||||
export function ScoreHelp({ plan }: { plan: SkyPlanData }) {
|
||||
const sunAt = plan.timeline?.find((t) => t.kind === 'sun')?.at;
|
||||
const rise = plan.kind === 'sunrise';
|
||||
return (
|
||||
<View className="mx-3 mt-1.5 px-1">
|
||||
<Toggle
|
||||
end
|
||||
label={
|
||||
<>
|
||||
<Text className="text-[12px] font-bold text-ink2">노을 점수 100점 만점 · 높을수록 붉어요</Text>
|
||||
<Q />
|
||||
</>
|
||||
}
|
||||
>
|
||||
<Text className="mt-1.5 rounded-xl bg-card/70 px-2.5 py-2 text-[12px] leading-snug font-semibold text-ink2">
|
||||
80점 넘으면 붉게, 60점 넘으면 곱게, 40점 넘으면 은은하게 물들어요.
|
||||
{sunAt && ` 해 ${rise ? '뜰' : '질'} 무렵(${new Date(sunAt).getHours()}시) 날씨 예보로 계산했고, 노을 피크 시각은 해 ${rise ? '뜨기 10~20분 전' : '지고 10~20분 뒤'}로 어림한 거라 실제와 다를 수 있어요.`}
|
||||
</Text>
|
||||
</Toggle>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 언제 보면 좋을까: 왼쪽 세로 줄 색이 그 시각 하늘색, 노을 피크만 강조 */
|
||||
export function Timeline({ rows, kind = 'sunset' }: { rows?: BestTime[]; kind?: SkyPlanData['kind'] }) {
|
||||
const rail = RAIL[kind === 'sunrise' ? 'sunrise' : 'sunset'];
|
||||
const list = rows ?? FOUR.map(() => undefined);
|
||||
return (
|
||||
<View className="mx-3 mt-3 rounded-[22px] border-b-[5px] border-shade bg-card px-4 pt-3.5 pb-3">
|
||||
<View className="flex-row gap-3">
|
||||
<LinearGradient colors={rail.colors} locations={rail.locations} style={{ width: 12, borderRadius: 6 }} />
|
||||
<View className="flex-1">
|
||||
{list.map((t, i) => {
|
||||
const peak = t?.kind === 'peak';
|
||||
return (
|
||||
<View key={t?.kind ?? i} className={`flex-row items-baseline gap-2.5 ${peak ? '-mx-1.5 my-0.5 rounded-xl bg-[#fff1f2] px-2.5 py-2' : 'py-1.5'}`} style={!peak && i < list.length - 1 ? { borderBottomWidth: 1 } : undefined}>
|
||||
<View className="min-w-[96px]">
|
||||
{t ? <Text className={`font-jua ${peak ? 'text-[20px] text-[#d23d5a]' : 'text-[17px] text-ink'}`}>{t.end ? `${clockShort(t.at)}~${clockShort(t.end)}` : clockShort(t.at)}</Text> : <Skel className="w-11" />}
|
||||
</View>
|
||||
{t ? <Text className={`flex-1 ${peak ? 'font-jua text-base text-[#d23d5a]' : 'text-[13.5px] font-bold text-ink2'}`}>{t.label}</Text> : <Skel className="w-20" />}
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
</View>
|
||||
{rows && (
|
||||
<View className="mt-2">
|
||||
<Toggle
|
||||
label={
|
||||
<>
|
||||
<Q className="bg-[#f1ebe3]" />
|
||||
<Text className="text-[12px] font-bold text-ink2">골든아워·블루아워가 뭐예요</Text>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<Text className="mt-1.5 rounded-xl bg-[#faf6f1] px-2.5 py-2 text-[12px] leading-snug text-[#5a6380]">
|
||||
<Text className="font-bold text-[#28304a]">골든아워</Text> 해가 {kind === 'sunrise' ? '뜬 뒤' : '지기 전'}, 햇빛이 금빛으로 물드는 시간{'\n'}
|
||||
<Text className="font-bold text-[#28304a]">블루아워</Text> 해가 {kind === 'sunrise' ? '뜨기 전' : '진 뒤'}, 하늘이 짙은 파랑으로 남는 시간
|
||||
</Text>
|
||||
</Toggle>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const ROW = 'flex-row items-center gap-2.5 px-1 py-3';
|
||||
|
||||
export function LiSkel({ ghost = false, last = false }: { ghost?: boolean; last?: boolean }) {
|
||||
return (
|
||||
<View className={`${ROW} border-line ${ghost ? 'opacity-0' : ''}`} style={last ? undefined : { borderBottomWidth: 1.5 }}>
|
||||
<View className="w-[34px] items-center">
|
||||
<Skel className="w-5" />
|
||||
</View>
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="h-4 w-24" />
|
||||
<Skel className="w-40" />
|
||||
</View>
|
||||
<Skel className="w-9" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 번호 · 이름(+설명) · 오른쪽 값 한 줄 */
|
||||
export function Li({ no, title, sub, right, mine = false, place, last = false }: { no: number; title: string; sub?: string | null; right: string; mine?: boolean; place?: string; last?: boolean }) {
|
||||
return (
|
||||
<View className={`${ROW} border-line ${mine ? 'rounded-2xl bg-card' : ''}`} style={last ? undefined : { borderBottomWidth: 1.5 }}>
|
||||
<Text className="w-[34px] text-center font-bagel text-xl text-orange">{no}</Text>
|
||||
<View className="min-w-0 flex-1">
|
||||
<Text className="font-jua text-[17px] text-ink">
|
||||
{place ? <MapLink place={place}>{title}</MapLink> : title}
|
||||
{mine && <Text className="text-xs font-extrabold text-rain"> 내 지역</Text>}
|
||||
</Text>
|
||||
<Text numberOfLines={1} className="text-[12.5px] font-semibold text-ink2">
|
||||
{sub || ' '}
|
||||
</Text>
|
||||
</View>
|
||||
<Text className="font-jua text-base text-ink">{right}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { View } from 'react-native';
|
||||
import Svg, { Defs, Polygon, RadialGradient, Rect, Stop } from 'react-native-svg';
|
||||
|
||||
// 웹 .b-skyline::after 의 clip-path 를 그대로 (0~100 비율)
|
||||
const POINTS = '0,55 8,55 8,30 15,30 15,50 22,50 22,10 28,10 28,45 36,45 36,25 44,25 44,55 52,55 52,35 60,35 60,5 66,5 66,40 74,40 74,20 82,20 82,50 90,50 90,30 100,30 100,100 0,100';
|
||||
|
||||
/** 아래에 깔리는 동네 건물 실루엣. height 는 상자 높이 대비 비율 */
|
||||
export function Skyline({ height = '22%' }: { height?: `${number}%` }) {
|
||||
return (
|
||||
<View pointerEvents="none" style={{ position: 'absolute', left: 0, right: 0, bottom: 0, height }}>
|
||||
<Svg width="100%" height="100%" viewBox="0 0 100 100" preserveAspectRatio="none">
|
||||
<Polygon points={POINTS} fill="#2d2440" />
|
||||
</Svg>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 건물 뒤로 지는 해 (.b-sit-sun) */
|
||||
export function SitSun({ size = 112, bottom = 24, opacity = 1 }: { size?: number; bottom?: number; opacity?: number }) {
|
||||
return (
|
||||
<View pointerEvents="none" style={{ position: 'absolute', bottom, left: '50%', marginLeft: -size / 2, width: size, height: size, opacity }}>
|
||||
<Svg width={size} height={size} viewBox="0 0 2 2">
|
||||
<Defs>
|
||||
<RadialGradient id="sitsun" cx="1" cy="1" r="1" gradientUnits="userSpaceOnUse">
|
||||
<Stop offset="0" stopColor="#fff6dd" />
|
||||
<Stop offset="0.38" stopColor="#ffd08f" />
|
||||
<Stop offset="0.7" stopColor="#ffa05a" stopOpacity={0} />
|
||||
</RadialGradient>
|
||||
</Defs>
|
||||
<Rect x="0" y="0" width="2" height="2" fill="url(#sitsun)" />
|
||||
</Svg>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import type { Hero as HeroData, ResWeatherToday, TopIndex } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { kindOfHour, kst, type Load, type TimeKind, WEEKDAYS } from '@nalssigak/shared/lib';
|
||||
import { KINDS, moonPath, PREVIEW, SLOT_KEY, WANING, WEATHER_ICON, weatherOf } from '@nalssigak/shared/lib/today';
|
||||
import { KINDS, moonPath, PREVIEW, SLOT_KEY, WANING, type Weather, WEATHER_ICON, weatherOf } from '@nalssigak/shared/lib/today';
|
||||
import { deg, slotAt } from '@nalssigak/shared/lib/weatherText';
|
||||
import { useEffect, useState, type ReactNode } from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
import { Pressable, Text, View, type DimensionValue, type ViewStyle } from 'react-native';
|
||||
import Animated, { cancelAnimation, Easing, interpolate, useAnimatedStyle, useReducedMotion, useSharedValue, withDelay, withRepeat, withTiming } from 'react-native-reanimated';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import Svg, { Defs, Path, RadialGradient, Rect, Stop } from 'react-native-svg';
|
||||
|
||||
@@ -28,6 +29,77 @@ const ORB: Record<'sun' | 'sunset' | 'night', { stops: [string, string, string,
|
||||
};
|
||||
const STARS = Array.from({ length: 26 }, (_, i) => ({ left: `${(i * 37) % 100}%`, top: `${(i * 53) % 60}%`, opacity: 0.4 + ((i * 7) % 6) / 10 }) as const);
|
||||
|
||||
// 구름 자리·떨어지는 지연·둥둥 주기 (웹 CLOUDS). 구름 수: 구름 많음 둘, 흐림·비·눈 셋
|
||||
const CLOUDS = [
|
||||
{ top: 36, left: '5%', w: 84, h: 32, d: 100, f: 6000 },
|
||||
{ top: 96, left: '63%', w: 96, h: 36, d: 250, f: 6400 },
|
||||
{ top: 30, left: '72%', w: 64, h: 28, d: 400, f: 5400 },
|
||||
] as const;
|
||||
const CLOUD_N: Record<Weather, number> = { clear: 0, partly: 2, cloudy: 3, rain: 3, snow: 3, sleet: 3 };
|
||||
|
||||
// 비·눈 줄기: 위치·주기를 엇갈려 고르게
|
||||
const DROPS = Array.from({ length: 22 }, (_, i) => ({ left: `${(i * 41) % 100}%`, top: `${(i * 29) % 90}%`, delay: ((i * 37) % 100) * 10, dur: 550 + ((i * 13) % 5) * 100 }) as const);
|
||||
const FLAKES = Array.from({ length: 16 }, (_, i) => ({ left: `${(i * 47) % 100}%`, top: `${(i * 31) % 90}%`, delay: ((i * 53) % 100) * 40, dur: 3200 + ((i * 7) % 5) * 500 }) as const);
|
||||
|
||||
/** 하늘에서 떨어진 뒤 둥둥 (웹 b-fall: b-drop 1.05초 뒤 b-float 무한). d·f 는 밀리초 */
|
||||
function Fall({ d, f, amp = 9, style, children }: { d: number; f: number; amp?: number; style?: ViewStyle; children: ReactNode }) {
|
||||
const reduce = useReducedMotion();
|
||||
const drop = useSharedValue(reduce ? 1 : 0);
|
||||
const float = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
if (reduce) return;
|
||||
drop.value = withDelay(d, withTiming(1, { duration: 1050, easing: Easing.bezier(0.22, 0.9, 0.3, 1) }));
|
||||
float.value = withDelay(d + 1050, withRepeat(withTiming(1, { duration: f / 2, easing: Easing.inOut(Easing.ease) }), -1, true));
|
||||
return () => {
|
||||
cancelAnimation(drop);
|
||||
cancelAnimation(float);
|
||||
};
|
||||
}, [reduce, d, f, drop, float]);
|
||||
const anim = useAnimatedStyle(() => {
|
||||
const p = drop.value;
|
||||
const y = interpolate(p, [0, 0.72, 0.86, 1], [-400, 0, -10, 0]) - amp * float.value;
|
||||
const rot = interpolate(p, [0, 0.72, 1], [-10, 2, 0]) + 1.2 * float.value;
|
||||
return {
|
||||
opacity: interpolate(p, [0, 0.55, 1], [0, 1, 1]),
|
||||
transform: [{ translateY: y }, { rotate: `${rot}deg` }, { scaleX: interpolate(p, [0, 0.72, 0.86, 1], [1, 1.04, 1, 1]) }, { scaleY: interpolate(p, [0, 0.72, 0.86, 1], [1, 0.96, 1, 1]) }],
|
||||
};
|
||||
});
|
||||
return <Animated.View style={[style, anim]}>{children}</Animated.View>;
|
||||
}
|
||||
|
||||
/** 둥근 구름: 몸통 위에 동그라미 둘을 겹친다 (웹 .b-cloud ::before/::after) */
|
||||
function Cloud({ w, h, night }: { w: number; h: number; night: boolean }) {
|
||||
const bg = night ? '#c9cdf0' : '#fff';
|
||||
const big = w * 0.46;
|
||||
const small = w * 0.36;
|
||||
return (
|
||||
<View style={{ width: w, height: h }}>
|
||||
<View style={{ position: 'absolute', left: w * 0.16, top: -h * 0.58, width: big, height: big, borderRadius: big, backgroundColor: bg }} />
|
||||
<View style={{ position: 'absolute', left: w * 0.5, top: -h * 0.36, width: small, height: small, borderRadius: small, backgroundColor: bg }} />
|
||||
<View style={{ width: w, height: h, borderRadius: h, backgroundColor: bg, boxShadow: '0 16px 28px rgb(40 70 120 / 0.13)' }} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** 비 줄기·눈송이 하나: 위에서 아래로 계속 떨어진다. 동작 줄이기면 제자리에 멈춘다 */
|
||||
function Particle({ left, top, delay, dur, snow, light }: { left: DimensionValue; top: DimensionValue; delay: number; dur: number; snow: boolean; light: boolean }) {
|
||||
const reduce = useReducedMotion();
|
||||
const t = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
if (reduce) return;
|
||||
t.value = withDelay(delay, withRepeat(withTiming(1, { duration: dur, easing: Easing.linear }), -1, false));
|
||||
return () => cancelAnimation(t);
|
||||
}, [reduce, delay, dur, t]);
|
||||
const anim = useAnimatedStyle(() => ({ transform: [{ translateX: (snow ? 18 : -8) * t.value }, { translateY: 440 * t.value }] }));
|
||||
const place: ViewStyle = { position: 'absolute', left, top: reduce ? top : -24 };
|
||||
if (snow) return <Animated.View style={[place, { width: 7, height: 7, borderRadius: 7, backgroundColor: '#fff', boxShadow: '0 0 4px rgb(120 150 200 / 0.5)' }, anim]} />;
|
||||
return (
|
||||
<Animated.View style={[place, anim]}>
|
||||
<LinearGradient colors={['transparent', light ? 'rgba(220,230,255,0.7)' : 'rgba(80,130,200,0.7)']} style={{ width: 2, height: 18, borderRadius: 2 }} />
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
function useNow(ms = 20000) {
|
||||
const [now, setNow] = useState(() => new Date());
|
||||
useEffect(() => {
|
||||
@@ -80,6 +152,8 @@ export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) {
|
||||
const bubble = slotTop ? (slotTop.score >= 70 ? `${when}은 ${slotTop.name}!` : `${when}은 쉬어 가요`) : hero ? (hero.bubble ?? '지금은 쉬어 가요') : failed(feedLoad) ? '앗, 날씨를 못 불러왔어요' : null;
|
||||
const status = hero?.status ?? [];
|
||||
const gray = !dark && weather !== 'clear' && weather !== 'partly';
|
||||
const rain = weather === 'rain' || weather === 'sleet';
|
||||
const snow = weather === 'snow' || weather === 'sleet';
|
||||
const orb = ORB[kind === 'sunset' ? 'sunset' : kind === 'night' ? 'night' : 'sun'];
|
||||
const text = dark ? 'text-white' : 'text-[#28304a]';
|
||||
|
||||
@@ -87,31 +161,44 @@ export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) {
|
||||
<View className="mx-3 mt-1 overflow-hidden rounded-[28px] px-4 pt-3 pb-3">
|
||||
<LinearGradient colors={HERO_BG[gray ? 'gray' : kind]} locations={kind === 'night' ? [0, 0.6, 1] : [0, 0.5, 1]} style={{ position: 'absolute', inset: 0 }} />
|
||||
{kind === 'night' && STARS.map((s, i) => <View key={i} className="absolute size-[3px] rounded-full bg-white" style={{ left: s.left, top: s.top, opacity: s.opacity }} />)}
|
||||
{(rain || snow) && (
|
||||
<View pointerEvents="none" style={{ position: 'absolute', inset: 0 }}>
|
||||
{rain && DROPS.map((p, i) => <Particle key={`r${i}`} {...p} snow={false} light={dark} />)}
|
||||
{snow && FLAKES.map((p, i) => <Particle key={`s${i}`} {...p} snow light={dark} />)}
|
||||
</View>
|
||||
)}
|
||||
<Text className={`text-[14px] font-bold opacity-80 ${text}`}>
|
||||
{t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일
|
||||
</Text>
|
||||
<View className="h-[146px] items-center">
|
||||
<View className="mt-2 size-32 items-center justify-center" style={{ boxShadow: `0 20px 40px ${kind === 'night' ? 'rgb(190 180 255 / 0.35)' : kind === 'sunset' ? 'rgb(255 150 110 / 0.4)' : 'rgb(240 106 58 / 0.32)'}`, borderRadius: 64 }}>
|
||||
<Svg viewBox="-1 -1 2 2" width={128} height={128} style={{ position: 'absolute' }}>
|
||||
<Defs>
|
||||
<RadialGradient id="orb" cx="-0.32" cy="-0.4" r="1.4" gradientUnits="userSpaceOnUse">
|
||||
<Stop offset="0" stopColor={orb.stops[0]} />
|
||||
<Stop offset="0.3" stopColor={orb.stops[1]} />
|
||||
<Stop offset="0.68" stopColor={orb.stops[2]} />
|
||||
<Stop offset="1" stopColor={orb.stops[3]} />
|
||||
</RadialGradient>
|
||||
</Defs>
|
||||
<Rect x="-1" y="-1" width="2" height="2" rx="1" fill="url(#orb)" opacity={gray ? 0.85 : 1} />
|
||||
{/* 안 보이는 쪽을 덮어 오늘 밤 달 모양으로 */}
|
||||
{moon && <Path d={moonPath(moon.pct, 1, false)} fill={kind === 'sunset' ? 'rgb(96 40 86 / .55)' : 'rgb(34 30 86 / .62)'} transform={moon.waning ? 'scale(-1,1)' : undefined} />}
|
||||
</Svg>
|
||||
<Text className="font-jua text-[12px]" style={{ color: orb.text }}>
|
||||
{failed(feedLoad) ? '점수를 못 불러왔어요' : `${slotScore != null && mode !== 'now' ? PREVIEW[mode].label : '지금'} 날씨 점수`}
|
||||
</Text>
|
||||
<Text className="font-bagel text-[52px] leading-[52px]" style={{ color: orb.text }}>
|
||||
{heroVal(feedLoad, score, 'w-[84px] h-10')}
|
||||
</Text>
|
||||
</View>
|
||||
<Fall d={0} f={5600} amp={8}>
|
||||
<View className="mt-2 size-32 items-center justify-center" style={{ boxShadow: `0 20px 40px ${kind === 'night' ? 'rgb(190 180 255 / 0.35)' : kind === 'sunset' ? 'rgb(255 150 110 / 0.4)' : 'rgb(240 106 58 / 0.32)'}`, borderRadius: 64 }}>
|
||||
<Svg viewBox="-1 -1 2 2" width={128} height={128} style={{ position: 'absolute' }}>
|
||||
<Defs>
|
||||
<RadialGradient id="orb" cx="-0.32" cy="-0.4" r="1.4" gradientUnits="userSpaceOnUse">
|
||||
<Stop offset="0" stopColor={orb.stops[0]} />
|
||||
<Stop offset="0.3" stopColor={orb.stops[1]} />
|
||||
<Stop offset="0.68" stopColor={orb.stops[2]} />
|
||||
<Stop offset="1" stopColor={orb.stops[3]} />
|
||||
</RadialGradient>
|
||||
</Defs>
|
||||
<Rect x="-1" y="-1" width="2" height="2" rx="1" fill="url(#orb)" opacity={gray ? 0.85 : 1} />
|
||||
{/* 안 보이는 쪽을 덮어 오늘 밤 달 모양으로 */}
|
||||
{moon && <Path d={moonPath(moon.pct, 1, false)} fill={kind === 'sunset' ? 'rgb(96 40 86 / .55)' : 'rgb(34 30 86 / .62)'} transform={moon.waning ? 'scale(-1,1)' : undefined} />}
|
||||
</Svg>
|
||||
<Text className="font-jua text-[12px]" style={{ color: orb.text }}>
|
||||
{failed(feedLoad) ? '점수를 못 불러왔어요' : `${slotScore != null && mode !== 'now' ? PREVIEW[mode].label : '지금'} 날씨 점수`}
|
||||
</Text>
|
||||
<Text className="font-bagel text-[52px] leading-[52px]" style={{ color: orb.text }}>
|
||||
{heroVal(feedLoad, score, 'w-[84px] h-10')}
|
||||
</Text>
|
||||
</View>
|
||||
</Fall>
|
||||
{CLOUDS.slice(0, CLOUD_N[weather]).map((c) => (
|
||||
<Fall key={c.left} d={c.d} f={c.f} style={{ position: 'absolute', top: c.top, left: c.left }}>
|
||||
<Cloud w={c.w} h={c.h} night={kind === 'night'} />
|
||||
</Fall>
|
||||
))}
|
||||
</View>
|
||||
<View className="items-center">
|
||||
{bubble ? (
|
||||
|
||||
@@ -3,37 +3,59 @@ import { kst, seasonOf } from '@nalssigak/shared/lib';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { usePathname } from 'expo-router';
|
||||
import { useState } from 'react';
|
||||
import { Text, View } from 'react-native';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
import { useCSSVariable } from 'uniwind';
|
||||
|
||||
import { PinIcon } from '@/components/svg';
|
||||
import { Ic } from '@/components/ui';
|
||||
import { Avatar, Ic } from '@/components/ui';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
const TITLES: Record<string, string> = { '/sky': '노을', '/gak': '오늘의 각', '/week': '주말·행사', '/season': '계절·상식' };
|
||||
|
||||
/** 로고 옆 계절 칩: 계절 이름과 지금 절기 */
|
||||
/** 로고 옆 계절 칩: 계절 이름과 지금 절기. 누르면 이번 주 절기 창 */
|
||||
function SeasonChip() {
|
||||
const { open } = useSheet();
|
||||
const week = useQuery(getSeasonWeekOptions());
|
||||
const [month] = useState(() => kst(new Date()).mo);
|
||||
const [name, icon] = seasonOf(month);
|
||||
const term = week.data?.term_now?.name;
|
||||
return (
|
||||
<View className="shrink flex-row items-center gap-1 rounded-full bg-card/70 py-1 pr-2.5 pl-1.5">
|
||||
<Pressable onPress={() => open({ type: 'seasonWeek' })} accessibilityLabel={`지금 ${name}${term ? `, ${term}` : ''}. 이번 주 절기 보기`} className="shrink flex-row items-center gap-1 rounded-full bg-card/70 py-1 pr-2.5 pl-1.5">
|
||||
<Ic name={icon} size={18} />
|
||||
<Text numberOfLines={1} className="text-[13px] font-extrabold text-ink">
|
||||
<Text numberOfLines={1} className="shrink text-[13px] font-extrabold text-ink">
|
||||
{name}
|
||||
{term && <Text className="font-bold opacity-70"> · {term}</Text>}
|
||||
</Text>
|
||||
</View>
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
/** 오른쪽 끝: 내 정보(아바타) 또는 로그인 버튼 */
|
||||
function Account() {
|
||||
const { open } = useSheet();
|
||||
const { me, mePending } = useAuth();
|
||||
if (mePending) return <View className="size-9 shrink-0 rounded-full bg-skel" />;
|
||||
if (me)
|
||||
return (
|
||||
<Pressable onPress={() => open({ type: 'me' })} accessibilityLabel={`내 정보, ${me.nickname}`} className="shrink-0 rounded-full" style={{ boxShadow: '0 6px 12px rgb(40 48 74 / 0.12)' }}>
|
||||
<Avatar character={me.character} color={me.color} mood={me.mood} size={36} />
|
||||
</Pressable>
|
||||
);
|
||||
return (
|
||||
<Pressable onPress={() => open({ type: 'login' })} className="shrink-0 rounded-full bg-ink-btn px-3 py-1.5">
|
||||
<Text className="text-[13px] font-extrabold text-white">로그인</Text>
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
export function TopBar() {
|
||||
const pathname = usePathname();
|
||||
const { region } = useRegion();
|
||||
const { open } = useSheet();
|
||||
const { kind } = useSky();
|
||||
const { top } = useSafeAreaInsets();
|
||||
const ink = String(useCSSVariable('--color-ink'));
|
||||
@@ -43,12 +65,13 @@ export function TopBar() {
|
||||
<View className="h-[54px] flex-row items-center gap-2 px-4">
|
||||
{title ? <Text className="font-jua text-[22px] text-ink">{title}</Text> : <Text className="font-jua text-[25px] text-orange">날씨각</Text>}
|
||||
<SeasonChip />
|
||||
<View className="ml-auto shrink-0 flex-row items-center gap-1 rounded-full border-b-4 border-shade bg-card px-3 pt-1 pb-1.5">
|
||||
<Pressable onPress={() => open({ type: 'region' })} accessibilityLabel={`위치 바꾸기, 지금 ${region.name}`} className="ml-auto shrink-0 flex-row items-center gap-1 rounded-full border-b-4 border-shade bg-card px-3 pt-1 pb-1.5">
|
||||
<PinIcon size={14} color={ink} />
|
||||
<Text numberOfLines={1} className="text-[13.5px] font-bold text-ink">
|
||||
{region.name.split(' ').at(-1)}
|
||||
</Text>
|
||||
</View>
|
||||
</Pressable>
|
||||
<Account />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
|
||||
@@ -2,7 +2,8 @@ import { AVATAR_COLORS, moodEmoji, naverMap, type Load } from '@nalssigak/shared
|
||||
import { Image, type ImageStyle } from 'expo-image';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { Link, type Href } from 'expo-router';
|
||||
import { useState, type ReactNode } from 'react';
|
||||
import { useEffect, useState, type ReactNode } from 'react';
|
||||
import Animated, { cancelAnimation, Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated';
|
||||
import { Linking, Pressable, ScrollView, Text, View, type StyleProp, type ViewStyle } from 'react-native';
|
||||
|
||||
import { ICONS } from '@/lib/icons';
|
||||
@@ -38,9 +39,21 @@ export function Thumb({ image, icon, iconSize, className, style, children }: { i
|
||||
);
|
||||
}
|
||||
|
||||
/** 불러오는 동안 자리만 잡는 막대 */
|
||||
/** 불러오는 동안 자리만 잡는 막대. 천천히 깜빡인다 (웹 animate-pulse, 동작 줄이기면 멈춤) */
|
||||
export function Skel({ className }: { className?: string }) {
|
||||
return <View className={`h-[0.9em] min-h-3 rounded-full bg-skel ${className ?? ''}`} />;
|
||||
const reduce = useReducedMotion();
|
||||
const dim = useSharedValue(0);
|
||||
useEffect(() => {
|
||||
if (reduce) return;
|
||||
dim.value = withRepeat(withTiming(1, { duration: 1000, easing: Easing.bezier(0.4, 0, 0.6, 1) }), -1, true);
|
||||
return () => cancelAnimation(dim);
|
||||
}, [reduce, dim]);
|
||||
const pulse = useAnimatedStyle(() => ({ opacity: 1 - dim.value * 0.5 }));
|
||||
return (
|
||||
<Animated.View style={pulse}>
|
||||
<View className={`h-[0.9em] min-h-3 rounded-full bg-skel ${className ?? ''}`} />
|
||||
</Animated.View>
|
||||
);
|
||||
}
|
||||
|
||||
export function Sec({ title, sub, more }: { title: string; sub?: string; more?: Href }) {
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
import type { EventData, PlaceData, WeekRankItem, DayData } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { cardBg, dateRange } from '@nalssigak/shared/lib';
|
||||
import { LinearGradient } from 'expo-linear-gradient';
|
||||
import { Pressable, ScrollView, Text, View } from 'react-native';
|
||||
|
||||
import { Credit, Ic, MapLink, Thumb } from '@/components/ui';
|
||||
import { CARD_BG } from '@/lib/colors';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
import { DAY_W, EVENT_CARD, PLACE_CARD } from './skels';
|
||||
|
||||
const PLACE_BG: Record<string, string> = { picnic: 'mint', walk: 'mint', sunset: 'dusk', chimaek: 'peach', photo: 'butter', bulb: 'lilac' };
|
||||
|
||||
function useBg() {
|
||||
const { kind } = useSky();
|
||||
return { night: kind === 'night', bg: CARD_BG[kind === 'night' ? 'night' : 'day'] };
|
||||
}
|
||||
|
||||
/** 열흘 날짜 줄: 누르면 그날 추천이 바뀐다 */
|
||||
export function DayStrip({ days, selected, onPick, dim }: { days: DayData[]; selected?: string; onPick: (day: string) => void; dim: boolean }) {
|
||||
const { night } = useBg();
|
||||
const red = night ? '#ff8db5' : '#d6457a';
|
||||
return (
|
||||
<ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerClassName="gap-1 px-3 pt-3" style={{ opacity: dim ? 0.6 : 1 }} accessibilityLabel="날짜 고르기">
|
||||
{days.map((d) => {
|
||||
const on = d.day === selected;
|
||||
const weekend = d.weekday === '토' || d.weekday === '일' || !!d.holiday;
|
||||
return (
|
||||
<Pressable key={d.day} accessibilityState={{ selected: on }} onPress={() => onPick(d.day)} className={`${DAY_W} items-center gap-0.5 rounded-[18px] pt-[9px] pb-2 ${on ? 'bg-ink-btn' : 'border-b-4 border-shade bg-card'}`}>
|
||||
<Text className={`text-xs font-extrabold ${on ? 'text-white' : weekend ? '' : 'text-ink2'}`} style={!on && weekend ? { color: red } : undefined}>
|
||||
{d.weekday}
|
||||
</Text>
|
||||
<Ic name={d.icon} size={28} />
|
||||
<Text className={`font-jua text-sm ${on ? 'text-white' : 'text-ink'}`}>{d.temp_max_c != null ? `${Math.round(d.temp_max_c)}°` : <Text className="opacity-50">?</Text>}</Text>
|
||||
<Text numberOfLines={1} className="px-0.5 text-[9.5px] font-extrabold" style={{ color: on ? '#ffb3c4' : red }}>
|
||||
{d.holiday ? d.holiday.replace(/\(.*\)/, '') : `${Number(d.day.slice(8))}일`}
|
||||
</Text>
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
/** 고른 날 추천 한 장 */
|
||||
export function PickCard({ day }: { day: DayData }) {
|
||||
const { night, bg } = useBg();
|
||||
return (
|
||||
<View className="mx-3 mt-3 flex-row items-center gap-3.5 overflow-hidden rounded-3xl border-b-[5px] border-shade p-4" accessibilityLiveRegion="polite">
|
||||
<LinearGradient colors={night ? bg.mint : ['#e9fbf2', '#ffffff']} style={{ position: 'absolute', inset: 0 }} />
|
||||
<Ic name={day.icon} size={64} />
|
||||
<View className="flex-1">
|
||||
<Text className="font-jua text-[19px] text-ink">{day.headline}</Text>
|
||||
<Text className="mt-0.5 text-[13.5px] font-semibold text-ink2">{day.summary}</Text>
|
||||
<Text className="mt-2 font-jua text-base text-ink">{day.pick}</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function PlaceCard({ place: p, index }: { place: PlaceData; index: number }) {
|
||||
const { bg } = useBg();
|
||||
return (
|
||||
<View className={PLACE_CARD}>
|
||||
<Thumb image={p.image} icon={p.icon} iconSize={62} className="h-[104px]">
|
||||
<LinearGradient colors={bg[PLACE_BG[p.icon] ?? (p.is_outdoor ? 'mint' : cardBg(p.icon, index))]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
|
||||
{p.is_good && (
|
||||
<View className={`absolute top-2.5 left-2.5 rounded-full px-2 py-[3px] ${p.is_outdoor ? 'bg-[#1f9d62]' : 'bg-rain'}`}>
|
||||
<Text className="text-[11.5px] font-extrabold text-white">{p.is_outdoor ? '오늘 딱' : '비 와도 OK'}</Text>
|
||||
</View>
|
||||
)}
|
||||
{p.image && p.image_credit && <Credit text={p.image_credit} />}
|
||||
</Thumb>
|
||||
<View className="px-3 pt-2.5 pb-3">
|
||||
<Text className="text-[11.5px] font-extrabold text-ink3">
|
||||
{p.area} · {p.distance_km}km · {p.is_outdoor ? '야외' : '실내'}
|
||||
</Text>
|
||||
<Text className="font-jua text-[16.5px] text-ink">
|
||||
<MapLink place={p.name}>{p.name}</MapLink>
|
||||
</Text>
|
||||
<Text className="text-[12.5px] leading-snug font-semibold text-ink2">
|
||||
{p.reason}
|
||||
{'\n'}추천 {p.best_time}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function RankRow({ item: r, mine }: { item: WeekRankItem; mine: boolean }) {
|
||||
return (
|
||||
<View className={`flex-row items-center gap-2.5 border-b-[1.5px] border-line px-1 py-3 ${mine ? 'rounded-2xl bg-card' : ''}`}>
|
||||
<Text className="w-[34px] text-center font-bagel text-xl text-orange">{r.rank}</Text>
|
||||
<View className="min-w-0 flex-1">
|
||||
<Text numberOfLines={1} className="font-jua text-[17px] text-ink">
|
||||
{r.name}
|
||||
{mine && <Text className="text-xs font-extrabold text-rain"> 내 지역</Text>}
|
||||
</Text>
|
||||
<Text numberOfLines={1} className="text-[12.5px] font-semibold text-ink2">
|
||||
{r.reason}
|
||||
{r.estimated && ' · 예상'}
|
||||
</Text>
|
||||
<View className="mt-[5px] h-1.5 overflow-hidden rounded-full bg-[#eef1f6]">
|
||||
<LinearGradient colors={['#9be7c4', '#1f9d62']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }} style={{ height: '100%', width: `${r.score}%` }} />
|
||||
</View>
|
||||
</View>
|
||||
<View className="flex-row items-center gap-1">
|
||||
<Ic name={r.icon} size={24} />
|
||||
<Text className="font-jua text-base text-ink">{r.score}점</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function EventRow({ event: e, index }: { event: EventData; index: number }) {
|
||||
const { night, bg } = useBg();
|
||||
const live = e.status === 'live';
|
||||
const rainy = e.fit?.includes('비');
|
||||
return (
|
||||
<View className={EVENT_CARD}>
|
||||
<Thumb image={e.image} icon={e.icon} iconSize={56} className="h-[84px] w-[84px] rounded-2xl">
|
||||
<LinearGradient colors={bg[cardBg(e.icon, index)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
|
||||
{e.image && e.image_credit && <Credit text={e.image_credit} />}
|
||||
</Thumb>
|
||||
{/* 이름 두 줄·정보 한 줄·날씨 한 줄로 고정해 카드 높이가 데이터와 무관하게 같다 */}
|
||||
<View className="min-w-0 flex-1">
|
||||
<Text numberOfLines={2} className="h-[46px] font-jua text-[17px] leading-snug text-ink">
|
||||
<Text className="text-[11px] font-extrabold" style={{ color: live ? (night ? '#4fd39a' : '#1f7a4f') : night ? '#ffab85' : '#c2471b', backgroundColor: live ? (night ? 'rgba(79,211,154,0.16)' : '#dff5ea') : night ? 'rgba(255,138,87,0.16)' : '#ffe8dc' }}>
|
||||
{` ${e.status_label} `}
|
||||
</Text>{' '}
|
||||
{e.name}
|
||||
</Text>
|
||||
<Text numberOfLines={1} className="text-[12.5px] font-semibold text-ink2">
|
||||
{dateRange(e.start_date, e.end_date)}
|
||||
{e.place_name && (
|
||||
<>
|
||||
{' · '}
|
||||
<MapLink place={e.place_name}>{e.place_name}</MapLink>
|
||||
</>
|
||||
)}
|
||||
{!e.is_confirmed && ' · 일정 확인 필요'}
|
||||
</Text>
|
||||
<Text numberOfLines={1} className="mt-[5px] text-xs font-extrabold" style={{ color: rainy ? (night ? '#ff8db5' : '#d6457a') : night ? '#4fd39a' : '#1f9d62' }}>
|
||||
{e.fit ?? ' '}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import { View } from 'react-native';
|
||||
|
||||
import { Skel } from '@/components/ui';
|
||||
|
||||
const TEN = Array.from({ length: 10 }, (_, i) => i);
|
||||
const THREE = [0, 1, 2];
|
||||
|
||||
export const DAY_W = 'w-[46px]';
|
||||
export const PLACE_CARD = 'w-[178px] overflow-hidden rounded-[22px] border-b-[5px] border-shade bg-card';
|
||||
export const EVENT_CARD = 'mx-3 mt-2.5 flex-row items-center gap-3 rounded-[22px] border-b-[5px] border-shade bg-card p-3';
|
||||
|
||||
export function DaysSkel() {
|
||||
return (
|
||||
<View className="flex-row gap-1 overflow-hidden px-3 pt-3">
|
||||
{TEN.map((i) => (
|
||||
<View key={i} className={`${DAY_W} items-center gap-1 rounded-[18px] border-b-4 border-shade bg-card pt-[9px] pb-2`}>
|
||||
<Skel className="w-3" />
|
||||
<View className="size-7 rounded-full bg-skel" />
|
||||
<Skel className="w-6" />
|
||||
<Skel className="w-5" />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function PickSkel() {
|
||||
return (
|
||||
<View className="mx-3 mt-3 flex-row items-center gap-3.5 rounded-3xl border-b-[5px] border-shade bg-card p-4">
|
||||
<View className="size-16 rounded-full bg-skel" />
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="h-4 w-32" />
|
||||
<Skel className="w-4/5" />
|
||||
<Skel className="mt-1 w-36" />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function PlacesSkel() {
|
||||
return (
|
||||
<View className="flex-row gap-2.5 overflow-hidden px-4 pt-3 pb-1">
|
||||
{THREE.map((i) => (
|
||||
<View key={i} className={PLACE_CARD}>
|
||||
<View className="h-[104px] bg-skel" />
|
||||
<View className="gap-1.5 px-3 pt-2.5 pb-3">
|
||||
<Skel className="w-16" />
|
||||
<Skel className="h-4 w-24" />
|
||||
<Skel className="w-full" />
|
||||
<Skel className="w-20" />
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function EventSkel() {
|
||||
return (
|
||||
<View className={EVENT_CARD}>
|
||||
<View className="h-[84px] w-[84px] rounded-2xl bg-skel" />
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="h-4 w-40" />
|
||||
<Skel className="h-4 w-20" />
|
||||
<Skel className="w-44" />
|
||||
<Skel className="w-24" />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function EventsSkel() {
|
||||
return (
|
||||
<>
|
||||
{THREE.map((i) => (
|
||||
<EventSkel key={i} />
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function RankSkel() {
|
||||
return (
|
||||
<View className="mx-3 mt-1.5">
|
||||
{TEN.map((i) => (
|
||||
<View key={i} className="flex-row items-center gap-2.5 border-b-[1.5px] border-line px-1 py-3">
|
||||
<View className="w-[34px] items-center">
|
||||
<Skel className="w-5" />
|
||||
</View>
|
||||
<View className="flex-1 gap-1.5">
|
||||
<Skel className="h-4 w-24" />
|
||||
<Skel className="w-40" />
|
||||
<View className="h-1.5 rounded-full bg-skel" />
|
||||
</View>
|
||||
<View className="flex-row items-center gap-1">
|
||||
<View className="size-6 rounded-full bg-skel" />
|
||||
<Skel className="w-9" />
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user