fix(useOnline): only log if actually faking state #2924

Merged
konrad merged 1 commits from dpschen/frontend:feature/useOnline-fix-logging into main 2023-01-05 13:33:39 +00:00
2 changed files with 13 additions and 6 deletions

10
env.d.ts vendored
View File

@ -1,3 +1,11 @@
/// <reference types="vite/client" />
/// <reference types="vite-svg-loader" />
/// <reference types="cypress" />
/// <reference types="cypress" />
interface ImportMetaEnv {
readonly VITE_IS_ONLINE: boolean
}
interface ImportMeta {
readonly env: ImportMetaEnv
}

View File

@ -3,12 +3,11 @@ import {useOnline as useNetworkOnline} from '@vueuse/core'
import type {ConfigurableWindow} from '@vueuse/core'
export function useOnline(options?: ConfigurableWindow) {
const isOnline = useNetworkOnline(options)
const fakeOnlineState = !!import.meta.env.VITE_IS_ONLINE
if (fakeOnlineState) {
if (isOnline.value === false && fakeOnlineState) {
console.log('Setting fake online state', fakeOnlineState)
return ref(true)
}
return fakeOnlineState
? ref(true)
: useNetworkOnline(options)
return isOnline
}