import React, { useState } from "react"; import { Reference } from "@/utils/global"; import { copyToClipboard, formatReferenceForCopy, formatAllReferencesForCopy, delteIndexUpdateBracketNumbersInDeltaKeepSelection, } from "@/utils/others/quillutils"; type ReferenceListProps = { references: Reference[]; addReference: (reference: Reference) => void; removeReference: (index: number) => void; setReferences: any; editor: any; }; function ReferenceList({ references, addReference, removeReference, setReferences, editor, }: ReferenceListProps) { const [newTitle, setNewTitle] = useState(""); const [newAuthor, setNewAuthor] = useState(""); const [newYear, setNewYear] = useState(2020); const [newPublisher, setNewPublisher] = useState(""); const [newUrl, setNewUrl] = useState(""); function moveReferenceUp(index: number) { setReferences((prevReferences) => { if (index === 0) return prevReferences; // 如果是第一个元素,不进行操作 const newReferences = [...prevReferences]; const temp = newReferences[index]; newReferences[index] = newReferences[index - 1]; newReferences[index - 1] = temp; console.log("moveReferenceUp", newReferences); // 调试输出 return newReferences; }); } function moveReferenceDown(index: number) { setReferences((prevReferences) => { if (index === prevReferences.length - 1) return prevReferences; // 如果是最后一个元素,不进行操作 const newReferences = [...prevReferences]; const temp = newReferences[index]; newReferences[index] = newReferences[index + 1]; newReferences[index + 1] = temp; console.log("moveReferenceDown", newReferences); // 调试输出 return newReferences; }); } function removeReferenceUpdateIndex(index: number) { removeReference(index); delteIndexUpdateBracketNumbersInDeltaKeepSelection(editor, index); } return (
{/* 表单区域 */}
{ e.preventDefault(); addReference({ title: newTitle, author: newAuthor, year: newYear, venue: newPublisher, url: newUrl, }); // 清空表单 setNewTitle(""); setNewAuthor(""); setNewYear(2020); setNewPublisher(""); setNewUrl(""); }} className="mb-6" >
setNewTitle(e.target.value)} placeholder="Title" /> setNewAuthor(e.target.value)} placeholder="Author" /> setNewYear(parseInt(e.target.value))} placeholder="Year" /> setNewPublisher(e.target.value)} placeholder="Publisher" /> setNewUrl(e.target.value)} placeholder="URL" />
{/* 引用列表显示区域 */}
); } export default ReferenceList;