mirror of
https://github.com/headporter81/ss-front-react.git
synced 2026-12-06 07:41:11 +09:00
feat : 자료실(4번 메뉴) 추가 — 링크 등록 시 영상/이미지 다운로드 후 게시
SpecialSource Frontend (React) CD / deploy (push) Successful in 14s
SpecialSource Frontend (React) CD / deploy (push) Successful in 14s
- 목록: 링크·제목 등록 칸, 받는 중인 글이 있으면 5초마다 자동 새로고침
- 상세: 파일별 <video>/<img> (백엔드가 준 1시간짜리 토큰 주소)
- API 오류 시 서버가 준 이유({"error"})를 팝업에 표시
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ca4df3e9a3
commit
eac57c04e7
8 files changed
+273
-10
No files matched your search
@@ -1,12 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useLayoutEffect, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
||||
import { useCallback, useEffect, useLayoutEffect, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
||||
import { AUTH_KEY, PALETTE_KEY, PALETTES } from "../constants";
|
||||
import { fetchBoards, fetchFeed } from "../api";
|
||||
import { fetchBoards, fetchFeed, fetchMediaPosts } from "../api";
|
||||
import { apiError, execute, initialState, LOGOUT } from "../lib/command";
|
||||
import type { ListKind, Nav, Palette } from "../types";
|
||||
import LoginForm from "./LoginForm";
|
||||
import MainMenu from "./MainMenu";
|
||||
import MediaDetail from "./MediaDetail";
|
||||
import MediaList from "./MediaList";
|
||||
import PostDetail from "./PostDetail";
|
||||
import PostList from "./PostList";
|
||||
import styles from "./bbs.module.css";
|
||||
@@ -97,6 +99,28 @@ export default function BbsTerminal() {
|
||||
};
|
||||
}, [feedKind, feedBoard, state.token, state.rev]);
|
||||
|
||||
// 자료실 목록: 들어오거나 "L"을 누르면 다시 불러옴. 받는 중인 글이 있으면 5초마다 다시 불러와 상태 갱신
|
||||
const onApiError = useCallback((e: unknown) => dispatch(apiError(e)), []);
|
||||
useEffect(() => {
|
||||
if (state.screen !== "media" || !state.token) return;
|
||||
const token = state.token;
|
||||
let stale = false;
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
const load = () =>
|
||||
fetchMediaPosts(token)
|
||||
.then((media) => {
|
||||
if (stale) return;
|
||||
dispatch({ media });
|
||||
if (media.some((p) => p.status === "DOWNLOADING")) timer = setTimeout(load, 5000);
|
||||
})
|
||||
.catch((e) => !stale && onApiError(e));
|
||||
load();
|
||||
return () => {
|
||||
stale = true;
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [state.screen, state.token, state.rev, onApiError]);
|
||||
|
||||
// 오류·안내 메시지가 생기면 팝업으로 띄우고, 다른 경로로 지워지면 닫음
|
||||
const dialogRef = useRef<HTMLDialogElement>(null);
|
||||
useEffect(() => {
|
||||
@@ -201,7 +225,7 @@ export default function BbsTerminal() {
|
||||
ref={screenRef}
|
||||
className={styles.screen}
|
||||
onScroll={(e) => {
|
||||
if (state.screen !== "post") scrollPos.current[scrollKey] = e.currentTarget.scrollTop;
|
||||
if (state.screen !== "post" && state.screen !== "mediaPost") scrollPos.current[scrollKey] = e.currentTarget.scrollTop;
|
||||
}}
|
||||
onTouchStart={(e) => {
|
||||
const t = e.touches[0];
|
||||
@@ -252,6 +276,18 @@ export default function BbsTerminal() {
|
||||
{state.screen === "post" && state.token && (
|
||||
<PostDetail post={state.feed?.posts.find((p) => p.id === state.postId)} token={state.token} />
|
||||
)}
|
||||
{state.screen === "media" && (
|
||||
<MediaList
|
||||
posts={state.media}
|
||||
token={state.token}
|
||||
onSelect={submitFromClick}
|
||||
onCreated={() => dispatch({ rev: state.rev + 1 })}
|
||||
onError={onApiError}
|
||||
/>
|
||||
)}
|
||||
{state.screen === "mediaPost" && state.token && state.postId !== null && (
|
||||
<MediaDetail id={state.postId} token={state.token} onError={onApiError} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user