fix: 解决vip状态不正确,因为没有使用dispatch
This commit is contained in:
parent
91ab703708
commit
833e2e1b0e
|
@ -24,6 +24,8 @@ import {
|
|||
} from "@/utils/supabase/supabaseutils";
|
||||
//动画
|
||||
import { CSSTransition } from "react-transition-group";
|
||||
import { animated, useSpring } from "@react-spring/web";
|
||||
|
||||
//删除远程论文按钮
|
||||
import ParagraphDeleteButton from "@/components/ParagraphDeleteInterface";
|
||||
//vip充值按钮
|
||||
|
@ -59,22 +61,26 @@ const PaperManagement = () => {
|
|||
}, [supabase]); // 依赖项数组中包含supabase,因为它可能会影响到fetchPapers函数的结果
|
||||
|
||||
//获取用户VIP状态
|
||||
const initFetch = async () => {
|
||||
const initFetchVipStatue = useCallback(async () => {
|
||||
const user = await getUser();
|
||||
if (user && user.id) {
|
||||
const isVip = await fetchUserVipStatus(user.id);
|
||||
console.log("isVip", isVip);
|
||||
setIsVip(isVip);
|
||||
return isVip;
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
initFetch();
|
||||
}, []);
|
||||
}, [supabase]);
|
||||
|
||||
// 使用useEffect在组件挂载后立即获取数据
|
||||
useEffect(() => {
|
||||
fetchPapers();
|
||||
}, [fetchPapers]);
|
||||
const checkAndFetchPapers = async () => {
|
||||
const isVip = await initFetchVipStatue();
|
||||
dispatch(setIsVip(isVip));
|
||||
console.log("isVip in initFetchVipStatue", isVip);
|
||||
if (isVip) {
|
||||
fetchPapers();
|
||||
}
|
||||
};
|
||||
checkAndFetchPapers();
|
||||
}, [supabase]);
|
||||
|
||||
const handlePaperClick = async (paperNumber: string) => {
|
||||
const data = await getUserPaper(userId, paperNumber, supabase); // 假设这个函数异步获取论文内容
|
||||
|
@ -110,6 +116,11 @@ const PaperManagement = () => {
|
|||
await fetchPapers();
|
||||
};
|
||||
|
||||
// const animations = useSpring({
|
||||
// opacity: showPaperManagement ? 1 : 0,
|
||||
// from: { opacity: 0 },
|
||||
// });
|
||||
|
||||
return (
|
||||
<CSSTransition
|
||||
in={showPaperManagement}
|
||||
|
@ -117,6 +128,8 @@ const PaperManagement = () => {
|
|||
classNames="slide"
|
||||
unmountOnExit
|
||||
>
|
||||
{/* showPaperManagement ? ( */}
|
||||
{/* <animated.div style={animations}> */}
|
||||
<>
|
||||
<div className="paper-management-container flex flex-col items-center space-y-4">
|
||||
<div className="max-w-md w-full bg-blue-gray-100 rounded overflow-hidden shadow-lg mx-auto p-5">
|
||||
|
@ -179,6 +192,8 @@ const PaperManagement = () => {
|
|||
)}
|
||||
</div>
|
||||
</>
|
||||
{/* </animated.div>
|
||||
) : null */}
|
||||
</CSSTransition>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import { Reference } from "@/utils/global";
|
||||
import Quill from "quill";
|
||||
import { animated, useSpring } from "@react-spring/web";
|
||||
|
||||
function getTextBeforeCursor(quill, length = 500) {
|
||||
const cursorPosition = quill.getSelection().index;
|
||||
function getTextBeforeCursor(quill: Quill, length = 500) {
|
||||
const cursorPosition = quill.getSelection()!.index;
|
||||
const start = Math.max(0, cursorPosition - length); // 确保开始位置不是负数
|
||||
return quill.getText(start, cursorPosition - start);
|
||||
}
|
||||
|
||||
function getNumberBeforeCursor(quill, length = 3000) {
|
||||
const cursorPosition = quill.getSelection().index;
|
||||
function getNumberBeforeCursor(quill: Quill, length = 3000) {
|
||||
const cursorPosition = quill.getSelection()!.index;
|
||||
const start = Math.max(0, cursorPosition - length); // 确保开始位置不是负数
|
||||
const textBeforeCursor = quill.getText(start, cursorPosition - start);
|
||||
|
||||
|
@ -31,10 +32,10 @@ function getNumberBeforeCursor(quill, length = 3000) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
function updateBracketNumbersInDelta(delta) {
|
||||
function updateBracketNumbersInDelta(delta: any) {
|
||||
let currentNumber = 1;
|
||||
|
||||
const updatedOps = delta.ops.map((op) => {
|
||||
const updatedOps = delta.ops.map((op: any) => {
|
||||
if (typeof op.insert === "string") {
|
||||
return {
|
||||
...op,
|
||||
|
@ -48,9 +49,9 @@ function updateBracketNumbersInDelta(delta) {
|
|||
}
|
||||
|
||||
function deleteReferenceNumberOrParagraph(
|
||||
delta,
|
||||
delta: any,
|
||||
indexToRemove: number,
|
||||
quill,
|
||||
quill: Quill,
|
||||
deleteParagraph: boolean
|
||||
) {
|
||||
const indexStr = `[${indexToRemove + 1}]`;
|
||||
|
@ -63,7 +64,7 @@ function deleteReferenceNumberOrParagraph(
|
|||
let delta = quill.clipboard.convert(htmlString);
|
||||
return delta;
|
||||
} else {
|
||||
const updatedOps = delta.ops.flatMap((op, i) => {
|
||||
const updatedOps = delta.ops.flatMap((op: any, i) => {
|
||||
if (typeof op.insert === "string") {
|
||||
const indexPos = op.insert.indexOf(indexStr);
|
||||
if (indexPos !== -1) {
|
||||
|
@ -131,7 +132,7 @@ function removeParagraphWithReference(
|
|||
);
|
||||
}
|
||||
|
||||
function updateBracketNumbersInDeltaKeepSelection(quill) {
|
||||
function updateBracketNumbersInDeltaKeepSelection(quill: Quill) {
|
||||
const selection = quill.getSelection();
|
||||
const delta = quill.getContents();
|
||||
const updatedDelta = updateBracketNumbersInDelta(delta);
|
||||
|
@ -142,7 +143,7 @@ function updateBracketNumbersInDeltaKeepSelection(quill) {
|
|||
}
|
||||
|
||||
export function delteIndexUpdateBracketNumbersInDeltaKeepSelection(
|
||||
quill,
|
||||
quill: Quill,
|
||||
index: number,
|
||||
rmPg: boolean
|
||||
) {
|
||||
|
@ -161,7 +162,7 @@ export function delteIndexUpdateBracketNumbersInDeltaKeepSelection(
|
|||
}
|
||||
}
|
||||
|
||||
function convertToSuperscript(quill) {
|
||||
function convertToSuperscript(quill: Quill) {
|
||||
const text = quill.getText();
|
||||
const regex = /\[\d+\]/g; // 正则表达式匹配 "[数字]" 格式
|
||||
let match;
|
||||
|
@ -220,7 +221,7 @@ function formatAllReferencesForCopy(references: Reference[]): string {
|
|||
.join("\n");
|
||||
}
|
||||
|
||||
export function formatTextInEditor(editor) {
|
||||
export function formatTextInEditor(editor: Quill) {
|
||||
convertToSuperscript(editor);
|
||||
updateBracketNumbersInDeltaKeepSelection(editor);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user