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 (