fix: edge cases on disabled sync modes
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
|||||||
setRESTCollections,
|
setRESTCollections,
|
||||||
setGraphqlCollections,
|
setGraphqlCollections,
|
||||||
} from "~/newstore/collections"
|
} from "~/newstore/collections"
|
||||||
import { settingsStore } from "~/newstore/settings"
|
import { getSettingSubject, settingsStore } from "~/newstore/settings"
|
||||||
|
|
||||||
type CollectionFlags = "collectionsGraphql" | "collections"
|
type CollectionFlags = "collectionsGraphql" | "collections"
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ export async function writeCollections(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function initCollections() {
|
export function initCollections() {
|
||||||
restCollections$.subscribe((collections) => {
|
const restCollSub = restCollections$.subscribe((collections) => {
|
||||||
if (
|
if (
|
||||||
loadedRESTCollections &&
|
loadedRESTCollections &&
|
||||||
currentUser$.value &&
|
currentUser$.value &&
|
||||||
@@ -77,7 +77,7 @@ export function initCollections() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
graphqlCollections$.subscribe((collections) => {
|
const gqlCollSub = graphqlCollections$.subscribe((collections) => {
|
||||||
if (
|
if (
|
||||||
loadedGraphqlCollections &&
|
loadedGraphqlCollections &&
|
||||||
currentUser$.value &&
|
currentUser$.value &&
|
||||||
@@ -90,7 +90,7 @@ export function initCollections() {
|
|||||||
let restSnapshotStop: (() => void) | null = null
|
let restSnapshotStop: (() => void) | null = null
|
||||||
let graphqlSnapshotStop: (() => void) | null = null
|
let graphqlSnapshotStop: (() => void) | null = null
|
||||||
|
|
||||||
currentUser$.subscribe((user) => {
|
const currentUserSub = currentUser$.subscribe((user) => {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
if (restSnapshotStop) {
|
if (restSnapshotStop) {
|
||||||
restSnapshotStop()
|
restSnapshotStop()
|
||||||
@@ -116,7 +116,7 @@ export function initCollections() {
|
|||||||
loadedRESTCollections = false
|
loadedRESTCollections = false
|
||||||
|
|
||||||
// TODO: Wth is with collections[0]
|
// TODO: Wth is with collections[0]
|
||||||
if (collections.length > 0) {
|
if (collections.length > 0 && settingsStore.value.syncCollections) {
|
||||||
setRESTCollections(
|
setRESTCollections(
|
||||||
(collections[0].collection ?? []).map(
|
(collections[0].collection ?? []).map(
|
||||||
translateToNewRESTCollection
|
translateToNewRESTCollection
|
||||||
@@ -142,7 +142,7 @@ export function initCollections() {
|
|||||||
loadedGraphqlCollections = false
|
loadedGraphqlCollections = false
|
||||||
|
|
||||||
// TODO: Wth is with collections[0]
|
// TODO: Wth is with collections[0]
|
||||||
if (collections.length > 0) {
|
if (collections.length > 0 && settingsStore.value.syncCollections) {
|
||||||
setGraphqlCollections(
|
setGraphqlCollections(
|
||||||
(collections[0].collection ?? []).map(translateToNewGQLCollection)
|
(collections[0].collection ?? []).map(translateToNewGQLCollection)
|
||||||
)
|
)
|
||||||
@@ -153,4 +153,24 @@ export function initCollections() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let oldSyncStatus = settingsStore.value.syncCollections
|
||||||
|
|
||||||
|
const syncStop = getSettingSubject("syncCollections").subscribe(
|
||||||
|
(newStatus) => {
|
||||||
|
if (oldSyncStatus === true && newStatus === false) {
|
||||||
|
restSnapshotStop?.()
|
||||||
|
graphqlSnapshotStop?.()
|
||||||
|
|
||||||
|
oldSyncStatus = newStatus
|
||||||
|
} else if (oldSyncStatus === false && newStatus === true) {
|
||||||
|
syncStop.unsubscribe()
|
||||||
|
restCollSub.unsubscribe()
|
||||||
|
gqlCollSub.unsubscribe()
|
||||||
|
currentUserSub.unsubscribe()
|
||||||
|
|
||||||
|
initCollections()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
replaceEnvironments,
|
replaceEnvironments,
|
||||||
setGlobalEnvVariables,
|
setGlobalEnvVariables,
|
||||||
} from "~/newstore/environments"
|
} from "~/newstore/environments"
|
||||||
import { settingsStore } from "~/newstore/settings"
|
import { getSettingSubject, settingsStore } from "~/newstore/settings"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used locally to prevent infinite loop when environment sync update
|
* Used locally to prevent infinite loop when environment sync update
|
||||||
@@ -84,7 +84,7 @@ async function writeGlobalEnvironment(variables: Environment["variables"]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function initEnvironments() {
|
export function initEnvironments() {
|
||||||
environments$.subscribe((envs) => {
|
const envListenSub = environments$.subscribe((envs) => {
|
||||||
if (
|
if (
|
||||||
currentUser$.value &&
|
currentUser$.value &&
|
||||||
settingsStore.value.syncEnvironments &&
|
settingsStore.value.syncEnvironments &&
|
||||||
@@ -94,7 +94,7 @@ export function initEnvironments() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
globalEnv$.subscribe((vars) => {
|
const globalListenSub = globalEnv$.subscribe((vars) => {
|
||||||
if (
|
if (
|
||||||
currentUser$.value &&
|
currentUser$.value &&
|
||||||
settingsStore.value.syncEnvironments &&
|
settingsStore.value.syncEnvironments &&
|
||||||
@@ -107,7 +107,7 @@ export function initEnvironments() {
|
|||||||
let envSnapshotStop: (() => void) | null = null
|
let envSnapshotStop: (() => void) | null = null
|
||||||
let globalsSnapshotStop: (() => void) | null = null
|
let globalsSnapshotStop: (() => void) | null = null
|
||||||
|
|
||||||
currentUser$.subscribe((user) => {
|
const currentUserSub = currentUser$.subscribe((user) => {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
// User logged out, clean up snapshot listener
|
// User logged out, clean up snapshot listener
|
||||||
if (envSnapshotStop) {
|
if (envSnapshotStop) {
|
||||||
@@ -132,7 +132,7 @@ export function initEnvironments() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
loadedEnvironments = false
|
loadedEnvironments = false
|
||||||
if (environments.length > 0) {
|
if (environments.length > 0 && settingsStore.value.syncEnvironments) {
|
||||||
replaceEnvironments(environments[0].environment)
|
replaceEnvironments(environments[0].environment)
|
||||||
}
|
}
|
||||||
loadedEnvironments = true
|
loadedEnvironments = true
|
||||||
@@ -148,10 +148,31 @@ export function initEnvironments() {
|
|||||||
|
|
||||||
const doc = globalsRef.docs[0].data()
|
const doc = globalsRef.docs[0].data()
|
||||||
loadedGlobals = false
|
loadedGlobals = false
|
||||||
setGlobalEnvVariables(doc.variables)
|
if (settingsStore.value.syncEnvironments)
|
||||||
|
setGlobalEnvVariables(doc.variables)
|
||||||
loadedGlobals = true
|
loadedGlobals = true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let oldSyncStatus = settingsStore.value.syncEnvironments
|
||||||
|
|
||||||
|
const syncStop = getSettingSubject("syncEnvironments").subscribe(
|
||||||
|
(newStatus) => {
|
||||||
|
if (oldSyncStatus === true && newStatus === false) {
|
||||||
|
envSnapshotStop?.()
|
||||||
|
globalsSnapshotStop?.()
|
||||||
|
|
||||||
|
oldSyncStatus = newStatus
|
||||||
|
} else if (oldSyncStatus === false && newStatus === true) {
|
||||||
|
syncStop.unsubscribe()
|
||||||
|
envListenSub.unsubscribe()
|
||||||
|
globalListenSub.unsubscribe()
|
||||||
|
currentUserSub.unsubscribe()
|
||||||
|
|
||||||
|
initEnvironments()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
} from "firebase/firestore"
|
} from "firebase/firestore"
|
||||||
import { FormDataKeyValue } from "@hoppscotch/data"
|
import { FormDataKeyValue } from "@hoppscotch/data"
|
||||||
import { currentUser$ } from "./auth"
|
import { currentUser$ } from "./auth"
|
||||||
import { settingsStore } from "~/newstore/settings"
|
import { getSettingSubject, settingsStore } from "~/newstore/settings"
|
||||||
import {
|
import {
|
||||||
GQLHistoryEntry,
|
GQLHistoryEntry,
|
||||||
graphqlHistoryStore,
|
graphqlHistoryStore,
|
||||||
@@ -142,7 +142,7 @@ async function toggleStar(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function initHistory() {
|
export function initHistory() {
|
||||||
restHistoryStore.dispatches$.subscribe((dispatch) => {
|
const restHistorySub = restHistoryStore.dispatches$.subscribe((dispatch) => {
|
||||||
if (
|
if (
|
||||||
loadedRESTHistory &&
|
loadedRESTHistory &&
|
||||||
currentUser$.value &&
|
currentUser$.value &&
|
||||||
@@ -160,28 +160,30 @@ export function initHistory() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
graphqlHistoryStore.dispatches$.subscribe((dispatch) => {
|
const gqlHistorySub = graphqlHistoryStore.dispatches$.subscribe(
|
||||||
if (
|
(dispatch) => {
|
||||||
loadedGraphqlHistory &&
|
if (
|
||||||
currentUser$.value &&
|
loadedGraphqlHistory &&
|
||||||
settingsStore.value.syncHistory
|
currentUser$.value &&
|
||||||
) {
|
settingsStore.value.syncHistory
|
||||||
if (dispatch.dispatcher === "addEntry") {
|
) {
|
||||||
writeHistory(dispatch.payload.entry, "graphqlHistory")
|
if (dispatch.dispatcher === "addEntry") {
|
||||||
} else if (dispatch.dispatcher === "deleteEntry") {
|
writeHistory(dispatch.payload.entry, "graphqlHistory")
|
||||||
deleteHistory(dispatch.payload.entry, "graphqlHistory")
|
} else if (dispatch.dispatcher === "deleteEntry") {
|
||||||
} else if (dispatch.dispatcher === "clearHistory") {
|
deleteHistory(dispatch.payload.entry, "graphqlHistory")
|
||||||
clearHistory("graphqlHistory")
|
} else if (dispatch.dispatcher === "clearHistory") {
|
||||||
} else if (dispatch.dispatcher === "toggleStar") {
|
clearHistory("graphqlHistory")
|
||||||
toggleStar(dispatch.payload.entry, "graphqlHistory")
|
} else if (dispatch.dispatcher === "toggleStar") {
|
||||||
|
toggleStar(dispatch.payload.entry, "graphqlHistory")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
|
|
||||||
let restSnapshotStop: (() => void) | null = null
|
let restSnapshotStop: (() => void) | null = null
|
||||||
let graphqlSnapshotStop: (() => void) | null = null
|
let graphqlSnapshotStop: (() => void) | null = null
|
||||||
|
|
||||||
currentUser$.subscribe((user) => {
|
const currentUserSub = currentUser$.subscribe((user) => {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
// Clear the snapshot listeners when the user logs out
|
// Clear the snapshot listeners when the user logs out
|
||||||
if (restSnapshotStop) {
|
if (restSnapshotStop) {
|
||||||
@@ -239,4 +241,22 @@ export function initHistory() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let oldSyncStatus = settingsStore.value.syncHistory
|
||||||
|
|
||||||
|
const syncStop = getSettingSubject("syncHistory").subscribe((newStatus) => {
|
||||||
|
if (oldSyncStatus === true && newStatus === false) {
|
||||||
|
restSnapshotStop?.()
|
||||||
|
graphqlSnapshotStop?.()
|
||||||
|
|
||||||
|
oldSyncStatus = newStatus
|
||||||
|
} else if (oldSyncStatus === false && newStatus === true) {
|
||||||
|
syncStop.unsubscribe()
|
||||||
|
restHistorySub.unsubscribe()
|
||||||
|
gqlHistorySub.unsubscribe()
|
||||||
|
currentUserSub.unsubscribe()
|
||||||
|
|
||||||
|
initHistory()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user