diff --git a/frontend/src/b/Shorts.tsx b/frontend/src/b/Shorts.tsx index 9a3470c..b4c3e1c 100644 --- a/frontend/src/b/Shorts.tsx +++ b/frontend/src/b/Shorts.tsx @@ -1,5 +1,5 @@ import { useQuery } from '@tanstack/react-query' -import { type CSSProperties, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from 'react' +import { type CSSProperties, type PointerEvent as ReactPointerEvent, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from 'react' import { Link, useNavigate, useParams } from 'react-router' import { listShortsOptions } from '../api/client/@tanstack/react-query.gen' import type { ShortItem } from '../api/client' @@ -140,6 +140,8 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta const frames = useRef(new Map()) const atRef = useRef(start) const soundRef = useRef(false) + // 누르기로 멈춘 상태. 다른 영상으로 넘어가면 다시 재생 중으로 + const paused = useRef(false) // 처음 한 번: 시작 영상으로 맞추고, 뒤 페이지 스크롤을 잠근다 const startRef = useRef(start) @@ -201,6 +203,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta useEffect(() => { if (atRef.current !== at) moved(items[at]) atRef.current = at + paused.current = false for (const [i, f] of frames.current) { if (i === at) { command(f, soundRef.current ? 'unMute' : 'mute') @@ -212,6 +215,46 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta } }, [at, items]) + // 마우스로도 끌어 넘긴다: 영상 위는 유튜브 iframe 이 마우스를 가져가서, 그 위에 투명한 판을 깔고 끈 만큼 목록을 옮긴다. + // 손가락은 브라우저 스크롤에 맡기고, 끌지 않고 누르기만 하면 재생·일시정지 + const drag = useRef<{ y: number; top: number; moved: boolean } | null>(null) + const lastPointer = useRef('') + const [dragging, setDragging] = useState(false) + const togglePause = () => { + paused.current = !paused.current + command(frames.current.get(atRef.current), paused.current ? 'pauseVideo' : 'playVideo') + } + const onPointerDown = (e: ReactPointerEvent) => { + lastPointer.current = e.pointerType + const box = list.current + if (e.pointerType !== 'mouse' || !box) return + e.currentTarget.setPointerCapture(e.pointerId) + drag.current = { y: e.clientY, top: box.scrollTop, moved: false } + setDragging(true) + } + const onPointerMove = (e: ReactPointerEvent) => { + const d = drag.current + const box = list.current + if (!d || !box) return + const dy = e.clientY - d.y + if (Math.abs(dy) > 6) d.moved = true + box.scrollTop = d.top - dy + } + const onPointerUp = (e: ReactPointerEvent) => { + const d = drag.current + const box = list.current + drag.current = null + setDragging(false) + if (!d || !box) return + if (!d.moved) return togglePause() + // 한 화면의 15% 넘게 끌면 다음·이전 영상으로, 아니면 제자리로 + const h = box.clientHeight + const dy = e.clientY - d.y + const base = Math.round(d.top / h) + const target = Math.min(items.length - 1, Math.max(0, base + (dy < -h * 0.15 ? 1 : dy > h * 0.15 ? -1 : 0))) + box.scrollTo({ top: target * h, behavior: 'smooth' }) + } + const toggleSound = () => { const on = !sound soundRef.current = on @@ -244,7 +287,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta {sound ? '소리 끄기' : '소리 켜기'} -
+
{items.map((s, i) => (
@@ -272,6 +315,18 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta className={cx('absolute inset-0 size-full border-0 transition-opacity duration-200', !ready.has(i) && 'opacity-0')} /> )} +
))}