fix: 히어로를 이전 디자인으로 되돌림, 밤 테마 시트 색, 열흘 날씨 줄 끌어 넘기기, 글자 선택 막기
This commit is contained in:
1 parent
6cc0a4d7b6
commit
b61ed92c54
6 files changed
+180
-99
No files matched your search
@@ -4,7 +4,7 @@ import { useQuery } from '@tanstack/react-query'
|
||||
import { getFeedOptions, getWeatherTodayOptions } from '../api/client/@tanstack/react-query.gen'
|
||||
import type { BandArticle, BandEvent, Hero as HeroData, ResWeatherToday, TopIndex } from '../api/client/types.gen'
|
||||
import { cx } from '../lib/utils'
|
||||
import { cardBg, kindOfHour, kst, type Load, loadOf, MEDALS, type TimeKind, WEEKDAYS } from './lib'
|
||||
import { cardBg, fall, kindOfHour, kst, type Load, loadOf, MEDALS, type TimeKind, WEEKDAYS } from './lib'
|
||||
import { PostCard, PostCardSkel } from './Post'
|
||||
import { useRegion } from './regionContext'
|
||||
import { useSheet } from './sheetContext'
|
||||
@@ -15,7 +15,7 @@ import { deg, skyText, slotAt } from './weatherText'
|
||||
type Mode = 'now' | TimeKind
|
||||
|
||||
const MODES: [Mode, string][] = [
|
||||
['now', '지금'],
|
||||
['now', '지금 시간'],
|
||||
['morning', '아침'],
|
||||
['day', '낮'],
|
||||
['sunset', '저녁'],
|
||||
@@ -30,8 +30,14 @@ const PREVIEW: Record<TimeKind, { label: string; clock: string; hour: number }>
|
||||
night: { label: '밤', clock: '22:10', hour: 22 },
|
||||
}
|
||||
|
||||
// 불쾌지수는 6~9월에만 뜻이 있고, 그 밖엔 늘 '쾌적'이라 하루 최저·최고(일교차)를 보여 준다
|
||||
const isMuggySeason = (month: number) => month >= 6 && month <= 9
|
||||
const STARS = Array.from({ length: 26 }, (_, i) => ({ left: `${(i * 37) % 100}%`, top: `${(i * 53) % 60}%`, opacity: 0.4 + ((i * 7) % 6) / 10 }))
|
||||
// 별똥별 셋: 위치·길이·주기를 엇갈려 하나씩 떨어지게
|
||||
const SHOOTS = [
|
||||
{ top: '6%', left: '80%', '--len': '90px', '--dur': '7s', '--dl': '1.5s' },
|
||||
{ top: '20%', left: '52%', '--len': '70px', '--dur': '9s', '--dl': '4s' },
|
||||
{ top: '34%', left: '94%', '--len': '80px', '--dur': '11s', '--dl': '6.5s' },
|
||||
]
|
||||
const ORB_POS = { left: '66%', top: '6px', d: '.5s', f: '4.4s' }
|
||||
|
||||
function useNow(ms = 20000) {
|
||||
const [now, setNow] = useState(() => new Date())
|
||||
@@ -60,6 +66,8 @@ function heroVal(load: Load, v: ReactNode, skel: string) {
|
||||
)
|
||||
}
|
||||
|
||||
const failed = (load: Load) => load === 'error' || load === 'retrying'
|
||||
|
||||
type HeroProps = { hero?: HeroData | null; today?: ResWeatherToday; feedLoad: Load; todayLoad: Load }
|
||||
|
||||
function Hero({ hero, today, feedLoad, todayLoad }: HeroProps) {
|
||||
@@ -79,82 +87,102 @@ function Hero({ hero, today, feedLoad, todayLoad }: HeroProps) {
|
||||
const temp = mode === 'now' && hero ? hero.temp_c : slot?.temp_c
|
||||
const feels = mode === 'now' && hero ? hero.feels_c : slot?.feels_c
|
||||
const top1 = hero?.top1
|
||||
const who = kind === 'night' ? 'bear' : 'rabbit'
|
||||
const tempLoad = mode === 'now' ? feedLoad : todayLoad
|
||||
const temps = slots.flatMap((s) => (s.temp_c == null ? [] : [s.temp_c]))
|
||||
const muggy = isMuggySeason(t.mo)
|
||||
const feelsLine = temp != null ? `체감 ${deg(feels)}${slot ? ` · ${skyText(slot)}` : ''}` : tempLoad === 'loading' ? null : '체감 ?°'
|
||||
// 1위 각 이름·점수는 바로 아래 '오늘의 각' 줄에 있으니 히어로는 결론 한 줄만
|
||||
const gakLine = hero?.bubble ?? (hero ? '오늘은 쉬어 가요' : null)
|
||||
const feelsLine = temp != null ? `체감 ${deg(feels)}${slot ? ` · ${skyText(slot)}` : ''}` : failed(tempLoad) ? '날씨를 못 불러왔어요' : tempLoad === 'ready' ? '체감 ?°' : null
|
||||
const bubble = hero ? (hero.bubble ?? '오늘은 쉬어 가요') : failed(feedLoad) ? '앗, 날씨를 못 불러왔어요' : null
|
||||
|
||||
// 글자 크기는 64(기온)·40(점수)·16(값)·13(라벨) 네 단계. 모든 값은 한 줄이라 로딩·완료·실패 높이가 같다
|
||||
// 아래 값은 모두 로딩·완료·실패 사이 높이가 같다: 글자 자리 스켈레톤, 비 칸은 두 줄 높이로 고정
|
||||
return (
|
||||
<div className="b-hero mx-3 mt-1 rounded-[28px] px-4 pt-3.5 pb-4" data-t={kind}>
|
||||
<div className="b-seg flex rounded-full p-[3px]" role="group" aria-label="시간대 배경 미리보기">
|
||||
<div className="b-hero relative mx-3 mt-1 overflow-hidden rounded-[32px] px-[18px] pt-4 pb-[18px]" data-t={kind}>
|
||||
<div className="b-stars pointer-events-none absolute inset-0" aria-hidden="true">
|
||||
{STARS.map((s, i) => (
|
||||
<i key={i} className="absolute size-[3px] rounded-full shadow-[0_0_6px_#fff]" style={s} />
|
||||
))}
|
||||
{SHOOTS.map((s, i) => (
|
||||
<span key={i} className="b-shoot" style={s} />
|
||||
))}
|
||||
</div>
|
||||
<div className="relative z-[3] flex flex-wrap gap-1.5" role="group" aria-label="시간대 배경 미리보기">
|
||||
{MODES.map(([m, l]) => (
|
||||
<button key={m} type="button" aria-pressed={mode === m} onClick={() => setMode(m)} className="flex-1 cursor-pointer rounded-full py-1 text-[13px] font-bold">
|
||||
<button key={m} type="button" aria-pressed={mode === m} onClick={() => setMode(m)} className={cx('cursor-pointer rounded-full px-2.5 py-[5px] text-xs font-bold', mode === m ? 'bg-(--ink) text-white' : 'bg-white/55 text-(--ink)')}>
|
||||
{l}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-4 flex items-center justify-between gap-3 px-1">
|
||||
<div className="min-w-0">
|
||||
<p className="text-[13px] font-bold">
|
||||
{t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일 · {mode === 'now' ? `${String(t.h).padStart(2, '0')}:${String(t.mi).padStart(2, '0')}` : `${PREVIEW[mode].label} ${PREVIEW[mode].clock} 예보`}
|
||||
<div className="relative z-[3] mt-3 flex items-end justify-between">
|
||||
<div>
|
||||
<p className="mb-1 text-[13.5px] font-bold opacity-85">
|
||||
{t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일 · {mode === 'now' ? '지금' : `${PREVIEW[mode].label} 미리보기`}
|
||||
</p>
|
||||
<b className="block font-bagel text-[64px] leading-[1.1] font-normal">{heroVal(tempLoad, temp != null ? deg(temp) : null, 'w-[112px]')}</b>
|
||||
<p className="truncate font-jua text-base">{feelsLine ?? <Skel className="w-[112px]" />}</p>
|
||||
<div className="font-bagel text-[60px] leading-none">{mode === 'now' ? `${String(t.h).padStart(2, '0')}:${String(t.mi).padStart(2, '0')}` : PREVIEW[mode].clock}</div>
|
||||
</div>
|
||||
<div className="b-sun b-bob grid size-[112px] shrink-0 place-items-center rounded-full text-center">
|
||||
<span>
|
||||
<b className="block font-bagel text-[40px] leading-[1.1] font-normal">{heroVal(feedLoad, hero?.weather_score, 'w-[52px]')}</b>
|
||||
<small className="block text-[13px] font-bold">날씨 점수</small>
|
||||
</span>
|
||||
<div className="text-right">
|
||||
<b className="block font-bagel text-[42px] leading-none font-normal">{heroVal(tempLoad, temp != null ? deg(temp) : null, 'w-[72px]')}</b>
|
||||
<span className="block text-[12.5px] font-bold opacity-85">{feelsLine ?? <Skel className="w-[118px]" />}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="b-stat mt-4 grid grid-cols-2 rounded-[20px]">
|
||||
<HeroStat icon="umbrella" label="앞으로 2시간">
|
||||
{heroVal(feedLoad, hero?.will_rain_2h == null ? null : hero.will_rain_2h ? '비, 우산 챙겨요' : '비 안 와요', 'w-[72px]')}
|
||||
<div className="relative z-[3] mt-3 grid grid-cols-2 gap-2.5">
|
||||
<HeroStat icon="thermo" label="불쾌지수">
|
||||
{heroVal(feedLoad, hero?.discomfort != null ? `${hero.discomfort} · ${hero.discomfort_label ?? ''}` : null, 'w-16')}
|
||||
</HeroStat>
|
||||
<HeroStat icon="thermo" label={muggy ? '불쾌지수' : '오늘 최저·최고'} className="border-l border-current/10">
|
||||
{muggy
|
||||
? heroVal(feedLoad, hero?.discomfort != null ? `${hero.discomfort} · ${hero.discomfort_label ?? ''}` : null, 'w-[72px]')
|
||||
: heroVal(todayLoad, temps.length ? `${deg(Math.min(...temps))} ~ ${deg(Math.max(...temps))}` : null, 'w-[72px]')}
|
||||
<HeroStat icon="umbrella" label="지금 비">
|
||||
{heroVal(feedLoad, hero?.will_rain_2h == null ? null : hero.will_rain_2h ? '2시간 안에 와요' : '2시간 동안 안 와요', 'w-16')}
|
||||
</HeroStat>
|
||||
</div>
|
||||
<div className="relative mt-5 h-[286px]">
|
||||
<span className="b-cloud b-fall top-6 left-[6%] h-[30px] w-[84px]" style={fall('.1s', '6s')} aria-hidden="true" />
|
||||
<div className="b-sun b-fall absolute top-10 left-1/2 -ml-[82px] grid aspect-square w-[164px] place-items-center rounded-full text-center" style={fall('0s', '5.6s', '8px')}>
|
||||
<span>
|
||||
<b className="block font-bagel text-[56px] leading-[0.9] font-normal">{heroVal(feedLoad, hero?.weather_score, 'w-[84px]')}</b>
|
||||
<small className="mt-0.5 block font-jua text-[14.5px]">{failed(feedLoad) ? '점수를 못 불러왔어요' : '오늘 날씨 점수'}</small>
|
||||
</span>
|
||||
</div>
|
||||
<span className="b-cloud b-fall top-[188px] left-[54%] h-10 w-[118px]" style={fall('.25s', '6.4s')} aria-hidden="true" />
|
||||
{top1 ? (
|
||||
<button type="button" onClick={() => open({ type: 'gak', indexId: top1.index_id })} aria-label={`오늘의 1위 ${top1.name} ${top1.score}점, 계산 근거 보기`} className="col-span-2 flex cursor-pointer items-center gap-2 border-t border-current/10 px-3.5 py-2.5 text-left">
|
||||
<HeroGak line={gakLine} load={feedLoad} />
|
||||
<span className="shrink-0 text-[13px] font-bold opacity-75" aria-hidden="true">
|
||||
근거 보기 ›
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => open({ type: 'gak', indexId: top1.index_id })}
|
||||
aria-label={`1위 ${top1.name} ${top1.score}점, 계산 근거 보기`}
|
||||
className="b-fall absolute z-[2] flex w-24 cursor-pointer flex-col items-center"
|
||||
style={{ left: ORB_POS.left, top: ORB_POS.top, ...fall(ORB_POS.d, ORB_POS.f) }}
|
||||
>
|
||||
<span className="relative w-[78px]">
|
||||
<Ic name={top1.icon} className="w-full drop-shadow-[0_10px_12px_rgb(40_48_74/0.16)]" />
|
||||
<Ic name={MEDALS[0]} className="absolute -top-2 -left-3.5 w-[30px]" />
|
||||
</span>
|
||||
<span className="b-orb-label font-jua text-sm whitespace-nowrap">
|
||||
1위 {top1.name} <em className="font-bagel text-(--orange) not-italic">{top1.score}</em>
|
||||
</span>
|
||||
</button>
|
||||
) : (
|
||||
<div className="col-span-2 flex items-center gap-2 border-t border-current/10 px-3.5 py-2.5">
|
||||
<HeroGak line={gakLine} load={feedLoad} />
|
||||
</div>
|
||||
feedLoad === 'loading' && (
|
||||
<span className="absolute z-[2] flex w-24 flex-col items-center gap-1" style={{ left: ORB_POS.left, top: ORB_POS.top }} aria-hidden="true">
|
||||
<Skel shape className="size-[78px] rounded-full" />
|
||||
<span className="font-jua text-sm">
|
||||
<Skel className="w-[72px]" />
|
||||
</span>
|
||||
</span>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function HeroStat({ icon, label, className, children }: { icon: string; label: string; className?: string; children: ReactNode }) {
|
||||
return (
|
||||
<div className={cx('flex min-w-0 items-center gap-2.5 px-3.5 py-2.5', className)}>
|
||||
<Ic name={icon} className="w-7 shrink-0" />
|
||||
<div className="min-w-0">
|
||||
<small className="block text-[13px] font-bold opacity-75">{label}</small>
|
||||
<b className="block truncate font-jua text-base font-normal">{children}</b>
|
||||
<div className="relative z-[3] flex items-end gap-2">
|
||||
<Ic name={who} alt={who === 'rabbit' ? '토끼' : '곰'} className="w-[50px] drop-shadow-[0_8px_10px_rgb(40_48_74/0.15)]" />
|
||||
<span className="mb-3 rounded-[20px_20px_20px_6px] bg-white px-3.5 py-[9px] font-jua text-base text-(--ink) shadow-[0_8px_16px_rgb(40_48_74/0.1)]">{bubble ?? <Skel className="w-[120px]" />}</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function HeroGak({ line, load }: { line: string | null; load: Load }) {
|
||||
function HeroStat({ icon, label, children }: { icon: string; label: string; children: ReactNode }) {
|
||||
return (
|
||||
<span className="min-w-0 flex-1">
|
||||
<small className="block text-[13px] font-bold opacity-75">오늘의 각</small>
|
||||
<b className="block truncate font-jua text-base font-normal">{heroVal(load, line, 'w-[128px]')}</b>
|
||||
</span>
|
||||
<div className="b-stat flex min-h-[90px] items-center gap-2.5 rounded-[20px] px-3 py-[9px]">
|
||||
<Ic name={icon} className="w-9 shrink-0" />
|
||||
<div className="min-w-0">
|
||||
<small className="block text-xs font-bold opacity-80">{label}</small>
|
||||
<b className="block font-jua text-lg font-normal">{children}</b>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user