From bcb72c8f7d8c5231db54f9325070b0a04cb54ec5 Mon Sep 17 00:00:00 2001 From: Ethan Liu Date: Sat, 19 Aug 2023 23:07:09 +0800 Subject: [PATCH] fix: fix sync bug --- src/components/backup/modalContent.tsx | 29 ++++++++++++++++---------- src/utils/constant/price.ts | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/components/backup/modalContent.tsx b/src/components/backup/modalContent.tsx index df0d6da..c9a36be 100644 --- a/src/components/backup/modalContent.tsx +++ b/src/components/backup/modalContent.tsx @@ -7,8 +7,9 @@ import { useFetchError } from "@/hooks/useFetchError"; import { useOpenAIStore } from "@/hooks/useOpenAI"; import { useChannelStore } from "@/hooks/useChannel"; import { useCharacterStore } from "@/hooks/useCharacter"; +import { useUserInfoStore } from "@/hooks/useUserInfo"; import { syncStore } from "@/store/sync"; -import { FREE_SYNC_SIZE } from "@/utils/constant"; +import { FREE_SYNC_SIZE, PRO_SYNC_SIZE } from "@/utils/constant"; interface IProps { onClose: () => void; @@ -33,6 +34,7 @@ export default function ModalContent({ onClose }: IProps) { state.list, ]); const characterList = useCharacterStore((state) => state.list); + const license_type = useUserInfoStore((state) => state.license_type); const syncSize = syncStore((state) => state.size); const [loadingBackup, setLoadingBackup] = React.useState(false); const [loadingRestore, setLoadingRestore] = React.useState(false); @@ -45,9 +47,12 @@ export default function ModalContent({ onClose }: IProps) { const importCharacterList = useCharacterStore((state) => state.importList); const updateSyncSize = syncStore((state) => state.updateSize); + const isFree = license_type !== "premium" && license_type !== "team"; + const totalSize = isFree ? FREE_SYNC_SIZE : PRO_SYNC_SIZE; + const syncUsage = React.useMemo(() => { - return (syncSize / FREE_SYNC_SIZE) * 100; - }, [syncSize]); + return (syncSize / totalSize) * 100; + }, [syncSize, isFree]); const getSyncSize = async () => { if (syncSize) return; @@ -199,15 +204,17 @@ export default function ModalContent({ onClose }: IProps) {
{tBackup("usage")}
- {syncSize} KB / {FREE_SYNC_SIZE} KB + {syncSize} KB / {totalSize} KB
- - (Free) - + {isFree && ( + + (Free) + + )}