feat: 10/20 회의 반영 — 이야기 탭을 오늘 피드로 합침(글쓰기 칸·사진 올리기·위치 정보 삭제), 오늘의 각 카드와 히어로·각 공유 템플릿, 나만의 각을 이름+날씨 조건 저장으로, 로그인 없이 좋아요(IP 해시), 피드 순서·불쾌지수 상시·포스트 그림 배경, 새 각 아이콘
This commit is contained in:
1 parent
017022a0b0
commit
d0213f41a6
81 files changed
+3503
-593
No files matched your search
+154
-91
@@ -1,134 +1,197 @@
|
||||
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 { useState, type ReactNode } from 'react'
|
||||
import type { MyGakRule, MyGakScore } from '../api/client/types.gen'
|
||||
import { cx } from '../lib/utils'
|
||||
import { mix, shareUrl, useMyGak } from './myGakState'
|
||||
import { gakName, shareUrl, SLOTS, type MyGak, type Slot, useMyGak, useMyGakScores } from './myGakState'
|
||||
import { useRegion } from './regionContext'
|
||||
import { useSheet } from './sheetContext'
|
||||
import { Ic, Sec } from './ui'
|
||||
import { Sec } from './ui'
|
||||
|
||||
function Bar({ g, low }: { g: TopIndex; low: boolean }) {
|
||||
const SLOT_WORD = Object.fromEntries(SLOTS) as Record<Slot, string>
|
||||
|
||||
function Score({ s, big }: { s?: MyGakScore; big?: boolean }) {
|
||||
const v = s?.score
|
||||
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>
|
||||
<em className={cx('ml-auto font-bagel leading-none not-italic', big ? 'text-[36px]' : 'text-[28px]', v == null || v < 50 ? 'text-(--ink3)' : 'text-(--orange)')}>
|
||||
{v ?? '–'}
|
||||
</em>
|
||||
)
|
||||
}
|
||||
|
||||
/** 오늘 탭의 내 각 줄: 섞은 각 카드들과 새로 섞기 */
|
||||
export function MyGakRow({ stories }: { stories: TopIndex[] }) {
|
||||
function Reasons({ s }: { s?: MyGakScore }) {
|
||||
if (!s?.slot) return <p className="m-0 text-[12.5px] font-semibold text-(--ink3)">예보를 불러오는 중이에요</p>
|
||||
return (
|
||||
<p className="m-0 text-[12.5px] leading-snug font-semibold text-(--ink2)">
|
||||
<b className="mr-1 text-(--ink)">{SLOT_WORD[s.slot as Slot]}</b>
|
||||
{s.reasons?.join(' · ')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
/** 오늘 탭의 내 각 줄: 내가 정한 조건으로 매긴 오늘 점수 */
|
||||
export function MyGakRow() {
|
||||
const { open } = useSheet()
|
||||
const { pairs, remove } = useMyGak()
|
||||
const [copied, setCopied] = useState<string | null>(null)
|
||||
const send = (ids: number[], name: string) => {
|
||||
const url = shareUrl(ids)
|
||||
const { items, remove } = useMyGak()
|
||||
const scores = useMyGakScores(items.map((g) => g.rule)).data?.scores ?? []
|
||||
const [copied, setCopied] = useState<number | null>(null)
|
||||
const send = (g: MyGak, i: number) => {
|
||||
const url = shareUrl(g)
|
||||
if (navigator.share) {
|
||||
navigator.share({ title: `${name} · 날씨각`, url }).catch((e: unknown) => {
|
||||
navigator.share({ title: `${g.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()),
|
||||
() => setCopied(i),
|
||||
(e: unknown) => console.error('[myGak] copy', e),
|
||||
)
|
||||
}
|
||||
if (!stories.length) return null
|
||||
return (
|
||||
<>
|
||||
<Sec title="내 각" sub="공식 각 두 개를 섞어 만들어요. 둘 다 좋아야 높아요" />
|
||||
<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>
|
||||
{items.map((g, i) => (
|
||||
<div key={g.id ?? 'local'} 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">
|
||||
<b className="font-jua text-[17px] leading-tight font-normal">{g.name}</b>
|
||||
<Score s={scores[i]} />
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
<Reasons s={scores[i]} />
|
||||
<div className="mt-auto flex gap-1.5 pt-0.5">
|
||||
<button type="button" onClick={() => send(g, i)} className="cursor-pointer rounded-full bg-(--ink) px-3 py-1.5 text-[12.5px] font-extrabold text-white">
|
||||
{copied === i ? '링크 복사함' : '친구에게 보내기'}
|
||||
</button>
|
||||
<button type="button" onClick={() => remove(g)} 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 }) {
|
||||
function Row({ label, on, onToggle, children }: { label: string; on: boolean; onToggle: () => void; children: ReactNode }) {
|
||||
return (
|
||||
<div className={cx('flex min-h-[44px] flex-wrap items-center gap-2 border-b border-(--line) py-2', !on && 'opacity-60')}>
|
||||
<label className="flex w-[84px] cursor-pointer items-center gap-1.5 text-[14px] font-extrabold">
|
||||
<input type="checkbox" checked={on} onChange={onToggle} className="size-4 accent-(--orange)" />
|
||||
{label}
|
||||
</label>
|
||||
{on ? <div className="flex min-w-0 flex-1 flex-wrap items-center gap-1.5 text-[13.5px] font-bold">{children}</div> : <span className="text-[13px] font-semibold text-(--ink3)">상관없음</span>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Num({ value, onChange, min, max, label }: { value: number; onChange: (v: number) => void; min: number; max: number; label: string }) {
|
||||
return (
|
||||
<input
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
aria-label={label}
|
||||
value={value}
|
||||
min={min}
|
||||
max={max}
|
||||
onChange={(e) => {
|
||||
const v = Number(e.target.value)
|
||||
if (e.target.value !== '' && Number.isFinite(v)) onChange(Math.min(max, Math.max(min, v)))
|
||||
}}
|
||||
className="w-[58px] rounded-xl bg-[#f3f6fb] px-2 py-1.5 text-center tabular-nums"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function Choice<T extends string>({ value, options, onChange, label }: { value: T; options: [T, string][]; onChange: (v: T) => void; label: string }) {
|
||||
return (
|
||||
<span className="flex gap-1" role="radiogroup" aria-label={label}>
|
||||
{options.map(([k, word]) => (
|
||||
<button key={k} type="button" role="radio" aria-checked={value === k} onClick={() => onChange(k)} className={cx('cursor-pointer rounded-full px-3 py-1.5', value === k ? 'bg-(--orange) text-white' : 'bg-[#eef4fc]')}>
|
||||
{word}
|
||||
</button>
|
||||
))}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
type Filled<T> = { [K in keyof T]-?: NonNullable<T[K]> }
|
||||
const DEFAULT_RULE: Filled<MyGakRule> = { temp: [15, 25], rain: 'dry', wind_max: 4, air: 'normal', humidity: [30, 60], slots: ['morning', 'day', 'evening', 'night'] }
|
||||
type Cond = 'temp' | 'rain' | 'wind_max' | 'air' | 'humidity'
|
||||
|
||||
/** 내 각 만들기(이름과 조건)와 미리보기. shared 면 받은 각을 내 동네 점수로 보여 주고 가져오기만 */
|
||||
export function MixSheet({ shared, onDone }: { shared?: MyGak; 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]))
|
||||
const { create, pending, failed } = useMyGak()
|
||||
const [name, setName] = useState(shared?.name ?? '')
|
||||
const [vals, setVals] = useState({ ...DEFAULT_RULE, ...(shared?.rule ?? {}) } as typeof DEFAULT_RULE)
|
||||
const [on, setOn] = useState<Record<Cond, boolean>>(
|
||||
shared ? { temp: !!shared.rule.temp, rain: !!shared.rule.rain, wind_max: shared.rule.wind_max != null, air: !!shared.rule.air, humidity: !!shared.rule.humidity } : { temp: true, rain: true, wind_max: false, air: false, humidity: false },
|
||||
)
|
||||
const set = <K extends keyof typeof vals>(k: K, v: (typeof vals)[K]) => setVals((x) => ({ ...x, [k]: v }))
|
||||
const toggle = (k: Cond) => setOn((x) => ({ ...x, [k]: !x[k] }))
|
||||
const rule: MyGakRule = { slots: vals.slots, ...(Object.fromEntries((Object.keys(on) as Cond[]).filter((k) => on[k]).map((k) => [k, vals[k]])) as Partial<MyGakRule>) }
|
||||
const valid = Object.values(on).some(Boolean) && vals.slots.length > 0 && (!on.temp || vals.temp[0] < vals.temp[1]) && (!on.humidity || vals.humidity[0] < vals.humidity[1])
|
||||
const score = useMyGakScores(valid ? [rule] : []).data?.scores?.[0]
|
||||
const title = gakName(name) || '이름 없는 각'
|
||||
const toggleSlot = (s: Slot) => set('slots', vals.slots.includes(s) ? vals.slots.filter((x) => x !== s) : SLOTS.map(([k]) => k).filter((k) => k === s || vals.slots.includes(k)))
|
||||
|
||||
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>
|
||||
</>
|
||||
{shared ? (
|
||||
<p className="m-0 text-[13px] font-bold text-(--ink2)">친구가 보낸 각이에요. {region.name} 기준 점수예요</p>
|
||||
) : (
|
||||
<label className="block">
|
||||
<span className="font-jua text-[19px]">이름</span>
|
||||
<input value={name} onChange={(e) => setName(e.target.value)} maxLength={11} placeholder="소맥, 야독, 새우깡" className="mt-1.5 w-full rounded-2xl bg-[#f3f6fb] px-3.5 py-2.5 text-[15px]" />
|
||||
</label>
|
||||
)}
|
||||
{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>
|
||||
<fieldset disabled={!!shared} className="m-0 mt-3 border-0 p-0">
|
||||
<legend className="font-jua text-[19px]">조건</legend>
|
||||
<Row label="기온" on={on.temp} onToggle={() => toggle('temp')}>
|
||||
<Num label="최저 기온" value={vals.temp[0]} min={-20} max={40} onChange={(v) => set('temp', [v, vals.temp[1]])} />~
|
||||
<Num label="최고 기온" value={vals.temp[1]} min={-20} max={40} onChange={(v) => set('temp', [vals.temp[0], v])} />° 체감
|
||||
</Row>
|
||||
<Row label="비" on={on.rain} onToggle={() => toggle('rain')}>
|
||||
<Choice label="비" value={vals.rain} onChange={(v) => set('rain', v)} options={[['dry', '안 와야'], ['wet', '와야']]} />
|
||||
</Row>
|
||||
<Row label="바람" on={on.wind_max} onToggle={() => toggle('wind_max')}>
|
||||
초속 <Num label="바람 상한" value={vals.wind_max} min={1} max={20} onChange={(v) => set('wind_max', v)} />m 이하
|
||||
</Row>
|
||||
<Row label="미세먼지" on={on.air} onToggle={() => toggle('air')}>
|
||||
<Choice label="미세먼지" value={vals.air} onChange={(v) => set('air', v)} options={[['good', '좋음만'], ['normal', '보통까지']]} />
|
||||
</Row>
|
||||
<Row label="습도" on={on.humidity} onToggle={() => toggle('humidity')}>
|
||||
<Num label="최저 습도" value={vals.humidity[0]} min={0} max={100} onChange={(v) => set('humidity', [v, vals.humidity[1]])} />~
|
||||
<Num label="최고 습도" value={vals.humidity[1]} min={0} max={100} onChange={(v) => set('humidity', [vals.humidity[0], v])} />%
|
||||
</Row>
|
||||
<div className="flex flex-wrap items-center gap-1.5 py-2.5 text-[13.5px] font-bold">
|
||||
<span className="w-[84px] text-[14px] font-extrabold">시간대</span>
|
||||
{SLOTS.map(([k, word]) => (
|
||||
<button key={k} type="button" aria-pressed={vals.slots.includes(k)} onClick={() => toggleSlot(k)} className={cx('cursor-pointer rounded-full px-3 py-1.5', vals.slots.includes(k) ? 'bg-(--orange) text-white' : 'bg-[#eef4fc]')}>
|
||||
{word}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</fieldset>
|
||||
<div className="mt-2 flex flex-col gap-1.5 rounded-[20px] bg-[#f3f6fb] p-3.5">
|
||||
<div className="flex items-center">
|
||||
<b className="font-jua text-[20px] font-normal">{title}</b>
|
||||
<Score s={valid ? score : undefined} big />
|
||||
</div>
|
||||
{valid ? <Reasons s={score} /> : <p className="m-0 text-[12.5px] font-semibold text-(--ink3)">조건과 시간대를 하나 이상 골라요</p>}
|
||||
</div>
|
||||
{failed && <p className="mt-2 mb-0 text-xs font-bold text-(--heart)">저장하지 못했어요. 이름에 링크나 긴 숫자가 있으면 빼 주세요</p>}
|
||||
<button
|
||||
type="button"
|
||||
disabled={!m || owned || pending}
|
||||
onClick={() => m && create(ids, onDone)}
|
||||
disabled={!valid || !gakName(name) || pending}
|
||||
onClick={() => create({ name, rule }, 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 ? '내 각으로 가져오기' : '내 각으로 만들기'}
|
||||
{shared ? '내 각으로 가져오기' : '내 각으로 저장'}
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user