feat: 앱 시트·로그인 상태·지역 저장 틀, 공통 UI(Avatar·Chips·Rows·Credit)

This commit is contained in:
minaChoi committed 2026-10-14 14:29:20 +09:00
1 parent e52f93fdbb
commit 28ff032160
8 files changed
+202 -15

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
import { useMemo, useState, type ReactNode } from 'react';
import { SheetContext, type SheetState } from '@/lib/sheet';
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>;
}
+9 -1
View File
@@ -8,6 +8,7 @@ import { LinearGradient } from 'expo-linear-gradient';
import Svg, { Defs, Path, RadialGradient, Rect, Stop } from 'react-native-svg';
import { Ic, Skel } from '@/components/ui';
import { useSheet } from '@/lib/sheet';
import { useSky } from '@/lib/sky';
type Mode = 'now' | TimeKind;
@@ -48,6 +49,7 @@ function heroVal(load: Load, v: ReactNode, skel: string) {
type Props = { hero?: HeroData | null; today?: ResWeatherToday; ranked: TopIndex[]; feedLoad: Load; todayLoad: Load };
export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) {
const { open } = useSheet();
const { preview, setServerKind, setPreview } = useSky();
const mode: Mode = preview ?? 'now';
const t = kst(useNow());
@@ -112,7 +114,13 @@ export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) {
</View>
</View>
<View className="items-center">
{bubble ? <Text className={`text-center font-jua text-[24px] leading-tight ${text}`}>{bubble}</Text> : <Skel className="h-6 w-[160px]" />}
{bubble ? (
<Pressable disabled={!top1} onPress={() => top1 && open({ type: 'gak', indexId: top1.index_id })} accessibilityLabel={top1 ? `${bubble} 1위 ${top1.name} ${top1.score}점, 계산 근거 보기` : undefined}>
<Text className={`text-center font-jua text-[24px] leading-tight ${text}`}>{bubble}</Text>
</Pressable>
) : (
<Skel className="h-6 w-[160px]" />
)}
{top1?.summary ? <Text className={`mt-0.5 text-center text-[15px] font-bold opacity-80 ${text}`}>{top1.summary}</Text> : feedLoad === 'loading' ? <Skel className="mt-1 w-[140px]" /> : null}
{/* 상태 한 줄: 습도·불쾌지수·자외선·미세먼지 단계 이름. 조심할 것만 색 */}
{status.length > 0 && (
+10 -6
View File
@@ -7,16 +7,18 @@ import { Pressable, Text, View } from 'react-native';
import { Ic, Rail, Sec, Skel, Thumb } from '@/components/ui';
import { CARD_BG, BAND_BG } from '@/lib/colors';
import { useSheet } from '@/lib/sheet';
import { useSky } from '@/lib/sky';
const CARD = 'overflow-hidden rounded-[22px] border-b-[5px] border-shade bg-card';
/** 오늘의 각 순위: 동그라미 + 이름 + 점수. 지금 시간대가 아닌 각은 흐리게 */
export function Stories({ items }: { items: TopIndex[] }) {
const { open } = useSheet();
return (
<Rail>
{items.map((g, i) => (
<View key={g.index_id} accessibilityLabel={g.active ? `${g.rank}위 ${g.name} ${g.score}점` : `${g.name}, 지금 시간대 아님`} className={`w-[72px] items-center gap-1 ${g.active ? '' : 'opacity-55'}`}>
<Pressable key={g.index_id} onPress={() => open({ type: 'gak', indexId: g.index_id })} accessibilityLabel={g.active ? `${g.rank}위 ${g.name} ${g.score}점` : `${g.name}, 지금 시간대 아님`} className={`w-[72px] items-center gap-1 ${g.active ? '' : 'opacity-55'}`}>
<View className="size-[68px]">
{!g.active || g.score < 50 ? (
<View className="absolute inset-0 rounded-full bg-[#d6deea]" />
@@ -32,7 +34,7 @@ export function Stories({ items }: { items: TopIndex[] }) {
{g.name}
</Text>
{g.active ? <Text className="font-bagel text-[12.5px] leading-[14px] text-orange">{g.score}</Text> : <Text className="text-[11px] leading-[14px] font-extrabold text-ink3">지금 아님</Text>}
</View>
</Pressable>
))}
</Rail>
);
@@ -96,17 +98,18 @@ export function EventsBand({ events }: { events: BandEvent[] }) {
}
export function TopBand({ items, sub }: { items: TopIndex[]; sub: string }) {
const { open } = useSheet();
return (
<Band tone={2} title="지금 뜨는 각 TOP 5" sub={sub} to="/gak">
<Rail>
{items.slice(0, 5).map((g, i) => (
<View key={g.index_id} className="w-[138px] gap-1 rounded-[22px] border-b-[5px] border-shade bg-card p-3">
<Pressable key={g.index_id} onPress={() => open({ type: 'gak', indexId: g.index_id })} className="w-[138px] gap-1 rounded-[22px] border-b-[5px] border-shade bg-card p-3">
{i < 3 ? <Ic name={MEDALS[i]} size={26} style={{ position: 'absolute', top: 8, left: 8 }} /> : <Text className="absolute top-2.5 left-3 font-jua text-ink3">{i + 1}위</Text>}
<Ic name={g.icon} size={58} style={{ alignSelf: 'center' }} />
<Text className="font-jua text-base text-ink">{g.name}</Text>
<Text className="font-bagel text-[22px] leading-[24px] text-orange">{g.score}</Text>
{g.summary && <Text className="text-xs font-semibold text-ink2">{g.summary}</Text>}
</View>
</Pressable>
))}
</Rail>
</Band>
@@ -115,11 +118,12 @@ export function TopBand({ items, sub }: { items: TopIndex[]; sub: string }) {
export function SeasonBand({ news }: { news: BandArticle[] }) {
const bg = useCardBg();
const { open } = useSheet();
return (
<Band tone={3} title="이번 주 계절 이야기" sub="예년 이맘때의 소식" to="/season">
<Rail>
{news.map((a) => (
<View key={a.article_id} className={`w-[200px] ${CARD}`}>
<Pressable key={a.article_id} onPress={() => open({ type: 'article', articleId: a.article_id })} className={`w-[200px] ${CARD}`}>
<Thumb image={a.image} icon={a.icon} iconSize={76} className="h-[116px]">
<LinearGradient colors={bg[cardBg(a.icon, a.article_id)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
</Thumb>
@@ -127,7 +131,7 @@ export function SeasonBand({ news }: { news: BandArticle[] }) {
<Text className="font-jua text-[16.5px] leading-snug text-ink">{a.title}</Text>
<Text className="text-[12.5px] font-semibold text-ink2">{a.meta}</Text>
</View>
</View>
</Pressable>
))}
</Rail>
</Band>
+81 -2
View File
@@ -1,9 +1,9 @@
import type { Load } from '@nalssigak/shared/lib';
import { AVATAR_COLORS, moodEmoji, naverMap, type Load } from '@nalssigak/shared/lib';
import { Image, type ImageStyle } from 'expo-image';
import { LinearGradient } from 'expo-linear-gradient';
import { Link, type Href } from 'expo-router';
import { useState, type ReactNode } from 'react';
import { Pressable, ScrollView, Text, View, type StyleProp, type ViewStyle } from 'react-native';
import { Linking, Pressable, ScrollView, Text, View, type StyleProp, type ViewStyle } from 'react-native';
import { ICONS } from '@/lib/icons';
import { imageUri } from '@/lib/site';
@@ -84,3 +84,82 @@ export function StateBox({ load, onRetry, empty }: { load: Load; onRetry?: () =>
</View>
);
}
/** 사진 출처 표기 (공공누리 조건). 위치는 className 으로 */
export function Credit({ text, className = 'right-1 bottom-1' }: { text: string; className?: string }) {
return (
<View pointerEvents="none" className={`absolute z-[1] rounded-[5px] bg-[rgb(16_20_34/0.5)] px-1 py-px ${className}`}>
<Text numberOfLines={1} className="text-[9px] leading-tight font-semibold text-white">
{text}
</Text>
</View>
);
}
/** 프로필 동그라미: 고른 배경색 위에 캐릭터, 오른쪽 위에 오늘 기분 */
export function Avatar({ character, color, mood, size = 34 }: { character: string; color?: string | null; mood?: string | null; size?: number }) {
const emoji = moodEmoji(mood);
return (
<View className="items-center justify-center rounded-full" style={{ width: size, height: size, backgroundColor: AVATAR_COLORS[color ?? ''] ?? AVATAR_COLORS.orange }}>
<Ic name={character} size={size * 0.7} />
{emoji && (
<View className="absolute -top-1 -right-1 items-center justify-center rounded-full bg-white" style={{ width: size * 0.48, height: size * 0.48 }}>
<Text style={{ fontSize: size * 0.3 }}>{emoji}</Text>
</View>
)}
</View>
);
}
type ChipsProps<K extends string> = { items: readonly (readonly [K, string])[]; value: K; onChange: (k: K) => void; disabled?: boolean };
/** 가로로 넘기는 고르기 칩 */
export function Chips<K extends string>({ items, value, onChange, disabled }: ChipsProps<K>) {
return (
<ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerClassName="gap-2 px-4 pt-3 pb-0.5">
{items.map(([k, l]) => (
<Pressable key={k} accessibilityState={{ selected: value === k }} disabled={disabled} onPress={() => onChange(k)} className={`rounded-full px-3.5 py-[7px] ${value === k ? 'bg-ink-btn' : 'border-b-[3px] border-shade bg-chip'}`}>
<Text className={`text-[13.5px] font-bold ${value === k ? 'text-white' : 'text-ink2'}`}>{l}</Text>
</Pressable>
))}
</ScrollView>
);
}
/** 장소 이름. 누르면 네이버 지도가 열린다 */
export function MapLink({ place, children }: { place: string; children: ReactNode }) {
return (
<Text onPress={() => Linking.openURL(naverMap(place))} accessibilityRole="link" accessibilityLabel={`${place}, 네이버 지도에서 보기`} className="underline">
{children}
</Text>
);
}
/** 자외선 단계(1 낮음 ~ 5 위험) 칩 색 */
const LEVEL_CHIP = [
['#1f9d62', '#fff'],
['#ffc21a', '#3a2a00'],
['#f0700a', '#fff'],
['#e03131', '#fff'],
['#8e3bc4', '#fff'],
] as const;
/** 줄 목록 (라벨 · 값) */
export function Rows({ rows, dark = false }: { rows: { label: string; value: string; place?: string | null; level?: number | null }[]; dark?: boolean }) {
return (
<View className="mt-auto">
{rows.map((r, i) => (
<View key={r.label} className="flex-row items-center justify-between gap-2.5 py-2.5" style={i < rows.length - 1 ? { borderBottomWidth: 2, borderColor: dark ? 'rgb(255 255 255 / 0.18)' : 'rgb(40 48 74 / 0.08)' } : undefined}>
<Text className={`font-bold ${dark ? 'text-white' : 'text-ink'}`}>{r.label}</Text>
{r.level ? (
<Text className="overflow-hidden rounded-full px-2.5 py-[3px] font-jua text-[15px]" style={{ backgroundColor: LEVEL_CHIP[r.level - 1][0], color: LEVEL_CHIP[r.level - 1][1] }}>
{r.value}
</Text>
) : (
<Text className={`text-right font-jua text-[17px] ${dark ? 'text-white' : 'text-ink'}`}>{r.place ? <MapLink place={r.place}>{r.value}</MapLink> : r.value}</Text>
)}
</View>
))}
</View>
);
}