feat : 자료실 글 삭제 버튼 추가 ([삭제] → 확인 → 목록으로)
SpecialSource Frontend (React) CD / deploy (push) Successful in 14s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
headporterandClaude Opus 5.5 committed 2026-11-27 17:09:41 +09:00
1 parent eac57c04e7
commit eaca07da53
4 files changed
+52 -4

No files matched your search

+3
View File
@@ -28,6 +28,9 @@ export const fetchMediaPosts = async (token: string): Promise<MediaPost[]> =>
export const fetchMediaPost = async (token: string, id: number): Promise<MediaPost> => export const fetchMediaPost = async (token: string, id: number): Promise<MediaPost> =>
(await call(`/api/media-posts/${id}`, token)).json(); (await call(`/api/media-posts/${id}`, token)).json();
/** 자료실 글 삭제 (NAS의 파일도 함께 지워짐, 본인 글만) */
export const deleteMediaPost = (token: string, id: number) => call(`/api/media-posts/${id}`, token, { method: "DELETE" });
/** 링크 등록 → 서버가 다운로드 봇에 요청. 다운로드는 뒤에서 진행 (status: DOWNLOADING → DONE/FAILED) */ /** 링크 등록 → 서버가 다운로드 봇에 요청. 다운로드는 뒤에서 진행 (status: DOWNLOADING → DONE/FAILED) */
export const createMediaPost = (token: string, url: string, title: string) => export const createMediaPost = (token: string, url: string, title: string) =>
call("/api/media-posts", token, { call("/api/media-posts", token, {
+6 -1
View File
@@ -286,7 +286,12 @@ export default function BbsTerminal() {
/> />
)} )}
{state.screen === "mediaPost" && state.token && state.postId !== null && ( {state.screen === "mediaPost" && state.token && state.postId !== null && (
<MediaDetail id={state.postId} token={state.token} onError={onApiError} /> <MediaDetail
id={state.postId}
token={state.token}
onError={onApiError}
onDeleted={() => dispatch({ screen: "media", rev: state.rev + 1 })}
/>
)} )}
</div> </div>
</div> </div>
+39 -3
View File
@@ -1,12 +1,33 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { API_URL, fetchMediaPost } from "../api"; import { API_URL, deleteMediaPost, fetchMediaPost } from "../api";
import type { MediaPost } from "../types"; import type { MediaPost } from "../types";
import { STATUS } from "./MediaList"; import { STATUS } from "./MediaList";
import styles from "./bbs.module.css"; import styles from "./bbs.module.css";
/** 자료실 글 보기: 파일마다 <video>/<img>. 파일 주소의 토큰은 1시간 유효 → 오래 열어 두었으면 "L" 후 다시 열기 */ /** 자료실 글 보기: 파일마다 <video>/<img>. 파일 주소의 토큰은 1시간 유효 → 오래 열어 두었으면 "L" 후 다시 열기 */
export default function MediaDetail({ id, token, onError }: { id: number; token: string; onError: (e: unknown) => void }) { interface Props {
id: number;
token: string;
onError: (e: unknown) => void;
onDeleted: () => void; // 삭제 성공 → 목록으로
}
export default function MediaDetail({ id, token, onError, onDeleted }: Props) {
const [post, setPost] = useState<MediaPost | null>(null); const [post, setPost] = useState<MediaPost | null>(null);
const [confirming, setConfirming] = useState(false); // [삭제] 한 번 누르면 "정말?" 확인 단계
const [busy, setBusy] = useState(false);
const remove = async () => {
setBusy(true);
try {
await deleteMediaPost(token, id);
onDeleted();
} catch (e) {
onError(e);
setBusy(false);
setConfirming(false);
}
};
// 받는 중이면 5초마다 다시 조회 → 끝나면 파일이 나타남 // 받는 중이면 5초마다 다시 조회 → 끝나면 파일이 나타남
useEffect(() => { useEffect(() => {
@@ -70,7 +91,22 @@ export default function MediaDetail({ id, token, onError }: { id: number; token:
<a className={styles.accent} href={post.sourceUrl} target="_blank" rel="noreferrer"> <a className={styles.accent} href={post.sourceUrl} target="_blank" rel="noreferrer">
원본 보기 ↗ 원본 보기 ↗
</a>{" "} </a>{" "}
· <b>L</b>=목록 · <b>M</b>=메인 · <b>L</b>=목록 · <b>M</b>=메인 ·{" "}
{confirming ? (
<>
<span className={styles.error}>파일까지 지워집니다. 정말 삭제할까요?</span>{" "}
<button type="button" className={styles.linkBtn} onClick={remove} disabled={busy}>
{busy ? "[삭제중...]" : "[예]"}
</button>{" "}
<button type="button" className={styles.linkBtn} onClick={() => setConfirming(false)} disabled={busy}>
[아니오]
</button>
</>
) : (
<button type="button" className={styles.linkBtn} onClick={() => setConfirming(true)}>
[삭제]
</button>
)}
</div> </div>
</section> </section>
); );
@@ -59,6 +59,10 @@
.rule { border: none; border-top: 1px dashed var(--bbs-dim); margin: 0.6em 0; } .rule { border: none; border-top: 1px dashed var(--bbs-dim); margin: 0.6em 0; }
.footer { color: var(--bbs-dim); margin-top: 0.6em; } .footer { color: var(--bbs-dim); margin-top: 0.6em; }
.footer b { color: var(--bbs-highlight); } .footer b { color: var(--bbs-highlight); }
/* 글자처럼 보이는 버튼 (자료실 [삭제] 등) */
.linkBtn { background: none; border: none; padding: 0; font: inherit; color: var(--bbs-accent); cursor: pointer; }
.linkBtn:hover { color: var(--bbs-highlight); }
.linkBtn:disabled { opacity: 0.5; cursor: wait; }
/* 메인 메뉴: 마우스를 올리면 반전 막대 */ /* 메인 메뉴: 마우스를 올리면 반전 막대 */
.menu { list-style: none; margin: 0; padding: 0; } .menu { list-style: none; margin: 0; padding: 0; }