feat: 다른 사이트에 붙이는 날씨각 위젯 — 누구나 붙이는 카드(/embed/card, 기본형·상세형, 배경 3종)와 사용 방법 페이지(/widget, 스크립트·iframe 코드)

- 카드: 군산각 카드를 옮겨 그림, 토끼 로딩, 실패하면 '날씨각에서 날씨 보기' 링크, 8초 제한, nginx 대체 화면, '자세히 보기' 버튼만 링크
- 크기: 폭은 자리에 맞춰 자동, 높이는 폭에 따라 비율대로(기본형 245~320px, 상세형 400~520px)
- 부하: 지역별 카드 데이터 5분 저장, 저장분이 비면 지역마다 한 요청만 새로 만듦, 노출 수는 Redis 에 쌓았다가 관리자 조회 때 DB(widget_view_daily)로 옮김
- 사용 방법 페이지: 지역(앱 지역은 바꾸지 않음)·모양·배경 고르기, 미리보기, 코드 복사. 들어오는 길은 문의 창 버튼(토스에서는 숨김)과 검색
- GA: 위젯_안내_보기, 위젯_옵션_고름, 위젯_코드_복사
- 문서: docs/위젯_운영.md, 백엔드 테스트 실행법(CLAUDE.md)
This commit is contained in:
skkim committed 2026-11-26 13:03:29 +09:00
1 parent 1a98adc155
commit dc8201e5f5
38 files changed
+4219 -28

No files matched your search

+69 -23
View File
@@ -1,5 +1,6 @@
import { useInfiniteQuery, useMutation, useQuery, useQueryClient, type InfiniteData } from '@tanstack/react-query'
import { useCallback, useDeferredValue, useEffect, useMemo, useRef, useState, type FormEvent, type ReactNode } from 'react'
import { useLocation, useNavigate } from 'react-router'
import { clearTokens, setTokens, subscribeAuth } from '@nalssigak/shared/api/auth'
import { SITE_URL } from '../api/setup'
import {
@@ -46,7 +47,7 @@ import { WeatherWhySheet } from './weatherWhy'
import { useSky } from './skyContext'
import { LEVELS } from './cloudMerge'
import { SHARE_SIZES, shareImage, type ShareSize } from './storyImage'
import { SheetContext, sheetEntryOnTop, useSheet, type CommentTarget, type SharePayload, type SheetState } from './sheetContext'
import { SheetContext, sheetEntryOnTop, useSheet, type CommentTarget, type RegionPick, type SharePayload, type SheetState } from './sheetContext'
import { HeartIcon } from './svg'
import { MyTalks } from './talk'
import { Avatar, Ic, Skel, StateBox, TAP44, Thumb } from './ui'
@@ -141,7 +142,7 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
}, [isOpen])
const then = shown?.type === 'login' ? shown.then : undefined
const title = !shown ? '' : shown.type === 'gak' ? gakTitle : shown.type === 'article' ? articleTitle || TITLES.article : shown.type === 'mix' ? (shown.shared ? '받은 각' : '내 각 만들기') : shown.type === 'myGak' ? '내 각' : TITLES[shown.type]
const title = !shown ? '' : shown.type === 'gak' ? gakTitle : shown.type === 'article' ? articleTitle || TITLES.article : shown.type === 'mix' ? (shown.shared ? '받은 각' : '내 각 만들기') : shown.type === 'myGak' ? '내 각' : shown.type === 'region' && shown.pick ? '미리 볼 지역 고르기' : TITLES[shown.type]
return (
<dialog
@@ -175,7 +176,7 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
{shown.type === 'comments' && <CommentsSheet to={shown} draft={shown.draft} />}
{shown.type === 'login' && <LoginSheet onDone={onClose} onLoggedIn={then ? () => open(then) : onClose} why={shown.why} />}
{shown.type === 'me' && <MeSheet onDone={onClose} />}
{shown.type === 'region' && <RegionSheet onDone={onClose} />}
{shown.type === 'region' && <RegionSheet onDone={onClose} pick={shown.pick} />}
{shown.type === 'mix' && <MixSheet shared={shown.shared} onDone={onClose} />}
{shown.type === 'myGak' && <MyGakSheet gak={shown.gak} shot={shown.shot} onDone={onClose} />}
{shown.type === 'install' && <InstallSheet />}
@@ -560,9 +561,28 @@ const CONTACTS = [
{ method: 'phone', label: '전화 문의', value: '010-2755-6463', href: 'tel:010-2755-6463', icon: 'M6.6 3h3l1.5 4.2-2 1.5a12 12 0 0 0 6.2 6.2l1.5-2L21 14.4v3A2.6 2.6 0 0 1 18.4 20 15.4 15.4 0 0 1 4 5.6 2.6 2.6 0 0 1 6.6 3Z' },
{ method: 'email', label: '이메일 문의', value: 'sales@o2o.kr', href: 'mailto:sales@o2o.kr', icon: 'M3.5 6.5h17v11h-17zM4 7l8 6.5L20 7' },
] as const
// 창 안의 해: 다른 사이트에 붙이는 날씨 카드
const WIDGET_ICON = 'M5 4.5h14A1.5 1.5 0 0 1 20.5 6v12a1.5 1.5 0 0 1-1.5 1.5H5A1.5 1.5 0 0 1 3.5 18V6A1.5 1.5 0 0 1 5 4.5ZM3.5 8.5h17M14.5 14a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0Z'
/** 오른쪽 아래 문의 버튼으로 여는 창: 운영사 소개와 전화·이메일 */
/** 오른쪽 아래 문의 버튼으로 여는 창: 운영사 소개와 전화·이메일, 날씨 위젯 사용 방법으로 가는 줄(토스 빌드에는 없음) */
function ContactSheet({ onDone }: { onDone: () => void }) {
const navigate = useNavigate()
const { pathname } = useLocation()
// 창이 쌓아 둔 방문 기록을 닫으며 되돌리므로(history.back), 되돌린 뒤(popstate)에 옮겨야 새 주소가 안 지워지고 뒤로 가기가 이 화면으로 온다
const toWidget = () => {
if (pathname === '/widget') {
onDone()
return
}
const go = () => navigate('/widget', { state: { from: 'contact' } })
if (sheetEntryOnTop()) {
window.addEventListener('popstate', go, { once: true })
onDone()
} else {
onDone()
go()
}
}
return (
<Body className="flex flex-col items-center text-center">
<img src="/b/aio2o.png" alt="AIO2O" width={162} height={27} className="mt-1 block h-[27px] w-auto" />
@@ -570,7 +590,7 @@ function ContactSheet({ onDone }: { onDone: () => void }) {
<p className="mt-1.5 mb-0 text-[13.5px] leading-[1.6] font-semibold text-(--ink2)">
날씨에 맞춘 광고, 지역 축제·행사 소개,
<br />
콘텐츠 협업 같은 제휴 문의를 받아요.
날씨 위젯, 콘텐츠 협업 같은 제휴 문의를 받아요.
<br />
전화나 이메일로 편하게 알려 주세요.
</p>
@@ -591,6 +611,20 @@ function ContactSheet({ onDone }: { onDone: () => void }) {
</span>
</a>
))}
{/* 위젯은 다른 사이트에 붙이는 웹 기능이라 토스 미니앱에서는 보이지 않는다 */}
{!IS_TOSS && (
<button type="button" onClick={toWidget} className="flex w-full cursor-pointer items-center gap-3 rounded-[16px] bg-[#f3f6fb] p-3 text-left text-(--ink)">
<span className="b-keep-bg grid size-11 shrink-0 place-items-center rounded-full bg-white text-(--orange)">
<svg viewBox="0 0 24 24" className="size-[22px]" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d={WIDGET_ICON} />
</svg>
</span>
<span className="min-w-0 flex-1 truncate text-[17px] font-extrabold">날씨 위젯 달기</span>
<span className="text-xl text-(--orange)" aria-hidden="true">
›
</span>
</button>
)}
</div>
<p className="mt-3.5 mb-0 text-[12px] font-semibold text-(--ink3)">날씨각은 주식회사 에이아이오투오가 만들어요</p>
<button type="button" onClick={onDone} className="mt-3 w-full cursor-pointer rounded-[14px] bg-(--orange) p-3 text-[15px] font-extrabold text-white">
@@ -1440,8 +1474,10 @@ const pageHref = (code: string) => {
return p ? `/today/${p.path}` : '/'
}
function RegionSheet({ onDone }: { onDone: () => void }) {
/** pick 이 있으면 '고르기만' 모드: 앱 지역을 바꾸지 않고(region_change 도 안 보냄) 고른 지역을 onPick 으로 넘긴다. 위치로 찾기·로그인 줄은 없다 */
function RegionSheet({ onDone, pick }: { onDone: () => void; pick?: RegionPick }) {
const { region, setRegion, locate, locateStatus } = useRegion()
const current = pick ? pick.current : region.code
const { me, logout } = useAuth()
const { open } = useSheet()
const alive = useRef(true)
@@ -1459,12 +1495,16 @@ function RegionSheet({ onDone }: { onDone: () => void }) {
return (
<Body>
<button type="button" onClick={() => locate(() => alive.current && onDone())} disabled={locateStatus === 'locating'} className="w-full cursor-pointer rounded-full bg-(--orange) p-3 font-jua text-[17px] text-white shadow-[inset_0_-5px_0_var(--orange-deep)] disabled:opacity-60">
지금 위치로 찾기
</button>
<p className="mt-2 min-h-5 text-center text-[13px] font-bold text-(--ink2)" aria-live="polite">
{LOCATE_TEXT[locateStatus]}
</p>
{!pick && (
<>
<button type="button" onClick={() => locate(() => alive.current && onDone())} disabled={locateStatus === 'locating'} className="w-full cursor-pointer rounded-full bg-(--orange) p-3 font-jua text-[17px] text-white shadow-[inset_0_-5px_0_var(--orange-deep)] disabled:opacity-60">
지금 위치로 찾기
</button>
<p className="mt-2 min-h-5 text-center text-[13px] font-bold text-(--ink2)" aria-live="polite">
{LOCATE_TEXT[locateStatus]}
</p>
</>
)}
<input value={q} onChange={(e) => setQ(e.target.value)} placeholder="구 이름으로 찾기 (예: 마포)" aria-label="구 이름으로 찾기" className="mt-1 w-full rounded-full border border-[#dfe5ee] bg-[#f7f9fc] px-3.5 py-2.5" />
{listLoad === 'loading' && <RegionsSkel />}
{listLoad !== 'loading' && !regions.length && (listLoad === 'ready' ? <StateBox load={listLoad} empty="찾는 구가 없어요." className="mt-3" /> : <StateBox load={listLoad} onRetry={() => list.refetch()} hold={<RegionsSkel />} className="inset-x-0 top-2 bottom-0" />)}
@@ -1473,27 +1513,33 @@ function RegionSheet({ onDone }: { onDone: () => void }) {
<li key={r.code}>
<a
href={pageHref(r.code)}
aria-current={r.code === region.code ? 'true' : undefined}
aria-current={r.code === current ? 'true' : undefined}
onClick={(e) => {
e.preventDefault()
setRegion(r)
track('region_change', { region_name: r.name, method: 'list' })
if (pick) {
pick.onPick(r)
} else {
setRegion(r)
track('region_change', { region_name: r.name, method: 'list' })
}
onDone()
}}
className={cx('flex w-full cursor-pointer items-center justify-between border-b-[1.5px] border-(--line) px-1 py-3 text-left font-jua text-[17px]', r.code === region.code && 'text-(--orange)')}
className={cx('flex w-full cursor-pointer items-center justify-between border-b-[1.5px] border-(--line) px-1 py-3 text-left font-jua text-[17px]', r.code === current && 'text-(--orange)')}
>
{r.name}
{r.code === region.code && <small className="font-sans text-xs font-extrabold">지금 보는 곳</small>}
{r.code === current && <small className="font-sans text-xs font-extrabold">지금 보는 곳</small>}
</a>
</li>
))}
</ul>
<p className="mt-4 flex items-center justify-center gap-2 text-[13px] font-bold text-(--ink2)">
{me ? `${me.nickname}(으)로 로그인했어요` : '로그인하면 좋아요·댓글을 쓸 수 있어요'}
<button type="button" onClick={me ? logout : () => open({ type: 'login' })} className="cursor-pointer font-extrabold text-(--rain)">
{me ? '로그아웃' : '로그인'}
</button>
</p>
{!pick && (
<p className="mt-4 flex items-center justify-center gap-2 text-[13px] font-bold text-(--ink2)">
{me ? `${me.nickname}(으)로 로그인했어요` : '로그인하면 좋아요·댓글을 쓸 수 있어요'}
<button type="button" onClick={me ? logout : () => open({ type: 'login' })} className="cursor-pointer font-extrabold text-(--rain)">
{me ? '로그아웃' : '로그인'}
</button>
</p>
)}
</Body>
)
}