From 0db4b130f0bd53ca49a681028d46055220ed1534 Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Mon, 26 Oct 2026 15:18:45 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=87=BC=EC=B8=A0=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=EC=97=90=EC=84=9C=20=EB=A7=88=EC=9A=B0=EC=8A=A4?= =?UTF-8?q?=EB=A1=9C=20=EB=81=8C=EC=96=B4=20=EB=84=98=EA=B8=B0=EA=B8=B0(?= =?UTF-8?q?=ED=95=9C=20=ED=99=94=EB=A9=B4=2015%=20=EB=84=98=EA=B2=8C=20?= =?UTF-8?q?=EB=81=8C=EB=A9=B4=20=EB=8B=A4=EC=9D=8C=C2=B7=EC=9D=B4=EC=A0=84?= =?UTF-8?q?),=20=EC=98=81=EC=83=81=EC=9D=84=20=EB=88=84=EB=A5=B4=EB=A9=B4?= =?UTF-8?q?=20=EC=9D=BC=EC=8B=9C=EC=A0=95=EC=A7=80=C2=B7=EC=9E=AC=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/b/Shorts.tsx | 59 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) 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')} /> )} +
))}