import React, { useState } from "react"; import { Reference } from "@/utils/global"; import { copyToClipboard, formatReferenceForCopy, formatAllReferencesForCopy, delteIndexUpdateBracketNumbersInDeltaKeepSelection, } from "@/utils/others/quillutils"; //删除文献按钮 import ParagraphDeleteButton from "@/components/ParagraphDeleteInterface"; //redux import { useAppDispatch, useAppSelector } from "@/app/store"; import { addReferenceRedux, removeReferenceRedux, clearReferencesRedux, swapReferencesRedux, } from "@/app/store/slices/authSlice"; type ReferenceListProps = { editor: any; }; function ReferenceList({ editor }: ReferenceListProps) { // console.log("editor in ReferenceList", editor); const [newTitle, setNewTitle] = useState(""); const [newAuthor, setNewAuthor] = useState(""); const [newYear, setNewYear] = useState(""); const [newPublisher, setNewPublisher] = useState(""); const [newUrl, setNewUrl] = useState(""); //redux const dispatch = useAppDispatch(); const references = useAppSelector((state) => state.auth.referencesRedux); function moveReferenceUp(index: number) { console.log("index", index); if (index <= 0 || index >= references.length) { console.log("index", index); return; // Index out of bounds or first element } dispatch(swapReferencesRedux({ indexA: index, indexB: index - 1 })); } function moveReferenceDown(index: number) { console.log("index", index); if (index < 0 || index >= references.length - 1) { console.log("index", index); return; // Index out of bounds or last element } dispatch(swapReferencesRedux({ indexA: index, indexB: index + 1 })); } function removeReferenceUpdateIndex(index: number, rmPg = false) { handleRemoveReference(index); delteIndexUpdateBracketNumbersInDeltaKeepSelection(editor, index, rmPg); } const handleAddReference = (newReference: Reference) => { dispatch(addReferenceRedux(newReference)); }; const handleRemoveReference = (index: number) => { dispatch(removeReferenceRedux(index)); }; const handleClearReferences = () => { dispatch(clearReferencesRedux()); }; return (
{/* 表单区域 */}
{ e.preventDefault(); handleAddReference({ title: newTitle, author: newAuthor, year: newYear, venue: newPublisher, url: newUrl, }); // 清空表单 setNewTitle(""); setNewAuthor(""); setNewYear(""); setNewPublisher(""); setNewUrl(""); }} className="mb-6" >
setNewTitle(e.target.value)} placeholder="Title" /> setNewAuthor(e.target.value)} placeholder="Author" /> setNewYear(e.target.value)} placeholder="Year" /> setNewPublisher(e.target.value)} placeholder="Publisher" /> setNewUrl(e.target.value)} placeholder="URL" />
{/* 引用列表显示区域 */}
); } export default ReferenceList;