172 lines
8.0 KiB
TypeScript
172 lines
8.0 KiB
TypeScript
import type { ResSaju, SajuLock } from '@nalssigak/shared/api/client/types.gen';
|
|
import { LinearGradient } from 'expo-linear-gradient';
|
|
import { Pressable, View } from 'react-native';
|
|
|
|
import { useSoft } from '@/components/sheets/parts';
|
|
import { Text } from '@/components/text';
|
|
import { Ic } from '@/components/ui';
|
|
import { useAuth } from '@/lib/auth';
|
|
import { progress, useLevel } from '@/lib/level';
|
|
import { useSaveBirth, type Birth } from '@/lib/saju-birth';
|
|
import { useSheet } from '@/lib/sheet';
|
|
|
|
import { dayWord, Panel } from './parts';
|
|
|
|
/** 앞으로 7일 흐름 (Lv.2) */
|
|
export function Week({ days }: { days: NonNullable<ResSaju['week']> }) {
|
|
const soft = useSoft();
|
|
return (
|
|
<Panel id="saju_week" icon="spiral_calendar" title="앞으로 7일 흐름">
|
|
<View className="gap-1">
|
|
{days.map((d) => (
|
|
<View key={d.day} className="flex-row items-center gap-2 rounded-xl px-2 py-1.5" style={d.best ? { backgroundColor: soft.warm } : undefined}>
|
|
<Text numberOfLines={1} className="w-[66px] text-[13px] font-bold text-ink">
|
|
{dayWord(d.day, d.weekday)}
|
|
</Text>
|
|
{d.icon ? <Ic name={d.icon} size={24} /> : <View className="size-6" />}
|
|
<Text numberOfLines={1} className="w-[52px] text-[13px] font-bold text-ink2">
|
|
{d.temp_max != null ? `${d.temp_min}~${d.temp_max}°` : ''}
|
|
</Text>
|
|
<Text numberOfLines={1} className="min-w-0 flex-1 text-[12.5px] font-bold text-ink2">
|
|
{d.title}
|
|
</Text>
|
|
<Text className={`font-bagel text-[15px] ${d.best ? 'text-orange' : 'text-ink'}`}>{d.score}</Text>
|
|
</View>
|
|
))}
|
|
</View>
|
|
<Text className="mt-1.5 text-xs font-semibold text-ink3">점수는 그날 사주와 예보로 계산해요. 주황색은 7일 중 점수가 가장 높은 날이에요.</Text>
|
|
</Panel>
|
|
);
|
|
}
|
|
|
|
/** 금전운·일운 (Lv.3) */
|
|
export function Money({ money, work }: { money: string[]; work: string[] }) {
|
|
const lines = [...money.map((l) => ['money_bag', l]), ...work.map((l) => ['briefcase', l])];
|
|
return (
|
|
<Panel id="saju_money" icon="money_bag" title="금전운 · 일운">
|
|
<View className="gap-1.5">
|
|
{lines.map(([icon, l]) => (
|
|
<View key={l} className="flex-row gap-2">
|
|
<Ic name={icon} size={20} />
|
|
<Text className="min-w-0 flex-1 text-[14px] font-semibold text-ink">{l}</Text>
|
|
</View>
|
|
))}
|
|
</View>
|
|
</Panel>
|
|
);
|
|
}
|
|
|
|
/** 앞으로 7일 연애운 (Lv.4). 성별을 고르면 이성 인연까지 */
|
|
export function Love({ love, birth }: { love: NonNullable<ResSaju['love']>; birth: Birth }) {
|
|
const soft = useSoft();
|
|
const save = useSaveBirth();
|
|
const pick = (g: 'M' | 'F' | null) => void save({ ...birth, gender: g });
|
|
return (
|
|
<Panel id="saju_love" icon="red_heart" title="앞으로 7일 연애운">
|
|
{love.good ? (
|
|
<View className="rounded-xl px-3 py-2.5" style={{ backgroundColor: soft.warm }}>
|
|
<Text className="text-xs font-extrabold text-heart">연애 기운이 좋은 날</Text>
|
|
<Text className="font-jua text-[17px] text-ink">
|
|
{dayWord(love.good.day, love.good.weekday)}
|
|
{love.good.word ? ` · ${love.good.word} ${love.good.temp_max ?? ''}°` : ''}
|
|
</Text>
|
|
<Text className="text-[13px] font-semibold text-ink">{love.good.body}</Text>
|
|
<Text className="text-[11.5px] font-semibold text-ink3">{love.good.why}</Text>
|
|
</View>
|
|
) : (
|
|
<Text className="text-[13px] font-semibold text-ink2">앞으로 7일 중엔 연애 기운이 두드러지는 날이 없어요.</Text>
|
|
)}
|
|
{!!love.caution && (
|
|
<Text className="mt-2 text-[13px] font-semibold text-ink">
|
|
조심할 날 {dayWord(love.caution.day, love.caution.weekday)}: {love.caution.body} <Text className="text-ink3">· {love.caution.why}</Text>
|
|
</Text>
|
|
)}
|
|
{love.gender_known ? (
|
|
<Text className="mt-2.5 text-xs font-bold text-ink3">
|
|
{birth.gender === 'M' ? '남성' : '여성'} 기준으로 이성 인연(재성·관성)까지 봤어요 ·{' '}
|
|
<Text onPress={() => pick(null)} accessibilityRole="button" className="font-extrabold text-orange">
|
|
빼고 보기
|
|
</Text>
|
|
</Text>
|
|
) : (
|
|
<View className="mt-2.5 flex-row flex-wrap items-center gap-1.5">
|
|
<Text className="text-xs font-bold text-ink2">성별을 고르면 이성 인연(재성·관성)까지 봐요</Text>
|
|
{(
|
|
[
|
|
['M', '남성'],
|
|
['F', '여성'],
|
|
] as const
|
|
).map(([g, word]) => (
|
|
<Pressable key={g} onPress={() => pick(g)} accessibilityRole="button" className="rounded-full px-2.5 py-1" style={{ backgroundColor: soft.soft }}>
|
|
<Text className="text-xs font-bold text-ink2">{word}</Text>
|
|
</Pressable>
|
|
))}
|
|
</View>
|
|
)}
|
|
</Panel>
|
|
);
|
|
}
|
|
|
|
/** 이달·올해 (Lv.6·7) */
|
|
export function Period({ id, icon, p }: { id: string; icon: string; p: NonNullable<ResSaju['month']> }) {
|
|
return (
|
|
<Panel id={id} icon={icon} title={p.label}>
|
|
<Text className="font-jua text-[17px] text-ink">
|
|
{p.title} <Text className="text-[13px] text-ink3">({p.ten_god})</Text>
|
|
</Text>
|
|
<Text className="mt-0.5 text-[13.5px] font-semibold text-ink">{p.body}</Text>
|
|
{(p.months?.length ?? 0) > 0 && (
|
|
<Text className="mt-1.5 text-[13.5px] font-bold text-ink">
|
|
{p.label.includes('미리') ? '내 사주와 잘 맞는 달' : '남은 달 중 잘 맞는 달'}: {p.months!.map((m) => `${m}월`).join(' · ')}
|
|
</Text>
|
|
)}
|
|
{p.notes?.map((n) => (
|
|
<Text key={n} className="mt-1 text-xs font-semibold text-ink3">
|
|
{n}
|
|
</Text>
|
|
))}
|
|
</Panel>
|
|
);
|
|
}
|
|
|
|
/** 아직 안 열린 것: 다음에 열릴 하나를 크게, 나머지는 한 줄로. 로그인 전이면 로그인부터 */
|
|
export function Locked({ locks }: { locks: SajuLock[] }) {
|
|
const { loggedIn } = useAuth();
|
|
const { open } = useSheet();
|
|
const soft = useSoft();
|
|
const level = useLevel().data;
|
|
if (!locks.length) return null;
|
|
const [next, ...rest] = [...locks].sort((a, b) => a.level - b.level);
|
|
const close = loggedIn && !!level && level.next_points != null && level.level + 1 === next.level;
|
|
return (
|
|
<View className="mx-4 rounded-[22px] px-4 py-3.5" style={{ backgroundColor: soft.soft }}>
|
|
<View className="flex-row items-center gap-3">
|
|
<Ic name="locked" size={32} />
|
|
<View className="min-w-0 flex-1">
|
|
<Text className="font-jua text-[16px] text-ink">{loggedIn ? `다음은 ${next.name}` : '각을 모으면 더 볼 수 있어요'}</Text>
|
|
<Text className="text-xs font-bold text-ink2">
|
|
{loggedIn ? (close && level ? `${level.next_points! - level.points}각 더 모으면 열려요` : `Lv.${next.level}이 되면 열려요`) : "로그인하고 출석·사주 보기·좋아요를 하면 활동 포인트 '각'이 쌓여요"}
|
|
</Text>
|
|
</View>
|
|
<Pressable onPress={() => open(loggedIn ? { type: 'level' } : { type: 'login', why: 'level' })} accessibilityRole="button" className="rounded-full bg-ink-btn px-3 py-1.5">
|
|
<Text className="text-xs font-extrabold text-white">{loggedIn ? '각 모으는 법' : '로그인'}</Text>
|
|
</Pressable>
|
|
</View>
|
|
{close && !!level && (
|
|
<View className="mt-2.5 h-1.5 overflow-hidden rounded-full bg-card">
|
|
<LinearGradient colors={['#ffb27a', '#ff7a45']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }} style={{ height: '100%', width: `${Math.round(progress(level) * 100)}%`, borderRadius: 999 }} />
|
|
</View>
|
|
)}
|
|
<View className="mt-2.5 flex-row flex-wrap gap-1.5">
|
|
{(loggedIn ? rest : [next, ...rest]).map((l) => (
|
|
<View key={l.key} className="rounded-full bg-card px-2.5 py-1">
|
|
<Text className="text-[11.5px] font-extrabold text-ink2">
|
|
Lv.{l.level} {l.name}
|
|
</Text>
|
|
</View>
|
|
))}
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|