mirror of
https://github.com/headporter81/ss-front-react.git
synced 2026-12-06 07:41:11 +09:00
feat : 자료실 영상 자동 재생·반복, 2배속 버튼, 더블 탭 5초 넘기기, 학습노트 20~22
SpecialSource Frontend (React) CD / deploy (push) Successful in 15s
SpecialSource Frontend (React) CD / deploy (push) Successful in 15s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7b4981ca9a
commit
dbaedafb0b
3 files changed
+117
-2
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState, type FormEvent } from "react";
|
||||
import { useEffect, useRef, useState, type FormEvent, type TouchEvent } from "react";
|
||||
import { API_URL, deleteMediaPost, fetchMediaPost, updateMediaPost } from "../api";
|
||||
import type { MediaPost } from "../types";
|
||||
import { bar, STATUS } from "./MediaList";
|
||||
@@ -16,6 +16,38 @@ const formatSize = (bytes: number) => {
|
||||
return `${i === 0 ? n : n.toFixed(1)}${units[i]}`;
|
||||
};
|
||||
|
||||
/** 모바일 더블 탭: 화면 왼쪽 절반 = 5초 뒤로, 오른쪽 절반 = 5초 앞으로 (아래쪽 재생 버튼 줄은 제외) */
|
||||
const seekOnDoubleTap = (e: TouchEvent<HTMLVideoElement>) => {
|
||||
const v = e.currentTarget;
|
||||
const touch = e.changedTouches[0];
|
||||
const rect = v.getBoundingClientRect();
|
||||
if (touch.clientY > rect.bottom - 60) return; // 컨트롤 바 연타는 무시
|
||||
const last = Number(v.dataset.lastTap ?? 0);
|
||||
v.dataset.lastTap = String(e.timeStamp);
|
||||
if (e.timeStamp - last > 300) return; // 첫 번째 탭
|
||||
e.preventDefault(); // 브라우저 기본 더블 탭 동작(확대·전체화면 등) 막기
|
||||
v.dataset.lastTap = "0"; // 세 번 연타가 두 번 넘기지 않게
|
||||
v.currentTime = Math.max(0, v.currentTime + (touch.clientX - rect.left < rect.width / 2 ? -5 : 5));
|
||||
};
|
||||
|
||||
/** 영상 + 오른쪽 위 2배속 버튼 (누를 때마다 1x ↔ 2x). 전체화면에서는 버튼이 안 보임 → 브라우저 ⋮ 메뉴 사용 */
|
||||
const Video = ({ src, autoPlay }: { src: string; autoPlay: boolean }) => {
|
||||
const ref = useRef<HTMLVideoElement>(null);
|
||||
const [fast, setFast] = useState(false);
|
||||
const toggle = () => {
|
||||
if (ref.current) ref.current.playbackRate = fast ? 1 : 2;
|
||||
setFast(!fast);
|
||||
};
|
||||
return (
|
||||
<div className={styles.videoBox}>
|
||||
<video ref={ref} src={src} controls preload="metadata" playsInline loop autoPlay={autoPlay} onTouchEnd={seekOnDoubleTap} />
|
||||
<button type="button" className={styles.speed} onClick={toggle} aria-pressed={fast}>
|
||||
{fast ? "2x" : "1x"}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/** 자료실 글 보기: 파일마다 <video>/<img>. 파일 주소의 토큰은 1시간 유효 → 오래 열어 두었으면 "L" 후 다시 열기 */
|
||||
interface Props {
|
||||
id: number;
|
||||
@@ -143,7 +175,10 @@ export default function MediaDetail({ id, token, categories, onError, onDeleted,
|
||||
<div className={styles.html}>
|
||||
{post.files.map((f) => {
|
||||
const src = API_URL + f.url;
|
||||
if (f.type === "video") return <video key={f.url} src={src} controls preload="metadata" playsInline />;
|
||||
// 첫 영상만 자동 재생 (여러 개가 한꺼번에 소리 나지 않게), 끝나면 처음부터 반복
|
||||
const first = f === post.files.find((x) => x.type === "video");
|
||||
if (f.type === "video")
|
||||
return <Video key={f.url} src={src} autoPlay={first} />;
|
||||
// eslint-disable-next-line @next/next/no-img-element -- 정적 export라 next/image 최적화 불가
|
||||
if (f.type === "image") return <img key={f.url} src={src} alt={f.name} loading="lazy" />;
|
||||
return null; // 그 밖의 파일은 아래 받기 목록에만
|
||||
|
||||
@@ -109,6 +109,11 @@
|
||||
.html p { margin: 0 0 0.6em; }
|
||||
.html a { color: var(--bbs-accent); }
|
||||
.html img, .html video, .html iframe { display: block; max-width: min(100%, 60ch); height: auto; margin: 0.6em 0; border: 4px double var(--bbs-hi); }
|
||||
/* 자료실 영상 + 2배속 버튼 (영상 오른쪽 위에 겹쳐 띄움) */
|
||||
.videoBox { position: relative; width: fit-content; max-width: 100%; margin: 0.6em 0; }
|
||||
.videoBox video { margin: 0; }
|
||||
.speed { position: absolute; top: 8px; right: 8px; padding: 0 6px; font: inherit; color: var(--bbs-hi); background: rgb(0 0 0 / 0.6); border: 1px solid var(--bbs-hi); cursor: pointer; }
|
||||
.speed[aria-pressed="true"] { color: var(--bbs-highlight); border-color: var(--bbs-highlight); }
|
||||
/* 자료실 받기 목록 */
|
||||
.files { list-style: none; margin: 0; padding: 0; overflow-wrap: anywhere; }
|
||||
.files a { text-decoration: none; }
|
||||
|
||||
Reference in new issue
Block a user