mirror of
https://github.com/headporter81/ss-front-react.git
synced 2026-12-06 07:41:11 +09:00
- 상세: 파일마다 [받기] (원래 파일명으로 저장) + 크기 표시 - 상세: [수정] → 제목·분류 입력칸 (분류는 기존 목록 자동완성), 저장/취소 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aff5d61aa8
commit
d359c35304
5 files changed
+105
-15
No files matched your search
@@ -301,6 +301,7 @@ export default function BbsTerminal() {
|
||||
<MediaDetail
|
||||
id={state.postId}
|
||||
token={state.token}
|
||||
categories={state.mediaCategories}
|
||||
onError={onApiError}
|
||||
onDeleted={() => dispatch({ screen: "media", rev: state.rev + 1 })}
|
||||
/>
|
||||
|
||||
@@ -1,22 +1,51 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { API_URL, deleteMediaPost, fetchMediaPost } from "../api";
|
||||
import { useEffect, useState, type FormEvent } from "react";
|
||||
import { API_URL, deleteMediaPost, fetchMediaPost, updateMediaPost } from "../api";
|
||||
import type { MediaPost } from "../types";
|
||||
import { bar, STATUS } from "./MediaList";
|
||||
import styles from "./bbs.module.css";
|
||||
|
||||
/** 바이트 → 사람이 읽는 크기 (1536 → "1.5KB") */
|
||||
const formatSize = (bytes: number) => {
|
||||
const units = ["B", "KB", "MB", "GB"];
|
||||
let n = bytes;
|
||||
let i = 0;
|
||||
while (n >= 1024 && i < units.length - 1) {
|
||||
n /= 1024;
|
||||
i++;
|
||||
}
|
||||
return `${i === 0 ? n : n.toFixed(1)}${units[i]}`;
|
||||
};
|
||||
|
||||
/** 자료실 글 보기: 파일마다 <video>/<img>. 파일 주소의 토큰은 1시간 유효 → 오래 열어 두었으면 "L" 후 다시 열기 */
|
||||
interface Props {
|
||||
id: number;
|
||||
token: string;
|
||||
categories: string[]; // 수정 칸 분류 자동완성
|
||||
onError: (e: unknown) => void;
|
||||
onDeleted: () => void; // 삭제 성공 → 목록으로
|
||||
}
|
||||
|
||||
export default function MediaDetail({ id, token, onError, onDeleted }: Props) {
|
||||
export default function MediaDetail({ id, token, categories, onError, onDeleted }: Props) {
|
||||
const [post, setPost] = useState<MediaPost | null>(null);
|
||||
const [confirming, setConfirming] = useState(false); // [삭제] 한 번 누르면 "정말?" 확인 단계
|
||||
const [editing, setEditing] = useState(false); // [수정] 누르면 제목·분류 입력칸으로 바뀜
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
// 목록으로 돌아가면 목록·분류 탭을 다시 불러오므로 바뀐 내용이 그대로 반영됨
|
||||
const save = async (e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
const data = new FormData(e.currentTarget);
|
||||
setBusy(true);
|
||||
try {
|
||||
setPost(await updateMediaPost(token, id, String(data.get("title")).trim(), String(data.get("category")).trim()));
|
||||
setEditing(false);
|
||||
} catch (err) {
|
||||
onError(err);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const remove = async () => {
|
||||
setBusy(true);
|
||||
try {
|
||||
@@ -59,9 +88,35 @@ export default function MediaDetail({ id, token, onError, onDeleted }: Props) {
|
||||
return (
|
||||
<section className={`${styles.win} ${styles.full}`}>
|
||||
<span className={styles.cap}>═ [4] 자료실 ═</span>
|
||||
<div className={styles.postHead}>
|
||||
<span>제목 :</span> {post.title}
|
||||
</div>
|
||||
{editing ? (
|
||||
<form className={styles.loginForm} onSubmit={save}>
|
||||
<label>
|
||||
<span className={styles.num}>제목</span>
|
||||
<input name="title" className={styles.wide} defaultValue={post.title} maxLength={500} required autoFocus />
|
||||
</label>
|
||||
<label>
|
||||
<span className={styles.num}>분류</span>
|
||||
<input name="category" list="media-edit-categories" defaultValue={post.category ?? ""} placeholder="비우면 미분류" maxLength={50} />
|
||||
<datalist id="media-edit-categories">
|
||||
{categories.map((c) => (
|
||||
<option key={c} value={c} />
|
||||
))}
|
||||
</datalist>
|
||||
</label>
|
||||
<span>
|
||||
<button type="submit" disabled={busy}>
|
||||
{busy ? "저장중..." : "저장"}
|
||||
</button>{" "}
|
||||
<button type="button" onClick={() => setEditing(false)} disabled={busy}>
|
||||
취소
|
||||
</button>
|
||||
</span>
|
||||
</form>
|
||||
) : (
|
||||
<div className={styles.postHead}>
|
||||
<span>제목 :</span> {post.title}
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.postHead}>
|
||||
<span>분류:</span> {post.category ?? "미분류"} <span>등록:</span> {post.author} <span>날짜:</span> {post.createdAt.slice(0, 16).replace("T", " ")}{" "}
|
||||
<span>상태:</span> {STATUS[post.status]}
|
||||
@@ -82,14 +137,26 @@ export default function MediaDetail({ id, token, onError, onDeleted }: Props) {
|
||||
if (f.type === "video") return <video key={f.url} src={src} controls preload="metadata" playsInline />;
|
||||
// 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 (
|
||||
<p key={f.url}>
|
||||
<a href={src}>{f.name}</a>
|
||||
</p>
|
||||
);
|
||||
return null; // 그 밖의 파일은 아래 받기 목록에만
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{post.files.length > 0 && (
|
||||
<>
|
||||
<hr className={styles.rule} />
|
||||
{/* &dl=1: 서버가 attachment로 응답 → 재생하지 않고 원래 파일 이름으로 저장 */}
|
||||
<ul className={styles.files}>
|
||||
{post.files.map((f) => (
|
||||
<li key={f.url}>
|
||||
<a className={styles.accent} href={`${API_URL}${f.url}&dl=1`}>
|
||||
[받기]
|
||||
</a>{" "}
|
||||
{f.name} {f.size >= 0 && <span className={styles.dim}>({formatSize(f.size)})</span>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
<hr className={styles.rule} />
|
||||
<div className={styles.footer}>
|
||||
<a className={styles.accent} href={post.sourceUrl} target="_blank" rel="noreferrer">
|
||||
@@ -107,9 +174,16 @@ export default function MediaDetail({ id, token, onError, onDeleted }: Props) {
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<button type="button" className={styles.linkBtn} onClick={() => setConfirming(true)}>
|
||||
[삭제]
|
||||
</button>
|
||||
<>
|
||||
{!editing && (
|
||||
<button type="button" className={styles.linkBtn} onClick={() => setEditing(true)}>
|
||||
[수정]
|
||||
</button>
|
||||
)}{" "}
|
||||
<button type="button" className={styles.linkBtn} onClick={() => setConfirming(true)}>
|
||||
[삭제]
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -101,6 +101,10 @@
|
||||
.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); }
|
||||
/* 자료실 받기 목록 */
|
||||
.files { list-style: none; margin: 0; padding: 0; overflow-wrap: anywhere; }
|
||||
.files a { text-decoration: none; }
|
||||
.files a:hover { color: var(--bbs-highlight); }
|
||||
/* 첨부 이미지(본문이 없을 때): 이중선 액자 + 캡션 */
|
||||
.figure { margin: 1em 0 0; max-width: 60ch; }
|
||||
.figure img { display: block; width: 100%; height: auto; border: 4px double var(--bbs-hi); }
|
||||
|
||||
Reference in new issue
Block a user