fix: df3fba7 에 섞여 들어간 옛 파일 되돌림 — 쇼츠 RSS·사주 생년월일 저장·생성 API 클라이언트를 ca6d55f 상태로

This commit is contained in:
minaChoi committed 2026-10-29 09:14:04 +09:00
1 parent cf7c96eaff
commit 051452d3b1
21 files changed
+865 -311

No files matched your search

+154 -82
View File
@@ -1,7 +1,7 @@
import { useEffect, useRef, useState, type ReactNode } from 'react'
import { useNavigate } from 'react-router'
import { useMutation, useQuery } from '@tanstack/react-query'
import { matchMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { matchMutation, myLevelQueryKey } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'
import { reading } from '@nalssigak/shared/api/client/sdk.gen'
import type { ResSaju, ResSajuMatch, SajuCard, SajuLock } from '@nalssigak/shared/api/client/types.gen'
import { track } from '../lib/analytics'
@@ -9,7 +9,7 @@ import { cx } from '../lib/utils'
import { useAuth } from './authContext'
import { progress, useLevel } from './level'
import { useRegion } from './regionContext'
import { BIRTH_PLACES, placeLon, setBirth, useBirth, validBirth, type Birth } from './sajuBirth'
import { BIRTH_PLACES, placeLon, useAccountBirth, useBirth, useSaveBirth, validBirth, type Birth } from './sajuBirth'
import { useSheet } from './sheetContext'
import { Ic, TAP44 } from './ui'
@@ -17,6 +17,9 @@ const SEEN_KEY = 'nalssigak.b.sajuSeen'
const EL_COLOR: Record<string, [string, string]> = { 木: ['#2f8a4c', '#e3f6ea'], 火: ['#d9442f', '#ffe6e0'], 土: ['#a8761a', '#fbf0d6'], 金: ['#6b7486', '#eef0f4'], 水: ['#2d4a8a', '#e3ebfb'] }
const CARD_ICON: Record<string, string> = { when: 'alarm_clock', do: 'check_mark_button', avoid: 'warning', good: 'sparkles', wear: 'tshirt' }
const POS_WORD: Record<string, string> = { hour: '시', day: '일', month: '월', year: '연' }
const HOURS = Array.from({ length: 24 }, (_, i) => i)
const MINUTES = Array.from({ length: 60 }, (_, i) => i)
const dayWord = (iso: string, weekday: string) => `${Number(iso.slice(5, 7))}/${Number(iso.slice(8, 10))}(${weekday})`
const toBody = (b: Birth) => ({
birth_date: `${b.y}-${String(b.m).padStart(2, '0')}-${String(b.d).padStart(2, '0')}`,
@@ -46,6 +49,7 @@ function markSeen() {
export function SajuPage() {
const navigate = useNavigate()
const birth = useBirth()
const loading = useAccountBirth()
const [editing, setEditing] = useState(false)
const back = () => (window.history.state?.idx > 0 ? navigate(-1) : navigate('/'))
return (
@@ -59,26 +63,38 @@ export function SajuPage() {
날씨 사주
</h2>
</div>
{!birth || editing ? <BirthForm initial={birth} onDone={() => setEditing(false)} /> : <Reading birth={birth} onEdit={() => setEditing(true)} />}
{loading && !birth ? (
<p className="m-0 px-4 py-16 text-center font-semibold text-(--ink2)">내 생년월일을 불러오는 중이에요…</p>
) : !birth || editing ? (
<BirthForm initial={birth} onDone={() => setEditing(false)} onCancel={birth ? () => setEditing(false) : undefined} />
) : (
<Reading birth={birth} onEdit={() => setEditing(true)} />
)}
</div>
)
}
function BirthForm({ initial, onDone }: { initial: Birth | null; onDone: () => void }) {
function BirthForm({ initial, onDone, onCancel }: { initial: Birth | null; onDone: () => void; onCancel?: () => void }) {
const { loggedIn } = useAuth()
const save = useSaveBirth()
const [y, setY] = useState(initial ? String(initial.y) : '')
const [m, setM] = useState(initial ? String(initial.m) : '')
const [d, setD] = useState(initial ? String(initial.d) : '')
const [time, setTime] = useState(initial?.hour != null ? `${String(initial.hour).padStart(2, '0')}:${String(initial.minute ?? 0).padStart(2, '0')}` : '')
const [hour, setHour] = useState(initial?.hour != null ? String(initial.hour) : '')
const [minute, setMinute] = useState(initial?.minute != null ? String(initial.minute) : '0')
const [place, setPlace] = useState(initial?.place ?? 'seoul')
const [error, setError] = useState('')
const input = 'min-w-0 flex-1 rounded-2xl border-[1.5px] border-(--line) bg-white px-3 py-3 text-center text-[17px] font-bold'
const box = 'w-full min-w-0 rounded-2xl border-[1.5px] border-(--line) bg-white px-2 py-3 text-center text-[17px] font-bold'
const pick = cx(box, 'cursor-pointer appearance-none bg-[url("data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20width=%2712%27%20height=%278%27%3E%3Cpath%20d=%27M1%201l5%205%205-5%27%20fill=%27none%27%20stroke=%27%238a93a6%27%20stroke-width=%272%27/%3E%3C/svg%3E")] bg-[length:12px_8px] bg-[position:right_14px_center] bg-no-repeat pr-8')
const num = (set: (v: string) => void, max: number) => (e: { target: { value: string } }) => (set(e.target.value.replace(/\D/g, '').slice(0, max)), setError(''))
const save = () => {
const submit = () => {
const [yy, mm, dd] = [Number(y), Number(m), Number(d)]
if (!validBirth(yy, mm, dd)) return setError('날짜를 다시 확인해 주세요')
const [hh, mi] = time ? time.split(':').map(Number) : [null, null]
setBirth({ y: yy, m: mm, d: dd, hour: hh, minute: mi, place, gender: initial?.gender ?? null })
track('saju_input', { with_time: time !== '' })
if (!y || !m || !d) return setError('생년월일을 모두 넣어 주세요')
if (!validBirth(yy, mm, dd)) return setError('없는 날짜예요. 다시 확인해 주세요')
const hh = hour === '' ? null : Number(hour)
save({ y: yy, m: mm, d: dd, hour: hh, minute: hh == null ? null : Number(minute), place, gender: initial?.gender ?? null })
track('saju_input', { with_time: hh != null })
onDone()
}
@@ -86,35 +102,63 @@ function BirthForm({ initial, onDone }: { initial: Birth | null; onDone: () => v
<div className="mx-4 mt-4 flex flex-col gap-4 rounded-[24px] bg-white p-5 shadow-[inset_0_-5px_0_var(--shade)]">
<div className="text-center">
<Ic name="yin_yang" className="mx-auto size-14" />
<p className="m-0 mt-2 font-jua text-[20px] leading-snug">태어난 날의 기운으로<br />오늘 날씨와 맞춰 봐요</p>
<p className="m-0 mt-2 font-jua text-[20px] leading-snug">
내 사주와 오늘 날씨로
<br />
오늘 하루를 봐요
</p>
</div>
<label className="flex flex-col gap-1.5 text-[13px] font-extrabold text-(--ink2)">
생년월일 (양력)
<span className="flex gap-1.5">
<input inputMode="numeric" placeholder="1995" value={y} onChange={(e) => setY(e.target.value.replace(/\D/g, '').slice(0, 4))} className={input} aria-label="년" />
<input inputMode="numeric" placeholder="3" value={m} onChange={(e) => setM(e.target.value.replace(/\D/g, '').slice(0, 2))} className={input} aria-label="월" />
<input inputMode="numeric" placeholder="14" value={d} onChange={(e) => setD(e.target.value.replace(/\D/g, '').slice(0, 2))} className={input} aria-label="일" />
</span>
</label>
<label className="flex flex-col gap-1.5 text-[13px] font-extrabold text-(--ink2)">
태어난 시각 (모르면 비워 두세요)
<input type="time" value={time} onChange={(e) => setTime(e.target.value)} className={cx(input, 'w-full')} />
</label>
<label className="flex flex-col gap-1.5 text-[13px] font-extrabold text-(--ink2)">
태어난 곳 (시각을 그곳에 맞춰요)
<select value={place} onChange={(e) => setPlace(e.target.value)} className={cx(input, 'w-full')}>
<fieldset className="m-0 flex min-w-0 flex-col gap-1.5 border-0 p-0">
<legend className="mb-1.5 p-0 text-[13px] font-extrabold text-(--ink2)">생년월일 (양력)</legend>
<div className="grid grid-cols-[1.5fr_1fr_1fr] gap-1.5">
<input inputMode="numeric" placeholder="연도" value={y} onChange={num(setY, 4)} className={box} aria-label="년" />
<input inputMode="numeric" placeholder="월" value={m} onChange={num(setM, 2)} className={box} aria-label="월" />
<input inputMode="numeric" placeholder="일" value={d} onChange={num(setD, 2)} className={box} aria-label="일" />
</div>
</fieldset>
<fieldset className="m-0 flex min-w-0 flex-col gap-1.5 border-0 p-0">
<legend className="mb-1.5 p-0 text-[13px] font-extrabold text-(--ink2)">태어난 시각 (모르면 '모름')</legend>
<div className="grid grid-cols-2 gap-1.5">
<select value={hour} onChange={(e) => setHour(e.target.value)} className={pick} aria-label="시">
<option value="">모름</option>
{HOURS.map((h) => (
<option key={h} value={h}>
{h}시
</option>
))}
</select>
<select value={minute} onChange={(e) => setMinute(e.target.value)} disabled={hour === ''} className={cx(pick, 'disabled:bg-[#f3f5f9] disabled:text-[#a0a8ba]')} aria-label="분">
{MINUTES.map((mi) => (
<option key={mi} value={mi}>
{mi}분
</option>
))}
</select>
</div>
</fieldset>
<label className="flex min-w-0 flex-col gap-1.5 text-[13px] font-extrabold text-(--ink2)">
태어난 지역
<select value={place} onChange={(e) => setPlace(e.target.value)} className={pick}>
{BIRTH_PLACES.map(([k, n]) => (
<option key={k} value={k}>
{n}
</option>
))}
</select>
<span className="text-xs font-semibold text-(--ink3)">지역마다 해가 뜨는 시각이 달라 태어난 시각을 그만큼 고쳐서 봐요.</span>
</label>
{error && <p className="m-0 text-center text-[13px] font-bold text-[#d9442f]">{error}</p>}
<button type="button" onClick={save} className="cursor-pointer rounded-full bg-(--orange) py-3.5 text-[15px] font-extrabold text-white">
내 기운 보기
<button type="button" onClick={submit} className="cursor-pointer rounded-full bg-(--orange) py-3.5 text-[15px] font-extrabold text-white">
오늘 날씨 사주 보기
</button>
<p className="m-0 text-center text-xs font-semibold text-(--ink3)">생년월일은 이 기기에만 저장돼요. 계산할 때만 보내고 서버에 남기지 않아요.</p>
{onCancel && (
<button type="button" onClick={onCancel} className="-mt-2 cursor-pointer py-1 text-[13px] font-extrabold text-(--ink3)">
취소
</button>
)}
<p className="m-0 text-center text-xs font-semibold text-(--ink3)">
{loggedIn ? '내 계정에 저장돼요. 내 정보에서 언제든 지울 수 있어요.' : '이 기기에만 저장돼요. 로그인하면 계정에 저장해 어느 기기에서든 바로 볼 수 있어요.'}
</p>
</div>
)
}
@@ -122,13 +166,17 @@ function BirthForm({ initial, onDone }: { initial: Birth | null; onDone: () => v
function Reading({ birth, onEdit }: { birth: Birth; onEdit: () => void }) {
const { region } = useRegion()
const { loggedIn } = useAuth()
const queryClient = useQueryClient()
const level = useLevel().data?.level
const body = { ...toBody(birth), region_code: region.code, gender: birth.gender === 'M' ? ('male' as const) : birth.gender === 'F' ? ('female' as const) : undefined }
// 레벨이 오르면 키가 바뀌어 새로 열린 칸까지 다시 받는다. 사주를 보면 각이 쌓이니 레벨도 새로 받는다
const q = useQuery({
queryKey: ['saju', body, loggedIn],
queryKey: ['saju', body, loggedIn, level],
staleTime: 10 * 60_000,
queryFn: async () => {
const { data } = await reading({ body })
if (!data.result?.success) throw new Error(data.result?.desc ?? 'saju')
if (loggedIn) queryClient.invalidateQueries({ queryKey: myLevelQueryKey() })
return data
},
})
@@ -147,8 +195,16 @@ function Reading({ birth, onEdit }: { birth: Birth; onEdit: () => void }) {
track('saju_view', { scene: r.me?.scene ?? '', score: r.today.score })
}, [r])
if (q.isPending) return <p className="m-0 px-4 py-16 text-center font-semibold text-(--ink2)">기운을 읽는 중이에요…</p>
if (!r?.today || !r.me) return <p className="m-0 px-4 py-16 text-center font-semibold text-(--ink2)">지금은 읽지 못했어요. 잠시 뒤에 다시 열어 주세요.</p>
if (q.isPending) return <p className="m-0 px-4 py-16 text-center font-semibold text-(--ink2)">사주를 풀고 있어요…</p>
if (!r?.today || !r.me)
return (
<div className="px-4 py-16 text-center">
<p className="m-0 font-semibold text-(--ink2)">결과를 불러오지 못했어요.</p>
<button type="button" onClick={() => q.refetch()} className="mt-3 cursor-pointer rounded-full bg-(--ink) px-4 py-2 text-[13px] font-extrabold text-white">
다시 시도
</button>
</div>
)
const t = r.today
const lock = (key: string) => r.locks?.find((l) => l.key === key)
@@ -161,17 +217,17 @@ function Reading({ birth, onEdit }: { birth: Birth; onEdit: () => void }) {
<p className="m-0 text-center font-bagel text-[60px] leading-none">{t.score}</p>
<h3 className="m-0 mt-1.5 text-center font-jua text-[23px] leading-tight font-normal">{t.title}</h3>
<div className="mt-2.5 flex flex-wrap justify-center gap-1.5 text-[11.5px] font-extrabold">
<span className="rounded-full bg-[#f3f6fb] px-2.5 py-1">사주 {t.saju_score}</span>
<span className="rounded-full bg-[#f3f6fb] px-2.5 py-1">사주 {t.saju_score}점</span>
{t.weather_points != null && (
<span className={cx('rounded-full px-2.5 py-1', t.weather_points >= 0 ? 'bg-[#e3f6ea] text-[#1f7a4f]' : 'bg-[#ffe8dc] text-[#c2471b]')}>
오늘 날씨와 궁합 {t.weather_points >= 0 ? '+' : '−'}
{Math.abs(t.weather_points)}
날씨 영향 {t.weather_points >= 0 ? '+' : '−'}
{Math.abs(t.weather_points)}점
</span>
)}
</div>
{(t.why?.length ?? 0) > 0 && (
<details className="mt-2 text-center">
<summary className="cursor-pointer text-xs font-bold text-(--ink3)">왜 이 점수인가요?</summary>
<summary className="cursor-pointer text-xs font-bold text-(--ink3)">왜 이 점수인가요? (↑ 올린 것 · ↓ 내린 것)</summary>
<ul className="m-0 mt-1.5 list-none p-0 text-xs font-semibold text-(--ink2)">
{t.why!.map((w) => (
<li key={w}>{w}</li>
@@ -192,9 +248,10 @@ function Reading({ birth, onEdit }: { birth: Birth; onEdit: () => void }) {
{r.week && <Week r={r} />}
{r.money && (
<Panel id="saju_money" icon="money_bag" title="금전운 · 일운">
{[...r.money.map((l) => ['💰', l]), ...(r.work ?? []).map((l) => ['💼', l])].map(([icon, l]) => (
<p key={l} className="m-0 mt-1 text-[14px] font-semibold first:mt-0">
{icon} {l}
{[...r.money.map((l) => ['money_bag', l]), ...(r.work ?? []).map((l) => ['briefcase', l])].map(([icon, l]) => (
<p key={l} className="m-0 mt-1.5 flex gap-2 text-[14px] font-semibold first:mt-0">
<Ic name={icon} className="mt-px size-5 shrink-0" />
{l}
</p>
))}
</Panel>
@@ -224,7 +281,7 @@ function DecisionCard({ c }: { c: SajuCard }) {
<div className="flex gap-3 rounded-[20px] bg-white px-4 py-3 shadow-[inset_0_-4px_0_var(--shade)]">
<Ic name={CARD_ICON[c.kind] ?? 'sparkles'} className="mt-0.5 size-8 shrink-0" />
<div className="min-w-0">
<p className="m-0 text-[12px] font-extrabold text-(--orange)">{c.kind === 'when' ? '중요한 일은 이때' : c.title}</p>
<p className="m-0 text-[12px] font-extrabold text-(--orange)">{c.kind === 'when' ? '내 기운에 맞는 시간' : c.title}</p>
<p className="m-0 font-jua text-[17px] leading-snug whitespace-pre-line">{c.kind === 'when' ? `${c.title} · ${c.sub}` : c.body}</p>
<p className="m-0 mt-0.5 text-[12px] leading-snug font-semibold text-(--ink3)">{c.kind === 'when' ? c.body : c.sub}</p>
</div>
@@ -236,7 +293,7 @@ function MeCard({ r, onEdit }: { r: ResSaju; onEdit: () => void }) {
const me = r.me!
const cols = [...me.pillars].reverse()
return (
<Panel icon={me.scene_icon} title={`내 기운 · ${me.scene}`} right={<button type="button" onClick={onEdit} className="cursor-pointer text-xs font-extrabold text-(--orange)">생년월일 바꾸기</button>}>
<Panel icon={me.scene_icon} title={`내 기운 · ${me.scene.replace(/ 기운$/, '')}`} right={<button type="button" onClick={onEdit} className="cursor-pointer text-xs font-extrabold text-(--orange)">생년월일 바꾸기</button>}>
<p className="m-0 text-[14px] font-semibold text-(--ink2)">{me.scene_desc}</p>
<div className="mt-3 grid grid-cols-4 gap-1.5 text-center">
{(me.hour_known ? cols : [null, ...cols]).map((p, i) => (
@@ -249,15 +306,15 @@ function MeCard({ r, onEdit }: { r: ResSaju; onEdit: () => void }) {
</>
) : (
<>
<span className="rounded-xl bg-[#f1f3f7] py-3 text-[14px] font-extrabold text-[#a0a8ba]">?</span>
<span className="rounded-xl bg-[#f1f3f7] py-3 text-[14px] font-extrabold text-[#a0a8ba]">?</span>
<span className="grid flex-1 place-items-center rounded-xl bg-[#f1f3f7] text-[12px] font-extrabold text-[#a0a8ba]">시각 모름</span>
</>
)}
</div>
))}
</div>
{(me.need?.length ?? 0) > 0 && <p className="m-0 mt-2.5 text-[13px] font-bold">내 기운에 필요한 날씨: {me.need!.join(' · ')}</p>}
{me.jeol_warning && <p className="m-0 mt-1 text-xs font-semibold text-[#c2471b]">태어난 날 절기가 바뀌어요. 시각을 넣으면 더 정확해요.</p>}
<p className="m-0 mt-2 text-[11.5px] font-semibold text-(--ink3)">태어난 연·월·일·시의 여덟 글자(사주팔자)예요. 색은 나무·불·흙·쇠·물 다섯 기운이에요.</p>
{(me.need?.length ?? 0) > 0 && <p className="m-0 mt-2 text-[13px] font-bold">내 기운에 좋은 날씨: {me.need!.join(' · ')}</p>}
{me.jeol_warning && <p className="m-0 mt-1 text-xs font-semibold text-[#c2471b]">태어난 날에 절기가 바뀌어요. 태어난 시각을 넣어야 달 기둥이 정확해요.</p>}
</Panel>
)
}
@@ -298,13 +355,13 @@ function Locked({ locks }: { locks: SajuLock[] }) {
<div className="flex items-center gap-3">
<Ic name="locked" className="size-8 shrink-0" />
<div className="min-w-0 flex-1">
<p className="m-0 font-jua text-[16px]">{loggedIn ? `다음에 열려요: ${next.name}` : '각을 모으면 차례로 열려요'}</p>
<p className="m-0 font-jua text-[16px]">{loggedIn ? `다음은 ${next.name}` : '각을 모으면 더 볼 수 있어요'}</p>
<p className="m-0 text-xs font-bold text-(--ink2)">
{loggedIn ? `Lv.${next.level}에서 열려요${close ? ` · ${level.next_points! - level.points}각 남았어요` : ''}` : '출석·사주·좋아요로 모은 각은 로그인해야 쌓여요'}
{loggedIn ? (close ? `${level.next_points! - level.points}각 더 모으면 열려요` : `Lv.${next.level}이 되면 열려요`) : "로그인하고 출석·사주 보기·좋아요를 하면 활동 포인트 '각'이 쌓여요"}
</p>
</div>
<button type="button" onClick={() => open(loggedIn ? { type: 'level' } : { type: 'login', why: 'level' })} className="shrink-0 cursor-pointer rounded-full bg-(--ink) px-3 py-1.5 text-xs font-extrabold text-white">
{loggedIn ? '각 모으기' : '로그인'}
{loggedIn ? '각 모으는 법' : '로그인'}
</button>
</div>
{close && (
@@ -325,55 +382,63 @@ function Locked({ locks }: { locks: SajuLock[] }) {
function Week({ r }: { r: ResSaju }) {
return (
<Panel id="saju_week" icon="spiral_calendar" title="이번 주 흐름">
<Panel id="saju_week" icon="spiral_calendar" title="앞으로 7일 흐름">
<ol className="m-0 flex list-none flex-col gap-1 p-0">
{r.week!.map((d) => (
<li key={d.day} className={cx('flex items-center gap-2 rounded-xl px-2 py-1.5 text-[13px] font-bold', d.best && 'bg-[#fff6ef]')}>
<span className="w-14 shrink-0">
{d.weekday} {Number(d.day.slice(8, 10))}일
</span>
<span className="w-[66px] shrink-0 whitespace-nowrap">{dayWord(d.day, d.weekday)}</span>
{d.icon && <Ic name={d.icon} className="size-6 shrink-0" />}
<span className="w-14 shrink-0 text-(--ink2)">{d.temp_max != null ? `${d.temp_min}~${d.temp_max}°` : ''}</span>
<span className="min-w-0 flex-1 truncate text-(--ink2)">{d.title}</span>
<span className="w-[52px] shrink-0 whitespace-nowrap text-(--ink2)">{d.temp_max != null ? `${d.temp_min}~${d.temp_max}°` : ''}</span>
<span className="min-w-0 flex-1 truncate text-[12.5px] text-(--ink2)">{d.title}</span>
<b className={cx('font-bagel text-[15px] font-normal', d.best ? 'text-(--orange)' : '')}>{d.score}</b>
</li>
))}
</ol>
<p className="m-0 mt-1.5 text-xs font-semibold text-(--ink3)">점수는 그날 사주와 예보로 계산해요. 주황색이 이번 주 가장 좋은 날이에요.</p>
<p className="m-0 mt-1.5 text-xs font-semibold text-(--ink3)">점수는 그날 사주와 예보로 계산해요. 주황색은 7일 중 점수가 가장 높은 날이에요.</p>
</Panel>
)
}
function Love({ r, birth }: { r: ResSaju; birth: Birth }) {
const love = r.love!
const pick = (g: 'M' | 'F' | null) => setBirth({ ...birth, gender: g })
const save = useSaveBirth()
const pick = (g: 'M' | 'F' | null) => save({ ...birth, gender: g })
const chip = 'cursor-pointer rounded-full bg-[#f3f6fb] px-2.5 py-1'
return (
<Panel id="saju_love" icon="red_heart" title="이번 주 연애운">
<Panel id="saju_love" icon="red_heart" title="앞으로 7일 연애운">
{love.good ? (
<div className="rounded-xl bg-[#fff0f3] px-3 py-2.5">
<p className="m-0 text-xs font-extrabold text-[#d6457a]">연애 기운 좋은 날</p>
<p className="m-0 text-xs font-extrabold text-[#d6457a]">연애 기운이 좋은 날</p>
<p className="m-0 font-jua text-[17px]">
{love.good.weekday}요일 {Number(love.good.day.slice(8, 10))}일{love.good.word ? ` · ${love.good.word} ${love.good.temp_max ?? ''}°` : ''}
{dayWord(love.good.day, love.good.weekday)}
{love.good.word ? ` · ${love.good.word} ${love.good.temp_max ?? ''}°` : ''}
</p>
<p className="m-0 text-[13px] font-semibold">{love.good.body}</p>
<p className="m-0 text-[11.5px] font-semibold text-(--ink3)">{love.good.why}</p>
</div>
) : (
<p className="m-0 text-[13px] font-semibold text-(--ink2)">이번 주엔 연애 기운이 특별히 드는 날이 없어요.</p>
<p className="m-0 text-[13px] font-semibold text-(--ink2)">앞으로 7일 중엔 연애 기운이 두드러지는 날이 없어요.</p>
)}
{love.caution && (
<p className="m-0 mt-2 text-[13px] font-semibold">
조심할 날: {love.caution.weekday}요일 — {love.caution.body} <span className="text-(--ink3)">({love.caution.why})</span>
조심할 날 {dayWord(love.caution.day, love.caution.weekday)}: {love.caution.body} <span className="text-(--ink3)">· {love.caution.why}</span>
</p>
)}
{!love.gender_known && (
<div className="mt-2.5 flex items-center gap-1.5 text-xs font-bold text-(--ink2)">
성별을 고르면 이성 기운까지 봐요
<button type="button" onClick={() => pick('M')} className="cursor-pointer rounded-full bg-[#f3f6fb] px-2.5 py-1">
남
{love.gender_known ? (
<p className="m-0 mt-2.5 text-xs font-bold text-(--ink3)">
{birth.gender === 'M' ? '남성' : '여성'} 기준으로 이성 인연(재성·관성)까지 봤어요 ·{' '}
<button type="button" onClick={() => pick(null)} className="cursor-pointer font-extrabold text-(--orange)">
빼고 보기
</button>
<button type="button" onClick={() => pick('F')} className="cursor-pointer rounded-full bg-[#f3f6fb] px-2.5 py-1">
여
</p>
) : (
<div className="mt-2.5 flex flex-wrap items-center gap-1.5 text-xs font-bold text-(--ink2)">
성별을 고르면 이성 인연(재성·관성)까지 봐요
<button type="button" onClick={() => pick('M')} className={chip}>
남성
</button>
<button type="button" onClick={() => pick('F')} className={chip}>
여성
</button>
</div>
)}
@@ -385,11 +450,15 @@ function Period({ id, icon, p }: { id: string; icon: string; p: NonNullable<ResS
return (
<Panel id={id} icon={icon} title={p.label}>
<p className="m-0 font-jua text-[17px]">
{p.title} <span className="text-[13px] text-(--ink3)">({p.pillar} · {p.ten_god})</span>
{p.title} <span className="text-[13px] text-(--ink3)">({p.ten_god})</span>
</p>
<p className="m-0 mt-0.5 text-[13.5px] font-semibold">{p.body}</p>
{(p.months?.length ?? 0) > 0 && <p className="m-0 mt-1.5 text-[13.5px] font-bold">잘 맞는 달: {p.months!.map((m) => `${m}월`).join(' · ')}</p>}
{(p.notes?.length ?? 0) > 0 && <p className="m-0 mt-1 text-xs font-semibold text-(--ink3)">{p.notes!.join(' · ')}</p>}
{(p.months?.length ?? 0) > 0 && <p className="m-0 mt-1.5 text-[13.5px] font-bold">{p.label.includes('미리') ? '내 사주와 잘 맞는 달' : '남은 달 중 잘 맞는 달'}: {p.months!.map((m) => `${m}월`).join(' · ')}</p>}
{p.notes?.map((n) => (
<p key={n} className="m-0 mt-1 text-xs font-semibold text-(--ink3)">
{n}
</p>
))}
</Panel>
)
}
@@ -402,10 +471,11 @@ function Match({ birth }: { birth: Birth }) {
const [error, setError] = useState('')
const run = useMutation({ ...matchMutation() })
const res: ResSajuMatch | undefined = run.data?.result?.success ? run.data : undefined
const input = 'min-w-0 flex-1 rounded-xl border-[1.5px] border-(--line) bg-white px-2 py-2 text-center text-[15px] font-bold'
const input = 'w-full min-w-0 rounded-xl border-[1.5px] border-(--line) bg-white px-1 py-2 text-center text-[15px] font-bold'
const go = () => {
const [yy, mm, dd] = [Number(y), Number(m), Number(d)]
if (!validBirth(yy, mm, dd)) return setError('날짜를 다시 확인해 주세요')
if (!y || !m || !d) return setError('상대 생년월일을 모두 넣어 주세요')
if (!validBirth(yy, mm, dd)) return setError('없는 날짜예요. 다시 확인해 주세요')
setError('')
run.mutate({ body: { region_code: region.code, me: toBody(birth), friend: { birth_date: `${yy}-${String(mm).padStart(2, '0')}-${String(dd).padStart(2, '0')}`, longitude: 126.98 } } })
}
@@ -420,7 +490,7 @@ function Match({ birth }: { birth: Birth }) {
</button>
</p>
<p className="m-0 font-jua text-[19px]">
{res.title} <span className="font-bagel text-[17px] text-(--orange)">{res.score}</span>
{res.title} <span className="font-bagel text-[17px] text-(--orange)">{res.score}점</span>
</p>
{res.lines?.map((l) => (
<p key={l} className="m-0 mt-1 text-[13.5px] font-semibold">
@@ -429,23 +499,25 @@ function Match({ birth }: { birth: Birth }) {
))}
{res.day && (
<p className="m-0 mt-2 rounded-xl bg-[#fff6ef] px-3 py-2 text-[13.5px] font-bold">
이번 주 같이 나가기 좋은 날: {res.day.weekday}요일 {Number(res.day.day.slice(8, 10))}일{res.day.word ? ` · ${res.day.word} ${res.day.temp_max ?? ''}°` : ''}
앞으로 7일 중 같이 나가기 좋은 날: {dayWord(res.day.day, res.day.weekday)}
{res.day.word ? ` · ${res.day.word} ${res.day.temp_max ?? ''}°` : ''}
</p>
)}
<p className="m-0 mt-1.5 text-xs font-semibold text-(--ink3)">상대 기운: {res.friend_scene}</p>
</>
) : (
<>
<p className="m-0 mb-2 text-[13px] font-semibold text-(--ink2)">상대 생년월일(양력)을 넣으면 둘의 사이와 이번 주 같이 나가기 좋은 날을 봐요.</p>
<div className="flex gap-1.5">
<input inputMode="numeric" placeholder="1996" value={y} onChange={(e) => setY(e.target.value.replace(/\D/g, '').slice(0, 4))} className={input} aria-label="상대 년" />
<input inputMode="numeric" placeholder="11" value={m} onChange={(e) => setM(e.target.value.replace(/\D/g, '').slice(0, 2))} className={input} aria-label="상대 월" />
<input inputMode="numeric" placeholder="2" value={d} onChange={(e) => setD(e.target.value.replace(/\D/g, '').slice(0, 2))} className={input} aria-label="상대 일" />
<p className="m-0 mb-2 text-[13px] font-semibold text-(--ink2)">상대 생년월일(양력)을 넣으면 두 사람 사주가 어떻게 맞는지와 앞으로 7일 중 같이 나가기 좋은 날을 봐요.</p>
<div className="grid grid-cols-[1.5fr_1fr_1fr_auto] gap-1.5">
<input inputMode="numeric" placeholder="연도" value={y} onChange={(e) => setY(e.target.value.replace(/\D/g, '').slice(0, 4))} className={input} aria-label="상대 년" />
<input inputMode="numeric" placeholder="월" value={m} onChange={(e) => setM(e.target.value.replace(/\D/g, '').slice(0, 2))} className={input} aria-label="상대 월" />
<input inputMode="numeric" placeholder="일" value={d} onChange={(e) => setD(e.target.value.replace(/\D/g, '').slice(0, 2))} className={input} aria-label="상대 일" />
<button type="button" onClick={go} disabled={run.isPending} className="shrink-0 cursor-pointer rounded-xl bg-(--orange) px-3 text-[14px] font-extrabold text-white">
보기
</button>
</div>
{error && <p className="m-0 mt-1.5 text-xs font-bold text-[#d9442f]">{error}</p>}
{(run.isError || (run.data && !run.data.result?.success)) && <p className="m-0 mt-1.5 text-xs font-bold text-[#d9442f]">궁합을 불러오지 못했어요. 다시 눌러 주세요.</p>}
<p className="m-0 mt-1.5 text-xs font-semibold text-(--ink3)">상대 생년월일은 저장하지 않아요.</p>
</>
)}
+18 -9
View File
@@ -13,8 +13,14 @@ import { Ic } from './ui'
const ACTION_TO: Record<string, string> = { saju: '/saju', react: '/', talk: '/talk' }
const ACTION_FEATURE: Record<string, string> = { tarot: 'tarot', checkin: 'tarot' }
// 받침 있으면 a, 없으면 b: josa('연애운', '이', '가') → '연애운이'
const josa = (w: string, a: string, b: string) => {
const c = w.charCodeAt(w.length - 1) - 0xac00
return w + (c >= 0 && c < 11172 && c % 28 === 0 ? b : a)
}
// 창이 쌓아 둔 방문 기록을 닫으며 되돌리므로, 되돌린 뒤(popstate)에 이동해야 새 주소가 안 지워진다
function useCloseAndGo() {
export function useCloseAndGo() {
const { close } = useSheet()
const navigate = useNavigate()
return (to: string) => {
@@ -125,8 +131,11 @@ export function LevelCard({ link = true }: { link?: boolean }) {
</div>
<div className="mt-1.5 flex items-center justify-between gap-2 text-xs font-bold text-(--ink2)">
<span>
{level.next_points != null ? `${level.next_points - level.points}각 더 모으면 Lv.${level.level + 1} ${level.next_name}` : '가장 높은 레벨이에요'}
{unlock.length > 0 && <b className="text-(--orange)"> · {unlock.join(', ')}</b>}
{level.next_points == null
? '가장 높은 레벨이에요'
: unlock.length > 0
? `${level.next_points - level.points}각 더 모으면 ${josa(unlock.join(', '), '이', '가')} 열려요`
: `${level.next_points - level.points}각 더 모으면 Lv.${level.level + 1} ${level.next_name}`}
</span>
{link && (
<button type="button" onClick={() => open({ type: 'level' })} className="shrink-0 cursor-pointer text-(--orange)">
@@ -145,7 +154,7 @@ export function LevelSheet() {
if (!level) return null
const steps = (level.unlocks ?? []).reduce<Record<number, string[]>>((m, u) => ({ ...m, [u.level]: [...(m[u.level] ?? []), u.name] }), {})
return (
<div className="flex flex-col gap-4 px-4 pb-4">
<div className="flex flex-1 flex-col gap-4 overflow-auto overscroll-contain px-4 pt-3.5 pb-4">
<LevelCard link={false} />
<section>
<h4 className="m-0 mb-2 text-sm font-extrabold">오늘 받을 수 있는 각</h4>
@@ -162,14 +171,14 @@ export function LevelSheet() {
<span className={cx('grid size-5 place-items-center rounded-full text-[11px] text-white', done ? 'bg-[#1f9d62]' : 'bg-[#dfe5ef]')}>{done ? '✓' : ''}</span>
<span className={cx(done && 'text-(--ink3) line-through')}>{a.name}</span>
<span className="ml-auto font-bagel text-[13px] font-normal text-(--orange)">
{a.earned > 0 && a.cap > a.points ? `${a.earned}/${a.cap}` : `+${a.points}`}각
{done ? `오늘 ${a.earned}각 받음` : a.earned > 0 ? `${a.earned}/${a.cap}각` : `+${a.points}각`}
</span>
{to && !done && <span className="text-(--ink3)">›</span>}
</li>
)
})}
</ul>
<p className="m-0 mt-1.5 text-xs font-semibold text-(--ink3)">{level.streak > 0 ? `${level.streak}일 이어 출석 · 7일마다 +50각` : '7일 이어 출석하면 +50각'}</p>
<p className="m-0 mt-1.5 text-xs font-semibold text-(--ink3)">{level.streak > 0 ? `${level.streak}일째 연속 출석 중 · 7일 연속이면 +50각` : '7일 연속 출석하면 +50각을 더 받아요'}</p>
</section>
<section>
<h4 className="m-0 mb-2 text-sm font-extrabold">레벨이 오르면 열려요</h4>
@@ -183,7 +192,7 @@ export function LevelSheet() {
<b className="block text-[13.5px] font-extrabold">
Lv.{lv} {name} <span className="font-semibold text-(--ink3)">· {points}각</span>
</b>
<span className="block text-xs font-semibold text-(--ink2)">{lv === 1 ? '지금 있는 기능 전부' : (steps[lv] ?? []).join(', ')}</span>
<span className="block text-xs font-semibold text-(--ink2)">{lv === 1 ? '날씨각의 기본 기능 모두' : (steps[lv] ?? []).join(', ')}</span>
</span>
</li>
)
@@ -203,12 +212,12 @@ export function LevelUpSheet({ level: lv }: { level: number }) {
const opened = unlocks.map((u) => u.name)
const name = level?.levels?.find((l) => l.level === lv)?.name
return (
<div className="flex flex-col items-center gap-2 px-6 pt-2 pb-6 text-center">
<div className="flex flex-1 flex-col items-center gap-2 overflow-auto overscroll-contain px-6 pt-2 pb-6 text-center">
<Ic name={levelIcon(lv)} className="size-24" />
<b className="font-jua text-[28px] font-normal">
Lv.{lv} {name}
</b>
{opened.length > 0 && <p className="m-0 text-[15px] font-bold text-(--ink2)">새로 열렸어요: {opened.join(', ')}</p>}
{opened.length > 0 && <p className="m-0 text-[15px] font-bold text-(--ink2)">이제 {josa(opened.join(', '), '을', '를')} 볼 수 있어요</p>}
{unlocks.length > 0 && (
<button type="button" onClick={() => go(`/saju#${unlocks[0].key}`)} className="mt-3 w-full cursor-pointer rounded-full bg-(--orange) py-3 text-[15px] font-extrabold text-white">
{opened[0]} 보러 가기
+48 -2
View File
@@ -1,6 +1,11 @@
import { useSyncExternalStore } from 'react'
import { useEffect, useSyncExternalStore } from 'react'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { getBirthQueryKey } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'
import { deleteBirth, getBirth, putBirth } from '@nalssigak/shared/api/client/sdk.gen'
import type { SajuSavedBirth } from '@nalssigak/shared/api/client/types.gen'
import { useAuth } from './authContext'
/** 날씨 사주에 쓰는 태어난 정보. 이 기기에만 저장하고, 계산할 때만 서버에 보낸다(서버는 남기지 않는다) */
/** 날씨 사주에 쓰는 태어난 정보. 기기에 두고, 로그인했으면 계정에도 저장한다 */
export type Birth = { y: number; m: number; d: number; hour: number | null; minute: number | null; place: string; gender: 'M' | 'F' | null }
const KEY = 'nalssigak.b.birth'
@@ -58,6 +63,47 @@ export function setBirth(b: Birth | null) {
export const useBirth = () => useSyncExternalStore(subscribe, () => birth)
const pad = (n: number) => String(n).padStart(2, '0')
const toSaved = (b: Birth): SajuSavedBirth => ({
birth_date: `${b.y}-${pad(b.m)}-${pad(b.d)}`,
birth_time: b.hour != null ? `${pad(b.hour)}:${pad(b.minute ?? 0)}` : undefined,
place: b.place,
gender: b.gender === 'M' ? 'male' : b.gender === 'F' ? 'female' : undefined,
})
const fromSaved = (s: SajuSavedBirth): Birth => {
const [y, m, d] = s.birth_date.split('-').map(Number)
const [hour, minute] = s.birth_time ? s.birth_time.split(':').map(Number) : [null, null]
return { y, m, d, hour, minute, place: s.place ?? 'seoul', gender: s.gender === 'male' ? 'M' : s.gender === 'female' ? 'F' : null }
}
/** 로그인했으면 계정의 생년월일을 기기로 가져온다. 계정엔 없고 기기에만 있으면 계정으로 올린다 */
export function useAccountBirth() {
const { loggedIn } = useAuth()
const q = useQuery({ queryKey: getBirthQueryKey(), enabled: loggedIn, staleTime: Infinity, queryFn: async () => (await getBirth()).data })
useEffect(() => {
if (!loggedIn || !q.data?.result?.success) return
if (q.data.birth) setBirth(fromSaved(q.data.birth))
else if (birth) putBirth({ body: toSaved(birth) }).catch((e) => console.warn('[saju] 계정에 올리지 못함', e))
}, [loggedIn, q.data])
return loggedIn && q.isPending
}
/** 생년월일 저장·지우기: 기기에 두고, 로그인했으면 계정에도 */
export function useSaveBirth() {
const { loggedIn } = useAuth()
const queryClient = useQueryClient()
return async (b: Birth | null) => {
setBirth(b)
if (!loggedIn) return
try {
const { data } = b ? await putBirth({ body: toSaved(b) }) : await deleteBirth()
if (data.result?.success) queryClient.setQueryData(getBirthQueryKey(), data)
} catch (e) {
console.warn('[saju] 계정에 저장하지 못함', e)
}
}
}
/** 있는 날짜이고 1900-01-01 ~ 오늘 사이인지 */
export function validBirth(y: number, m: number, d: number) {
const at = new Date(Date.UTC(y, m - 1, d))