feat: 나만의 각 1단계 — 공식 각 두 개를 섞어 내 각 만들기(점수는 낮은 쪽), 로그인 없이 1개·로그인하면 계정 저장, 친구에게 보낸 링크로 내 동네 점수 보기
This commit is contained in:
1 parent
96cbd19c61
commit
a8a126f6a5
18 files changed
+842
-6
No files matched your search
@@ -0,0 +1,135 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useState } from 'react'
|
||||
import { getFeedOptions } from '../api/client/@tanstack/react-query.gen'
|
||||
import type { TopIndex } from '../api/client/types.gen'
|
||||
import { cx } from '../lib/utils'
|
||||
import { mix, shareUrl, useMyGak } from './myGakState'
|
||||
import { useRegion } from './regionContext'
|
||||
import { useSheet } from './sheetContext'
|
||||
import { Ic, Sec } from './ui'
|
||||
|
||||
function Bar({ g, low }: { g: TopIndex; low: boolean }) {
|
||||
return (
|
||||
<span className="grid grid-cols-[1fr_auto] items-center gap-x-2 text-[12.5px] font-bold">
|
||||
<span>{g.name}</span>
|
||||
<em className={cx('font-jua not-italic', low ? 'text-(--ink2)' : 'text-(--orange)')}>{g.score}</em>
|
||||
<i className="col-span-2 block h-[7px] overflow-hidden rounded-full bg-[#e3eaf4]">
|
||||
<s className={cx('b-keep-bg block h-full', low ? 'bg-[#f3b38f]' : 'bg-(--orange)')} style={{ width: `${g.score}%` }} />
|
||||
</i>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
/** 오늘 탭의 내 각 줄: 섞은 각 카드들과 새로 섞기 */
|
||||
export function MyGakRow({ stories }: { stories: TopIndex[] }) {
|
||||
const { open } = useSheet()
|
||||
const { pairs, remove } = useMyGak()
|
||||
const [copied, setCopied] = useState<string | null>(null)
|
||||
const send = (ids: number[], name: string) => {
|
||||
const url = shareUrl(ids)
|
||||
if (navigator.share) {
|
||||
navigator.share({ title: `${name} · 날씨각`, url }).catch((e: unknown) => {
|
||||
if (!(e instanceof DOMException && e.name === 'AbortError')) console.error('[myGak] share', e)
|
||||
})
|
||||
return
|
||||
}
|
||||
navigator.clipboard.writeText(url).then(
|
||||
() => setCopied(ids.join()),
|
||||
(e: unknown) => console.error('[myGak] copy', e),
|
||||
)
|
||||
}
|
||||
if (!stories.length) return null
|
||||
return (
|
||||
<>
|
||||
<Sec title="내 각" sub="공식 각 두 개를 섞어 만들어요. 둘 다 좋아야 높아요" />
|
||||
<div className="flex snap-x gap-2 overflow-x-auto px-3 pb-1 [scrollbar-width:none]">
|
||||
{pairs.map((p) => {
|
||||
const m = mix(stories, p.ids)
|
||||
if (!m) return null
|
||||
return (
|
||||
<div key={p.ids.join()} className="flex w-[220px] shrink-0 snap-start flex-col gap-1.5 rounded-[22px] bg-white p-3 shadow-[inset_0_-5px_0_var(--shade)]">
|
||||
<div className="flex items-center gap-1">
|
||||
<Ic name={m.a.icon} className="w-8" />
|
||||
<Ic name={m.b.icon} className="-ml-3 w-8" />
|
||||
<b className="ml-1 font-jua text-[17px] leading-tight font-normal">{m.name}</b>
|
||||
<em className={cx('ml-auto font-bagel text-[28px] leading-none not-italic', m.score < 50 ? 'text-(--ink3)' : 'text-(--orange)')}>{m.score}</em>
|
||||
</div>
|
||||
<Bar g={m.a} low={m.low === m.a && m.a.score !== m.b.score} />
|
||||
<Bar g={m.b} low={m.low === m.b && m.a.score !== m.b.score} />
|
||||
<div className="mt-0.5 flex gap-1.5">
|
||||
<button type="button" onClick={() => send(p.ids, m.name)} className="cursor-pointer rounded-full bg-(--ink) px-3 py-1.5 text-[12.5px] font-extrabold text-white">
|
||||
{copied === p.ids.join() ? '링크 복사함' : '친구에게 보내기'}
|
||||
</button>
|
||||
<button type="button" onClick={() => remove(p)} className="cursor-pointer rounded-full bg-[#eef4fc] px-3 py-1.5 text-[12.5px] font-extrabold text-(--ink2)">
|
||||
지우기
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
<button type="button" onClick={() => open({ type: 'mix' })} className="flex w-[120px] shrink-0 cursor-pointer snap-start flex-col items-center justify-center gap-1 rounded-[22px] border-2 border-dashed border-(--line) p-3 font-jua text-[15px] text-(--ink2)">
|
||||
<span className="text-[26px] leading-none">+</span>
|
||||
각 섞기
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
/** 섞을 각 고르기와 미리보기. ids 가 둘이면(받은 링크) 바로 미리보기 */
|
||||
export function MixSheet({ ids: start = [], shared = false, onDone }: { ids?: number[]; shared?: boolean; onDone: () => void }) {
|
||||
const { region } = useRegion()
|
||||
const stories = useQuery(getFeedOptions({ query: { region: region.code } })).data?.stories ?? []
|
||||
const { mixable, has, create, pending } = useMyGak()
|
||||
const [ids, setIds] = useState<number[]>(start.slice(0, 2))
|
||||
const choices = stories.filter((g) => mixable.has(g.index_id))
|
||||
const m = ids.length === 2 ? mix(stories, ids) : null
|
||||
const owned = ids.length === 2 && has(ids)
|
||||
const toggle = (id: number) => setIds((now) => (now.includes(id) ? now.filter((x) => x !== id) : now.length < 2 ? [...now, id] : [now[0], id]))
|
||||
|
||||
return (
|
||||
<div className="flex-1 overflow-auto overscroll-contain px-4 pt-3.5 pb-[18px]">
|
||||
{!shared && (
|
||||
<>
|
||||
<p className="m-0 font-jua text-[19px]">{ids.length === 2 ? '이 둘을 섞어요' : ids.length ? '하나 더 골라요' : '섞을 각 두 개를 골라요'}</p>
|
||||
<p className="mt-0.5 mb-2.5 text-[13px] font-semibold text-(--ink2)">함께 할 일끼리 골라요. 점수는 둘 중 낮은 쪽이에요</p>
|
||||
<div className="flex flex-wrap gap-1.5" role="group" aria-label="섞을 각">
|
||||
{choices.map((g) => {
|
||||
const on = ids.includes(g.index_id)
|
||||
return (
|
||||
<button key={g.index_id} type="button" aria-pressed={on} onClick={() => toggle(g.index_id)} className={cx('flex cursor-pointer items-center gap-1 rounded-full py-1 pr-3 pl-1.5 text-[13.5px] font-extrabold', on ? 'bg-(--orange) text-white' : 'bg-[#eef4fc] text-(--ink)')}>
|
||||
<Ic name={g.icon} className="w-6" />
|
||||
{g.name.replace(/각$/, '')}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{m && (
|
||||
<div className="mt-3.5 flex flex-col gap-2 rounded-[20px] bg-[#f3f6fb] p-3.5">
|
||||
{shared && <p className="m-0 text-[13px] font-bold text-(--ink2)">친구가 보낸 각이에요. {region.name} 기준 점수예요</p>}
|
||||
<div className="flex items-center gap-1">
|
||||
<Ic name={m.a.icon} className="w-9" />
|
||||
<Ic name={m.b.icon} className="-ml-3 w-9" />
|
||||
<b className="ml-1 font-jua text-[20px] font-normal">{m.name}</b>
|
||||
<em className={cx('ml-auto font-bagel text-[36px] leading-none not-italic', m.score < 50 ? 'text-(--ink3)' : 'text-(--orange)')}>{m.score}</em>
|
||||
</div>
|
||||
<Bar g={m.a} low={m.low === m.a && m.a.score !== m.b.score} />
|
||||
<Bar g={m.b} low={m.low === m.b && m.a.score !== m.b.score} />
|
||||
<p className="m-0 text-[13px] font-semibold text-(--ink2)">
|
||||
{m.a.score === m.b.score ? '두 각 점수가 같아요' : `오늘은 ${m.low.name} 점수를 따라가요`}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
disabled={!m || owned || pending}
|
||||
onClick={() => m && create(ids, onDone)}
|
||||
className="mt-3.5 w-full cursor-pointer rounded-2xl bg-(--orange) py-3 font-jua text-[17px] text-white disabled:cursor-default disabled:opacity-45"
|
||||
>
|
||||
{owned ? '이미 내 각에 있어요' : shared ? '내 각으로 가져오기' : '내 각으로 만들기'}
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user