feat: 히어로 공유 이미지를 하루 띠로 — 아침·낮·저녁·밤 네 줄(그 시간대 하늘·날씨·기온·날씨 점수·1등 각, 지금 표시), 1:1은 2×2 칸

This commit is contained in:
minaChoi committed 2026-10-21 13:33:54 +09:00
1 parent 8b487b7030
commit b5c280ca3c
4 files changed
+91 -62

No files matched your search

+2 -2
View File
@@ -532,7 +532,7 @@ function ShareSheet({ share }: { share: SharePayload }) {
if (images[size] || failed[size]) return
let alive = true
const today = new Date().toLocaleDateString('ko-KR', { month: 'long', day: 'numeric', weekday: 'long' })
shareImage(share.slides, { size, sky: kind, sub: `${region.name} · ${today}`, host: new URL(SITE_URL).host }).then(
shareImage(size === 'square' && share.square ? share.square : share.slides, { size, sky: kind, sub: `${region.name} · ${today}`, host: new URL(SITE_URL).host }).then(
(blob) => {
if (!alive) return
const src = URL.createObjectURL(blob)
@@ -547,7 +547,7 @@ function ShareSheet({ share }: { share: SharePayload }) {
return () => {
alive = false
}
}, [size, images, failed, share.slides, kind, region.name])
}, [size, images, failed, share.slides, share.square, kind, region.name])
useEffect(() => {
const list = srcs.current
+24 -21
View File
@@ -15,7 +15,7 @@ import { useFeedTalks } from './talkState'
import { useRegion } from './regionContext'
import { useSheet } from './sheetContext'
import { useSky } from './skyContext'
import { GakShareCard, HeroShareCard, type HeroShare } from './shareCards'
import { DayShareCard, DayShareGrid, GakShareCard, type DayShare } from './shareCards'
import { SendIcon } from './svg'
import { Ic, Rail, Sec, Skel, StateBox, TAP44, Thumb } from './ui'
import { deg, slotAt } from './weatherText'
@@ -86,7 +86,7 @@ function atSlot(items: TopIndex[], kind: TimeKind | null): TopIndex[] {
]
}
type HeroProps = { hero?: HeroData | null; today?: ResWeatherToday; ranked: TopIndex[]; feedLoad: Load; todayLoad: Load }
type HeroProps = { hero?: HeroData | null; today?: ResWeatherToday; ranked: TopIndex[]; all: TopIndex[]; feedLoad: Load; todayLoad: Load }
type Weather = 'clear' | 'partly' | 'cloudy' | 'rain' | 'snow' | 'sleet'
@@ -108,11 +108,13 @@ const CLOUDS = [
]
const CLOUD_N: Record<Weather, number> = { clear: 0, partly: 2, cloudy: 3, rain: 3, snow: 3, sleet: 3 }
function Hero({ hero, today, ranked, feedLoad, todayLoad }: HeroProps) {
function Hero({ hero, today, ranked, all, feedLoad, todayLoad }: HeroProps) {
const { open } = useSheet()
const { region } = useRegion()
const tplRef = useRef<HTMLDivElement>(null)
const share = () => tplRef.current && open({ type: 'share', share: { title: `${region.name} 오늘 날씨`, slides: [tplRef.current] } })
const gridRef = useRef<HTMLDivElement>(null)
const share = () =>
tplRef.current && open({ type: 'share', share: { title: `${region.name} 오늘 날씨`, slides: [tplRef.current], square: gridRef.current ? [gridRef.current] : undefined } })
const { preview, setServerKind, setPreview } = useSky()
const mode: Mode = preview ?? 'now'
const clock = useNow()
@@ -148,26 +150,27 @@ function Hero({ hero, today, ranked, feedLoad, todayLoad }: HeroProps) {
const rain = weather === 'rain' || weather === 'sleet'
const snow = weather === 'snow' || weather === 'sleet'
const shareData: HeroShare = {
kind,
sky: weather,
date: `${t.mo}월 ${t.d}일 ${WEEKDAYS[t.wd]}요일`,
place: region.name,
label: `${slotScore != null && mode !== 'now' ? PREVIEW[mode].label : '지금'} 날씨 점수`,
score,
bubble,
summary: top1?.summary,
status: status.map((x) => ({ label: x.label, value: x.value, warn: x.tone === 'warn' })),
slots: KINDS.map((k) => {
const s = slotOf(k === nowKind ? 'now' : k)
return { label: k === nowKind ? '지금' : PREVIEW[k].label, icon: k === 'night' && weatherOf(s) === 'clear' ? 'moon' : WEATHER_ICON[weatherOf(s)], temp: s?.temp_c != null ? deg(s.temp_c) : '–', on: k === kind }
}),
}
// 공유 이미지: 아침~밤 네 시간대 모두. 점수는 시간대 점수, 각은 그 시간대 1등
const days: DayShare[] = KINDS.map((k) => {
const isNow = k === nowKind
const s = slotOf(isNow ? 'now' : k)
const top = atSlot(all, k).find((g) => g.active)
return {
kind: k,
label: PREVIEW[k].label,
now: isNow,
icon: k === 'night' && weatherOf(s) === 'clear' ? 'moon' : WEATHER_ICON[weatherOf(s)],
temp: s?.temp_c != null ? deg(s.temp_c) : '–',
score: hero?.weather_slots?.[SLOT_KEY[k]] ?? (isNow ? hero?.weather_score : null),
gak: top ? { name: top.name, icon: top.icon } : null,
}
})
// 시안 D4-2: 가운데 해(점수)와 하늘 날씨, 결론 두 줄, 상태 한 줄, 아래 하루 흐름 칸(누르면 그 시간대 하늘로)
return (
<div className="b-hero relative mx-3 mt-1 overflow-hidden rounded-[28px] px-4 pt-3 pb-3" data-t={kind} data-sky={weather}>
<HeroShareCard d={shareData} ref={tplRef} />
<DayShareCard days={days} ref={tplRef} />
<DayShareGrid days={days} ref={gridRef} />
<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} />
@@ -388,7 +391,7 @@ export function TodayPage() {
return (
// 피드 칸은 전국 공통이라 지역이 바뀌어도 글 번호가 같다. 지역마다 새로 그려 넘긴 슬라이드·펼친 상태가 남지 않게 한다
<section key={region.code} aria-label="오늘" aria-busy={load === 'loading'} className={cx('transition-opacity', feed.isPlaceholderData && 'opacity-60')}>
<Hero hero={f?.hero} today={today.data} ranked={stories} feedLoad={load} todayLoad={loadOf(today)} />
<Hero hero={f?.hero} today={today.data} ranked={stories} all={f?.stories ?? []} feedLoad={load} todayLoad={loadOf(today)} />
<FeedComposer onPosted={(t) => setMine((m) => [t, ...m])} />
{mine.map((t) => (
<TalkCard key={t.talk_id} t={t} />
+63 -38
View File
@@ -1,8 +1,7 @@
import type { Ref } from 'react'
import { createPortal } from 'react-dom'
import type { TopIndex } from '../api/client/types.gen'
import { cx } from '../lib/utils'
import { MEDALS } from './lib'
import { MEDALS, type TimeKind } from './lib'
import { Ic } from './ui'
/** 공유 이미지 전용 틀. 화면 밖에 그려 두고 보내기 때 이것만 찍는다 (화면의 버튼은 이미지에서 빠지므로 글자만으로 만든다) */
@@ -15,50 +14,76 @@ function Offscreen({ children }: { children: React.ReactNode }) {
)
}
export type HeroShare = {
kind: string
sky: string
date: string
place: string
export type DayShare = {
kind: TimeKind
label: string
now: boolean
icon: string
temp: string
score?: number | null
bubble?: string | null
summary?: string | null
status: { label: string; value: string; warn: boolean }[]
slots: { label: string; icon: string; temp: string; on: boolean }[]
gak?: { name: string; icon: string } | null
}
export function HeroShareCard({ d, ref }: { d: HeroShare; ref: Ref<HTMLDivElement> }) {
function DayLabel({ d }: { d: DayShare }) {
return (
<span className="flex items-center gap-1.5 font-jua text-[20px]">
{d.label}
{d.now && <small className="rounded-full bg-[#ff7a45] px-1.5 py-px font-sans text-[11px] font-extrabold text-white">지금</small>}
</span>
)
}
/** 히어로 공유: 아침·낮·저녁·밤 네 줄. 줄마다 그 시간대 하늘에 날씨·기온, 날씨 점수, 그 시간 1등 각. 로고·지역·날짜는 공유 틀이 그린다 */
export function DayShareCard({ days, ref }: { days: DayShare[]; ref: Ref<HTMLDivElement> }) {
return (
<Offscreen>
<div ref={ref} className="b-hero relative flex aspect-[4/5] flex-col overflow-hidden px-5 pt-5 pb-4 text-center" data-t={d.kind} data-sky={d.sky}>
<p className="m-0 text-left text-[14px] font-bold opacity-80">
{d.date} · {d.place}
</p>
<div className="b-sun mx-auto mt-5 grid aspect-square w-36 place-items-center rounded-full">
<span>
<small className="block font-jua text-[13px]">{d.label}</small>
<b className="block font-bagel text-[58px] leading-[0.95] font-normal">{d.score ?? '–'}</b>
</span>
</div>
<p className="m-0 mt-4 font-jua text-[26px] leading-tight">{d.bubble}</p>
{d.summary && <p className="m-0 mt-1 text-[15px] font-bold opacity-80">{d.summary}</p>}
<p className="m-0 mt-2 flex flex-wrap justify-center gap-x-2 font-jua text-[14px]">
{d.status.map((x) => (
<span key={x.label} className={cx('whitespace-nowrap', x.warn && 'b-warn')}>
<span className="opacity-75">{x.label}</span> {x.value}
<div ref={ref} className="flex aspect-[4/5] flex-col">
{days.map((d) => (
<div key={d.kind} className="b-hero grid flex-1 grid-cols-[76px_64px_1fr_auto] items-center gap-2 px-5" data-t={d.kind}>
<DayLabel d={d} />
<span className="flex flex-col items-center">
<Ic name={d.icon} className="h-8 w-8 object-contain" />
<b className="font-jua text-[17px] font-normal">{d.temp}</b>
</span>
))}
</p>
<div className="b-strip mt-auto grid grid-cols-4 gap-1 rounded-[18px] p-[3px]">
{d.slots.map((s) => (
<span key={s.label} className={cx('flex flex-col items-center rounded-[14px] py-1.5', s.on && 'b-strip-on')}>
<span className="text-[13px] font-bold opacity-80">{s.label}</span>
<Ic name={s.icon} className="my-0.5 h-[22px] w-[22px] object-contain" />
<b className="font-jua text-[15px] font-normal">{s.temp}</b>
<span className="flex min-w-0 items-center gap-1.5">
{d.gak && <Ic name={d.gak.icon} className="w-7 shrink-0" />}
<b className="truncate font-jua text-[18px] font-normal">{d.gak?.name ?? '쉬어 가요'}</b>
</span>
))}
</div>
<span className="text-right">
<b className="block font-bagel text-[40px] leading-none font-normal">{d.score ?? '–'}</b>
<small className="text-[11px] font-bold opacity-75">날씨 점수</small>
</span>
</div>
))}
</div>
</Offscreen>
)
}
/** 1:1 공유용: 같은 내용을 2×2 칸으로 */
export function DayShareGrid({ days, ref }: { days: DayShare[]; ref: Ref<HTMLDivElement> }) {
return (
<Offscreen>
<div ref={ref} className="grid aspect-square grid-cols-2 grid-rows-2">
{days.map((d) => (
<div key={d.kind} className="b-hero flex flex-col justify-between p-4" data-t={d.kind}>
<span className="flex items-center justify-between">
<DayLabel d={d} />
<span className="flex items-center gap-1 font-jua text-[16px]">
<Ic name={d.icon} className="h-6 w-6 object-contain" />
{d.temp}
</span>
</span>
<span className="flex items-end gap-1.5">
<b className="font-bagel text-[48px] leading-none font-normal">{d.score ?? '–'}</b>
<small className="pb-1 text-[11px] font-bold opacity-75">날씨 점수</small>
</span>
<span className="flex min-w-0 items-center gap-1.5">
{d.gak && <Ic name={d.gak.icon} className="w-6 shrink-0" />}
<b className="truncate font-jua text-[16px] font-normal">{d.gak?.name ?? '쉬어 가요'}</b>
</span>
</div>
))}
</div>
</Offscreen>
)
+2 -1
View File
@@ -1,6 +1,7 @@
import type { MyGak } from './myGakState'
import { createContext, use } from 'react'
export type SharePayload = { title: string; slides: HTMLElement[] }
/** square: 1:1 비율일 때 slides 대신 찍을 틀 (없으면 slides) */
export type SharePayload = { title: string; slides: HTMLElement[]; square?: HTMLElement[] }
type CommentsState = { type: 'comments'; postId: number; draft?: string }