feat: 히어로 날씨 점수 옆 ? 버튼 — 누르면 비중 막대(칸 넓이=비중, 채운 만큼=얻은 점수)와 조건별 지금 값으로 점수 근거를 보여 주는 창

This commit is contained in:
minaChoi committed 2026-10-21 13:55:15 +09:00
1 parent 8f95519cb6
commit b7d4df4d7a
8 files changed
+190 -6

No files matched your search

+3 -1
View File
@@ -28,6 +28,7 @@ import { ago, ARTICLE_CAT, articleMeta, AVATAR_COLORS, cardBg, CHARACTERS, dateR
import { GoogleButton } from './googleLogin'
import { useInstall, useInstallable } from './install'
import { InstallSheet } from './installBanner'
import { WeatherWhySheet } from './weatherWhy'
import { MixSheet } from './myGak'
import { ownPage, useRegion } from './regionContext'
import { useSky } from './skyContext'
@@ -76,7 +77,7 @@ export function SheetProvider({ children }: { children: ReactNode }) {
)
}
const TITLES = { article: '읽을거리', seasonWeek: '이번 주 특집', share: '보내기', comments: '댓글', login: '로그인', me: '내 정보', region: '지역 바꾸기', install: '홈 화면에 추가' } as const
const TITLES = { article: '읽을거리', seasonWeek: '이번 주 특집', share: '보내기', comments: '댓글', login: '로그인', me: '내 정보', region: '지역 바꾸기', install: '홈 화면에 추가', weatherWhy: '날씨 점수는 이렇게 나와요' } as const
/** 아래에서 올라오는 창: 네이티브 <dialog>라 ESC·포커스 가두기·포커스 되돌리기가 기본으로 된다 */
function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void }) {
@@ -138,6 +139,7 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
{state.type === 'region' && <RegionSheet onDone={onClose} />}
{state.type === 'mix' && <MixSheet shared={state.shared} onDone={onClose} />}
{state.type === 'install' && <InstallSheet />}
{state.type === 'weatherWhy' && <WeatherWhySheet d={state.why} />}
</div>
)}
{!state && <RegionLinks />}
+14
View File
@@ -139,6 +139,10 @@ function Hero({ hero, today, ranked, all, feedLoad, todayLoad }: HeroProps) {
const weather = weatherOf(slotOf(mode))
const slotScore = mode === 'now' ? undefined : hero?.weather_slots?.[SLOT_KEY[mode]]
const score = slotScore ?? hero?.weather_score
// 점수 옆 ? 버튼: 보고 있는 시간대(지금이면 지금 구간)의 날씨 점수 근거
const whyKey = mode === 'now' ? SLOT_KEY[nowKind] : SLOT_KEY[mode]
const why = hero?.weather_why?.[whyKey]
const whyLabel = mode === 'now' || mode === nowKind ? '지금' : PREVIEW[mode].label
const slotTop = mode === 'now' ? undefined : ranked.find((g) => g.active)
const top1 = slotTop ?? hero?.top1
// 저녁(노을)부터는 가운데 동그라미가 오늘 밤 달 모양이 된다
@@ -208,6 +212,16 @@ function Hero({ hero, today, ranked, all, feedLoad, todayLoad }: HeroProps) {
<small className="block font-jua text-[12px]">{failed(feedLoad) ? '점수를 못 불러왔어요' : `${slotScore != null && mode !== 'now' ? PREVIEW[mode].label : '지금'} 날씨 점수`}</small>
<b className="block font-bagel text-[52px] leading-[0.95] font-normal">{heroVal(feedLoad, score, 'w-[84px]')}</b>
</span>
{why && score != null && (
<button
type="button"
onClick={() => open({ type: 'weatherWhy', why: { label: whyLabel, score, why } })}
aria-label={`${whyLabel} 날씨 점수 ${score}점, 어떻게 나왔는지 보기`}
className={cx('absolute right-0 bottom-1 z-[2] grid size-7 cursor-pointer place-items-center rounded-full bg-white font-jua text-[16px] text-(--orange-deep) shadow-[0_2px_6px_rgb(40_48_74/0.25)]', TAP44)}
>
?
</button>
)}
</div>
</div>
<div className="relative z-[3] text-center">
+2
View File
@@ -1,4 +1,5 @@
import type { MyGak } from './myGakState'
import type { WeatherWhyPayload } from './weatherWhy'
import { createContext, use } from 'react'
/** square: 1:1 비율일 때 slides 대신 찍을 틀 (없으면 slides) */
export type SharePayload = { title: string; slides: HTMLElement[]; square?: HTMLElement[] }
@@ -16,6 +17,7 @@ export type SheetState =
| { type: 'region' }
| { type: 'mix'; shared?: MyGak }
| { type: 'install' }
| { type: 'weatherWhy'; why: WeatherWhyPayload }
| null
export type SheetApi = { open: (s: Exclude<SheetState, null>) => void; close: () => void }
+54
View File
@@ -0,0 +1,54 @@
import type { WeatherWhy } from '../api/client/types.gen'
export type WeatherWhyPayload = { label: string; score: number; why: WeatherWhy[] }
// 조건마다 같은 색을 막대 칸과 아래 줄 점에 같이 써서 이어 보이게
const COLOR: Record<string, string> = {
기온: '#ff7a45',
비: '#4f97e3',
햇볕: '#ffb02e',
바람: '#5fb8b0',
습도: '#8e8cf0',
미세먼지: '#b59a86',
}
const colorOf = (label: string) => COLOR[label] ?? '#9aa3b8'
/** 날씨 점수 근거: 비중만큼 나눈 막대(채운 만큼 얻은 점수)와 조건별 지금 값 */
export function WeatherWhySheet({ d }: { d: WeatherWhyPayload }) {
return (
<div className="flex-1 overflow-auto overscroll-contain px-4 pt-4 pb-[18px]">
<p className="m-0 flex items-baseline gap-2">
<b className="font-bagel text-[44px] leading-none font-normal">{d.score}</b>
<span className="font-jua text-[17px] text-(--ink2)">{d.label} 날씨 점수</span>
</p>
<div className="mt-3 flex h-7 gap-[3px] overflow-hidden rounded-[10px]" role="img" aria-label={d.why.map((w) => `${w.label} 비중 ${w.weight}% 중 ${w.score}점`).join(', ')}>
{d.why.map((w) => (
<span key={w.label} className="relative h-full bg-[#eef2f8]" style={{ width: `${w.weight}%` }}>
<span className="absolute inset-y-0 left-0" style={{ width: `${w.score}%`, background: colorOf(w.label) }} />
</span>
))}
</div>
<p className="m-0 mt-1.5 text-[12.5px] font-semibold text-(--ink3)">칸 넓이는 비중, 채운 만큼이 얻은 점수예요</p>
<ul className="m-0 mt-3 flex list-none flex-col gap-1.5 p-0">
{d.why.map((w) => (
<li key={w.label} className="flex items-center gap-3 rounded-2xl bg-[#f5f8fc] px-3.5 py-2.5">
<i className="size-3 shrink-0 rounded-full" style={{ background: colorOf(w.label) }} aria-hidden="true" />
<span className="min-w-0 flex-1">
<b className="block font-jua text-[16px] leading-tight font-normal">
{w.label} <small className="font-sans text-[12px] font-bold text-(--ink3)">비중 {w.weight}%</small>
</b>
<small className="block text-[13px] font-semibold text-(--ink2)">{w.note}</small>
</span>
<b className="font-jua text-[20px] font-normal tabular-nums">{w.score}</b>
</li>
))}
</ul>
<p className="m-0 mt-3 text-[13px] leading-relaxed font-semibold text-(--ink2)">
조건마다 점수를 매겨 비중대로 합쳐요. 유난히 아쉬운 조건이 있으면 조금 더 깎고, 모든 조건이 완벽할 때만 만점이 나와요.
</p>
</div>
)
}