feat: 사주 금전·일은 이번 주에 정할 날로, 올해 운에 잘 맞는 달, 레벨업 창에서 열린 칸으로 바로 가기
- 금전·일: 오늘 카드를 되풀이하지 않고 이번 주 중 결제·계약할 날, 돈 빌려주기 피할 날, 보고·면접 잡을 날 - 올해 운: 잘 맞는 달 3개, 11월부터는 다음 해 미리 보기 - 레벨업 창 '…보러 가기' → /saju#칸, 내 레벨 창의 각 모으는 일 줄을 누르면 그 화면으로 - 궁합 결과에 상대 생일과 다른 사람 보기
This commit is contained in:
1 parent
e4834fd24e
commit
cb013fcc9a
7 files changed
+121
-28
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { useNavigate } from 'react-router'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { attendMutation, myLevelOptions, myLevelQueryKey, sharedMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'
|
||||
import type { ResLevel } from '@nalssigak/shared/api/client/types.gen'
|
||||
@@ -8,6 +9,20 @@ import { HIDDEN } from './features'
|
||||
import { useSheet } from './sheetContext'
|
||||
import { Ic } from './ui'
|
||||
|
||||
// 각을 주는 일 → 그 일을 하러 가는 곳, 숨긴 기능에 딸린 일 (서버 ACTIONS 키)
|
||||
const ACTION_TO: Record<string, string> = { saju: '/saju', react: '/', talk: '/talk' }
|
||||
const ACTION_FEATURE: Record<string, string> = { tarot: 'tarot', checkin: 'tarot' }
|
||||
|
||||
// 창이 쌓아 둔 방문 기록을 닫으며 되돌리므로, 되돌린 뒤(popstate)에 이동해야 새 주소가 안 지워진다
|
||||
function useCloseAndGo() {
|
||||
const { close } = useSheet()
|
||||
const navigate = useNavigate()
|
||||
return (to: string) => {
|
||||
window.addEventListener('popstate', () => navigate(to), { once: true })
|
||||
close()
|
||||
}
|
||||
}
|
||||
|
||||
// 레벨마다 보여 줄 하늘 아이콘 (이름은 서버 LEVELS)
|
||||
const LEVEL_ICON = ['droplet', 'sun', 'leaf', 'rainbow', 'sunset', 'milky_way', 'shooting_star']
|
||||
export const levelIcon = (level: number) => LEVEL_ICON[Math.min(Math.max(level, 1), LEVEL_ICON.length) - 1]
|
||||
@@ -126,6 +141,7 @@ export function LevelCard({ link = true }: { link?: boolean }) {
|
||||
/** 내 레벨 창: 오늘 받을 수 있는 각, 레벨마다 열리는 것 */
|
||||
export function LevelSheet() {
|
||||
const level = useLevel().data
|
||||
const go = useCloseAndGo()
|
||||
if (!level) return null
|
||||
const steps = (level.unlocks ?? []).reduce<Record<number, string[]>>((m, u) => ({ ...m, [u.level]: [...(m[u.level] ?? []), u.name] }), {})
|
||||
return (
|
||||
@@ -134,15 +150,21 @@ export function LevelSheet() {
|
||||
<section>
|
||||
<h4 className="m-0 mb-2 text-sm font-extrabold">오늘 받을 수 있는 각</h4>
|
||||
<ul className="m-0 list-none rounded-2xl bg-white p-0 shadow-[inset_0_-4px_0_var(--shade)]">
|
||||
{(level.today ?? []).filter((a) => !HIDDEN.has(a.action)).map((a) => {
|
||||
{(level.today ?? []).filter((a) => !HIDDEN.has(ACTION_FEATURE[a.action] ?? a.action)).map((a) => {
|
||||
const done = a.earned >= a.cap
|
||||
const to = ACTION_TO[a.action]
|
||||
return (
|
||||
<li key={a.action} className="flex items-center gap-2.5 border-b border-[#eef1f6] px-3.5 py-2.5 text-[13.5px] font-bold last:border-0">
|
||||
<li
|
||||
key={a.action}
|
||||
onClick={to && !done ? () => go(to) : undefined}
|
||||
className={cx('flex items-center gap-2.5 border-b border-[#eef1f6] px-3.5 py-2.5 text-[13.5px] font-bold last:border-0', to && !done && 'cursor-pointer')}
|
||||
>
|
||||
<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}`}각
|
||||
</span>
|
||||
{to && !done && <span className="text-(--ink3)">›</span>}
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
@@ -176,7 +198,9 @@ export function LevelSheet() {
|
||||
export function LevelUpSheet({ level: lv }: { level: number }) {
|
||||
const level = useLevel().data
|
||||
const { open } = useSheet()
|
||||
const opened = (level?.unlocks ?? []).filter((u) => u.level === lv).map((u) => u.name)
|
||||
const go = useCloseAndGo()
|
||||
const unlocks = (level?.unlocks ?? []).filter((u) => u.level === lv)
|
||||
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">
|
||||
@@ -185,7 +209,12 @@ export function LevelUpSheet({ level: lv }: { level: number }) {
|
||||
Lv.{lv} {name}
|
||||
</b>
|
||||
{opened.length > 0 && <p className="m-0 text-[15px] font-bold text-(--ink2)">새로 열렸어요: {opened.join(', ')}</p>}
|
||||
<button type="button" onClick={() => open({ type: 'level' })} className="mt-3 w-full cursor-pointer rounded-full bg-(--orange) py-3 text-[15px] font-extrabold text-white">
|
||||
{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]} 보러 가기
|
||||
</button>
|
||||
)}
|
||||
<button type="button" onClick={() => open({ type: 'level' })} className={cx('w-full cursor-pointer py-2 text-[14px] font-extrabold', unlocks.length ? 'text-(--ink2)' : 'mt-3 rounded-full bg-(--orange) py-3 text-white')}>
|
||||
내 레벨 보기
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user