This commit is contained in:
root
2026-06-07 19:18:24 +08:00
parent a1daa040ef
commit 32b900547a
16 changed files with 127 additions and 427 deletions

View File

@@ -21,6 +21,7 @@ interface ContentSubmissionModalProps {
open: boolean;
locale: string;
onClose: () => void;
submissionType?: SubmissionType;
}
const MB = 1024 * 1024;
@@ -37,11 +38,20 @@ const EMPTY_FORM: FormState = {
chaptersText: "",
};
export default function ContentSubmissionModal({ open, locale, onClose }: ContentSubmissionModalProps) {
export default function ContentSubmissionModal({ open, locale, onClose, submissionType }: ContentSubmissionModalProps) {
const isZh = locale === "zh";
const copy = useMemo(
() => ({
title: isZh ? "投稿电子书 / 访谈视频" : "Submit ebook / interview",
const initialType = submissionType || "ebook";
const copy = useMemo(() => {
let title = isZh ? "投稿电子书 / 访谈视频" : "Submit ebook / interview";
if (submissionType === "ebook") {
title = isZh ? "投稿电子书" : "Submit ebook";
}
if (submissionType === "video") {
title = isZh ? "投稿访谈视频" : "Submit interview video";
}
return {
title,
close: isZh ? "关闭" : "Close",
ebook: isZh ? "电子书" : "Ebook",
video: isZh ? "访谈视频" : "Interview video",
@@ -66,11 +76,10 @@ export default function ContentSubmissionModal({ open, locale, onClose }: Conten
uploadFailed: isZh ? "上传失败" : "Upload failed",
fileTooLarge: isZh ? "文件过大" : "File too large",
review: isZh ? "状态:待审核" : "Status: pending review",
}),
[isZh]
);
};
}, [isZh, submissionType]);
const [form, setForm] = useState<FormState>(EMPTY_FORM);
const [form, setForm] = useState<FormState>({ ...EMPTY_FORM, type: initialType });
const [uploading, setUploading] = useState<"coverImage" | "mediaUrl" | null>(null);
const [submitting, setSubmitting] = useState(false);
const [message, setMessage] = useState("");
@@ -80,8 +89,9 @@ export default function ContentSubmissionModal({ open, locale, onClose }: Conten
if (open) {
setMessage("");
setError("");
setForm((prev) => ({ ...prev, type: initialType }));
}
}, [open]);
}, [open, initialType]);
if (!open) return null;
@@ -164,7 +174,7 @@ export default function ContentSubmissionModal({ open, locale, onClose }: Conten
}),
});
setMessage(copy.success);
setForm({ ...EMPTY_FORM, type: form.type });
setForm({ ...EMPTY_FORM, type: initialType });
} catch (err) {
setError(err instanceof Error ? err.message : "提交失败");
} finally {
@@ -194,22 +204,24 @@ export default function ContentSubmissionModal({ open, locale, onClose }: Conten
</div>
<form onSubmit={submit} className="space-y-5 px-4 py-5 sm:px-6">
<div className="grid grid-cols-2 gap-2 rounded-lg bg-gray-100 p-1 dark:bg-gray-900">
{(["ebook", "video"] as SubmissionType[]).map((type) => (
<button
key={type}
type="button"
onClick={() => set("type", type)}
className={`rounded-md px-3 py-2 text-sm font-bold transition-colors ${
form.type === type
? "bg-[#ff4d4f] text-white shadow-sm"
: "text-gray-600 hover:bg-white dark:text-gray-300 dark:hover:bg-gray-800"
}`}
>
{type === "ebook" ? copy.ebook : copy.video}
</button>
))}
</div>
{!submissionType && (
<div className="grid grid-cols-2 gap-2 rounded-lg bg-gray-100 p-1 dark:bg-gray-900">
{(["ebook", "video"] as SubmissionType[]).map((type) => (
<button
key={type}
type="button"
onClick={() => set("type", type)}
className={`rounded-md px-3 py-2 text-sm font-bold transition-colors ${
form.type === type
? "bg-[#ff4d4f] text-white shadow-sm"
: "text-gray-600 hover:bg-white dark:text-gray-300 dark:hover:bg-gray-800"
}`}
>
{type === "ebook" ? copy.ebook : copy.video}
</button>
))}
</div>
)}
<div className="grid gap-4 sm:grid-cols-2">
<label className="block">