Merge branch 'main' into feat/app-webview-shell — main 최신 반영(홈 첫 로드 가볍게·쇼츠 미리보기·사이트맵 줄이기·주말 순위 비 상한 등)
This commit is contained in:
commit
2b6657c951
175 files changed
+134
-17
No files matched your search
@@ -75,11 +75,43 @@ function useVisible<T extends Element>(threshold = 0.5) {
|
||||
return [ref, visible] as const
|
||||
}
|
||||
|
||||
/** 오늘 화면 히어로 아래 쇼츠 줄: 첫 카드만 소리 없이 재생, 누르면 쇼츠 페이지(/shorts/영상ID)에서 위아래로 넘겨 본다 */
|
||||
// 마우스를 올릴 수 있는 기기(데스크톱)인지. 터치 기기는 올리기가 없어 첫 터치 뒤 첫 카드를 자동 재생한다
|
||||
const CAN_HOVER = typeof window !== 'undefined' && window.matchMedia('(hover: hover) and (pointer: fine)').matches
|
||||
// 마우스가 줄 위를 지나가기만 할 땐 플레이어를 받지 않게, 이만큼 머물러야 재생한다
|
||||
const HOVER_PLAY_MS = 200
|
||||
|
||||
// scroll 은 넣지 않는다: 브라우저가 스크롤 위치를 되돌릴 때도 나서 조작으로 볼 수 없다
|
||||
const TOUCH_EVENTS = ['pointerdown', 'touchstart', 'keydown'] as const
|
||||
// 한 번 조작했으면 다른 화면에 다녀와도 그대로 둔다
|
||||
let touchedOnce = false
|
||||
|
||||
/** 터치 기기에서 사용자가 화면을 처음 조작(누르기·키)한 뒤부터 true. 유튜브 플레이어(약 850KB)를 첫 화면 로드에서 빼려고 쓴다 */
|
||||
function useTouched(enabled: boolean) {
|
||||
const [touched, setTouched] = useState(touchedOnce)
|
||||
useEffect(() => {
|
||||
if (!enabled || touchedOnce) return
|
||||
const opts = { capture: true, passive: true }
|
||||
const off = () => TOUCH_EVENTS.forEach((t) => window.removeEventListener(t, on, opts))
|
||||
const on = () => {
|
||||
touchedOnce = true
|
||||
setTouched(true)
|
||||
off()
|
||||
}
|
||||
TOUCH_EVENTS.forEach((t) => window.addEventListener(t, on, opts))
|
||||
return off
|
||||
}, [enabled])
|
||||
return touched
|
||||
}
|
||||
|
||||
/**
|
||||
* 오늘 화면 히어로 아래 쇼츠 줄: 누르면 쇼츠 페이지(/shorts/영상ID)에서 위아래로 넘겨 본다.
|
||||
* 줄에서는 소리 없이 미리 보인다 — 데스크톱은 마우스를 올린 카드, 터치 기기는 첫 터치 뒤 첫 카드
|
||||
*/
|
||||
export function ShortsRail() {
|
||||
const q = useQuery(listShortsOptions())
|
||||
const items = q.data?.items ?? []
|
||||
const [ref, visible] = useVisible<HTMLElement>()
|
||||
const touched = useTouched(!CAN_HOVER && !IS_TOSS)
|
||||
|
||||
if (q.isPending) {
|
||||
return (
|
||||
@@ -99,33 +131,62 @@ export function ShortsRail() {
|
||||
<Rail label="쇼츠 목록">
|
||||
{items.map((s, i) => (
|
||||
// 토스 앱 웹뷰는 유튜브 플레이어가 무거워, 줄에선 표지만 보이고 누르면 재생
|
||||
<ShortCard key={s.id} s={s} playing={!IS_TOSS && i === 0 && visible} />
|
||||
<ShortCard key={s.id} s={s} first={i === 0} auto={!IS_TOSS && !CAN_HOVER && i === 0 && visible && touched} />
|
||||
))}
|
||||
</Rail>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function ShortCard({ s, playing }: { s: ShortItem; playing: boolean }) {
|
||||
/** auto: 올리지 않아도 재생 (터치 기기의 첫 카드) */
|
||||
function ShortCard({ s, first, auto }: { s: ShortItem; first: boolean; auto: boolean }) {
|
||||
const [hover, setHover] = useState(false)
|
||||
const hoverTimer = useRef(0)
|
||||
useEffect(() => () => window.clearTimeout(hoverTimer.current), [])
|
||||
const enter = () => {
|
||||
hoverTimer.current = window.setTimeout(() => setHover(true), HOVER_PLAY_MS)
|
||||
}
|
||||
const leave = () => {
|
||||
window.clearTimeout(hoverTimer.current)
|
||||
setHover(false)
|
||||
}
|
||||
const playing = auto || hover
|
||||
// 재생이 시작된 뒤에만 플레이어를 보인다: 자동재생이 막히면(아이폰 절전 등) 유튜브 재생 버튼 대신 표지 그대로
|
||||
const [started, setStarted] = useState(false)
|
||||
const frame = useRef<HTMLIFrameElement>(null)
|
||||
// 플레이어는 반복 재생하며 재생 상태를 여러 번 보내고 마우스도 여러 번 올리므로, 미리보기 이벤트는 카드마다 한 번만
|
||||
const previewSent = useRef(false)
|
||||
useEffect(() => {
|
||||
if (!playing) return
|
||||
const onMessage = (e: MessageEvent) => {
|
||||
if (e.origin !== YT_ORIGIN || typeof e.data !== 'string' || e.source !== frame.current?.contentWindow) return
|
||||
try {
|
||||
if ((JSON.parse(e.data) as { info?: { playerState?: number } }).info?.playerState === PLAYING) setStarted(true)
|
||||
if ((JSON.parse(e.data) as { info?: { playerState?: number } }).info?.playerState !== PLAYING) return
|
||||
setStarted(true)
|
||||
if (previewSent.current) return
|
||||
previewSent.current = true
|
||||
track('shorts_preview', { video_id: s.id, trigger: auto ? 'auto' : 'hover' })
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
window.addEventListener('message', onMessage)
|
||||
return () => window.removeEventListener('message', onMessage)
|
||||
}, [playing])
|
||||
return () => {
|
||||
window.removeEventListener('message', onMessage)
|
||||
// 플레이어를 내렸다 다시 띄우면 첫 장면을 받을 때까지 다시 표지
|
||||
setStarted(false)
|
||||
}
|
||||
}, [playing, auto, s.id])
|
||||
return (
|
||||
<Link to={`/shorts/${s.id}`} aria-label={`${s.title} 보기`} className="relative block aspect-[9/16] w-[120px] cursor-pointer overflow-hidden rounded-xl bg-[#1d2233] p-0 text-left text-white">
|
||||
<img src={`https://i.ytimg.com/vi/${s.id}/hqdefault.jpg`} alt="" loading="lazy" className="absolute inset-0 size-full object-cover" />
|
||||
<Link
|
||||
to={`/shorts/${s.id}`}
|
||||
aria-label={`${s.title} 보기`}
|
||||
onMouseEnter={CAN_HOVER && !IS_TOSS ? enter : undefined}
|
||||
onMouseLeave={CAN_HOVER && !IS_TOSS ? leave : undefined}
|
||||
className="relative block aspect-[9/16] w-[120px] cursor-pointer overflow-hidden rounded-xl bg-[#1d2233] p-0 text-left text-white"
|
||||
>
|
||||
{/* 첫 카드 표지는 첫 화면에서 가장 큰 그림(LCP)이라 미루지 않고 먼저 받는다 */}
|
||||
<img src={`https://i.ytimg.com/vi/${s.id}/hqdefault.jpg`} alt="" loading={first ? 'eager' : 'lazy'} fetchPriority={first ? 'high' : 'auto'} className="absolute inset-0 size-full object-cover" />
|
||||
{playing && (
|
||||
<iframe
|
||||
ref={frame}
|
||||
|
||||
@@ -680,11 +680,15 @@ export function TodayPage() {
|
||||
</>
|
||||
)}
|
||||
{about && (
|
||||
<div
|
||||
data-nosnippet
|
||||
className="mx-4 mt-6 mb-4 text-[13px] leading-relaxed text-(--ink3) [&_a]:underline [&_h1]:mb-1 [&_h1]:text-[15px] [&_h1]:font-bold [&_h1]:text-(--ink2) [&_h2]:mt-4 [&_h2]:mb-1 [&_h2]:text-[14px] [&_h2]:font-bold [&_h2]:text-(--ink2) [&_h3]:mt-2 [&_h3]:font-semibold [&_li]:inline [&_li]:mr-2 [&_p]:my-1 [&_ul]:m-0 [&_ul]:p-0"
|
||||
dangerouslySetInnerHTML={{ __html: about }}
|
||||
/>
|
||||
// 검색으로 들어온 지역 페이지의 소개 글(서버가 채움). 구글이 색인하도록 화면에 남기되, 피드 끝이 길어지지 않게 접어 둔다
|
||||
<details data-nosnippet className="group mx-4 mt-6 mb-4" onToggle={(e) => e.currentTarget.open && track('region_about_open', { region_name: region.name })}>
|
||||
<summary className="flex cursor-pointer list-none items-center gap-2 rounded-xl bg-white/60 px-3 py-2.5 text-[13px] font-bold text-(--ink2) [&::-webkit-details-marker]:hidden">
|
||||
{region.name} 날씨 안내 · 자주 묻는 질문
|
||||
<span aria-hidden="true" className="text-[11px] text-(--ink3) group-open:hidden">펼치기</span>
|
||||
<span aria-hidden="true" className="hidden text-[11px] text-(--ink3) group-open:inline">접기</span>
|
||||
</summary>
|
||||
<div className="mt-2 text-[13px] leading-relaxed text-(--ink3) [&_a]:underline [&_h1]:mb-1 [&_h1]:text-[15px] [&_h1]:font-bold [&_h1]:text-(--ink2) [&_h2]:mt-4 [&_h2]:mb-1 [&_h2]:text-[14px] [&_h2]:font-bold [&_h2]:text-(--ink2) [&_h3]:mt-2 [&_h3]:font-semibold [&_li]:inline [&_li]:mr-2 [&_p]:my-1 [&_ul]:m-0 [&_ul]:p-0" dangerouslySetInnerHTML={{ __html: about }} />
|
||||
</details>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
|
||||
@@ -4,11 +4,14 @@ import { ARTICLE_LABEL } from '@nalssigak/shared/lib'
|
||||
const SHARED = new Set(['bear', 'bike', 'bronze', 'camping', 'carwash', 'chimaek', 'cloud', 'coldwind', 'delivery', 'dog', 'garden', 'glasses', 'gold', 'hiking', 'iced_hot', 'jjamppong', 'laundry', 'letter', 'makeup', 'makgeolli', 'maple', 'moon', 'muggy', 'naengmyeon', 'photo', 'picnic', 'rabbit', 'rain', 'running', 'silver', 'snow', 'stars', 'sun_cloud', 'sun', 'sunset', 'taxi', 'umbrella', 'vent', 'walk', 'yajang', 'baseball', 'study', 'netflix', 'chestnut', 'peanut', 'tangerine', 'sweet_potato', 'fallen_leaf', 'kimchi', 'apple', 'mask', 'golf', 'jipkok', 'fishing', 'drive', 'kite', 'waterplay', 'riverwind', 'trot', 'pajeon', 'bingsu', 'blanket', 'indoordry', 'flower', 'bungeoppang', 'singing_rain', 'hangang', 'themepark', 'date', 'frizz', 'boiler', 'sunscreen', 'mosquito', 'tennis', 'hyodo', 'thanks', 'gift', 'party', 'game', 'selfie', 'sentimental', 'ginkgo', 'top', 'contact'])
|
||||
const OWN = new Set(['fireworks', 'bulb', 'calendar', 'thermo', 'sheaf', 'popup', 'exhibition', 'concert', 'crystal_ball', 'yin_yang', 'tshirt', 'clapper', 'speech', 'droplet', 'leaf', 'rainbow', 'milky_way', 'shooting_star', 'alarm_clock', 'check_mark_button', 'sparkles', 'warning', 'locked', 'money_bag', 'red_heart', 'briefcase', 'spiral_calendar', 'two_hearts', 'sunrise', 'candy', 'lollipop', 'spider', 'spider_web', 'bat', 'ghost', 'skull', 'jack_o_lantern', 'pepero_choco', 'pepero_almond', 'pepero_strawberry', 'pepero_nude', 'pepero_pair', 'pepero_bundle', 'pepero_box', 'pepero_basket', 'xmas_candy_cane', 'xmas_ornament', 'xmas_gingerbread', 'xmas_santa_hat', 'xmas_stocking', 'xmas_wreath', 'xmas_santa', 'christmas_tree', 'pear', 'dango', 'moon_viewing', 'full_moon', 'suneung_pencil', 'suneung_eraser', 'suneung_heatpack', 'suneung_yeot', 'suneung_mochi', 'suneung_lunchbox', 'suneung_ticket', 'suneung_bouquet', 'newyear_popper', 'newyear_pouch', 'newyear_tteokguk', 'newyear_bell', 'newyear_sunset'])
|
||||
|
||||
/** 아이콘 이름 → 파일 경로 (공용 public/icons, B 전용 public/b/icons). 'none'(데이터 없는 칸)은 그림 없음 */
|
||||
/**
|
||||
* 아이콘 이름 → 파일 경로 (공용 public/icons, B 전용 public/b/icons). 'none'(데이터 없는 칸)은 그림 없음.
|
||||
* 웹은 PNG 옆의 WebP 사본을 쓴다 (PNG 의 1/5 크기). 아이콘 PNG 를 추가하거나 바꾸면 `python frontend/scripts/icons_webp.py` 로 WebP 도 만든다
|
||||
*/
|
||||
export function iconSrc(name: string) {
|
||||
if (name === 'none') return null
|
||||
if (OWN.has(name)) return `/b/icons/${name}.png`
|
||||
return `/icons/${SHARED.has(name) ? name : 'sun_cloud'}.png`
|
||||
if (OWN.has(name)) return `/b/icons/${name}.webp`
|
||||
return `/icons/${SHARED.has(name) ? name : 'sun_cloud'}.webp`
|
||||
}
|
||||
|
||||
export const fall = (d: string, f = '4.8s') => ({ '--d': d, '--f': f }) as CSSProperties
|
||||
|
||||
Reference in new issue
Block a user