Skip to content

Commit

Permalink
refactor(versionCheck): add app data ready check condition
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoAria committed Nov 26, 2024
1 parent fdfab6e commit 90671b6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/hooks/useVersionCheck.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { useStore } from "@nanostores/react"
import { ofetch } from "ofetch"
import { useEffect, useState } from "react"

import { dataState } from "@/store/dataState"
import { GITHUB_REPO_PATH, UPDATE_NOTIFICATION_KEY } from "@/utils/constants"
import { checkIsInLast24Hours, getTimestamp } from "@/utils/date"
import buildInfo from "@/version-info.json"

function useVersionCheck() {
const { isAppDataReady } = useStore(dataState)

const [hasUpdate, setHasUpdate] = useState(false)

const dismissUpdate = () => {
Expand All @@ -14,7 +18,7 @@ function useVersionCheck() {
}

useEffect(() => {
if (!import.meta.env.PROD) {
if (!isAppDataReady || !import.meta.env.PROD) {
return
}

Expand All @@ -37,7 +41,7 @@ function useVersionCheck() {
}

checkUpdate()
}, [])
}, [isAppDataReady])

return { hasUpdate, dismissUpdate }
}
Expand Down

0 comments on commit 90671b6

Please sign in to comment.