import React, { useState } from "react"; import { Reference } from "@/utils/global"; import { copyToClipboard, formatReferenceForCopy, formatAllReferencesForCopy, delteIndexUpdateBracketNumbersInDeltaKeepSelection, } from "@/utils/others/quillutils"; //redux import { useAppDispatch, useAppSelector } from "@/app/store"; import { addReferenceRedux, removeReferenceRedux, clearReferencesRedux, } from "@/app/store/slices/authSlice"; 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(""); const [newPublisher, setNewPublisher] = useState(""); const [newUrl, setNewUrl] = useState(""); //redux const dispatch = useAppDispatch(); const references = useAppSelector((state) => state.auth.referencesRedux); 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); handleRemoveReference(index); delteIndexUpdateBracketNumbersInDeltaKeepSelection(editor, index); } const handleAddReference = (newReference: Reference) => { dispatch(addReferenceRedux(newReference)); }; const handleRemoveReference = (index: number) => { dispatch(removeReferenceRedux(index)); }; const handleClearReferences = () => { dispatch(clearReferencesRedux()); }; return (