"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "packages/hoppscotch-app/helpers/fb/collections.ts" between
hoppscotch-2.2.1.tar.gz and hoppscotch-3.0.0.tar.gz

About: Hoppscotch is a light-weight, web based API development suite.

collections.ts  (hoppscotch-2.2.1):collections.ts  (hoppscotch-3.0.0)
skipping to change at line 19 skipping to change at line 19
translateToNewRESTCollection, translateToNewRESTCollection,
translateToNewGQLCollection, translateToNewGQLCollection,
} from "@hoppscotch/data" } from "@hoppscotch/data"
import { currentUser$ } from "./auth" import { currentUser$ } from "./auth"
import { import {
restCollections$, restCollections$,
graphqlCollections$, graphqlCollections$,
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"
/** /**
* Whether the collections are loaded. If this is set to true * Whether the collections are loaded. If this is set to true
* Updates to the collections store are written into firebase. * Updates to the collections store are written into firebase.
* *
* If you have want to update the store and not fire the store update * If you have want to update the store and not fire the store update
* subscription, set this variable to false, do the update and then * subscription, set this variable to false, do the update and then
* set it to true * set it to true
skipping to change at line 70 skipping to change at line 70
doc(getFirestore(), "users", currentUser$.value.uid, flag, "sync"), doc(getFirestore(), "users", currentUser$.value.uid, flag, "sync"),
cl cl
) )
} catch (e) { } catch (e) {
console.error("error updating", cl, e) console.error("error updating", cl, e)
throw e throw e
} }
} }
export function initCollections() { export function initCollections() {
restCollections$.subscribe((collections) => { const restCollSub = restCollections$.subscribe((collections) => {
if ( if (
loadedRESTCollections && loadedRESTCollections &&
currentUser$.value && currentUser$.value &&
settingsStore.value.syncCollections settingsStore.value.syncCollections
) { ) {
writeCollections(collections, "collections") writeCollections(collections, "collections")
} }
}) })
graphqlCollections$.subscribe((collections) => { const gqlCollSub = graphqlCollections$.subscribe((collections) => {
if ( if (
loadedGraphqlCollections && loadedGraphqlCollections &&
currentUser$.value && currentUser$.value &&
settingsStore.value.syncCollections settingsStore.value.syncCollections
) { ) {
writeCollections(collections, "collectionsGraphql") writeCollections(collections, "collectionsGraphql")
} }
}) })
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()
restSnapshotStop = null restSnapshotStop = null
} }
if (graphqlSnapshotStop) { if (graphqlSnapshotStop) {
graphqlSnapshotStop() graphqlSnapshotStop()
graphqlSnapshotStop = null graphqlSnapshotStop = null
} }
skipping to change at line 119 skipping to change at line 119
collectionsRef.forEach((doc) => { collectionsRef.forEach((doc) => {
const collection = doc.data() const collection = doc.data()
collection.id = doc.id collection.id = doc.id
collections.push(collection) collections.push(collection)
}) })
// Prevent infinite ping-pong of updates // Prevent infinite ping-pong of updates
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
) )
) )
} }
loadedRESTCollections = true loadedRESTCollections = true
} }
) )
skipping to change at line 145 skipping to change at line 145
collectionsRef.forEach((doc) => { collectionsRef.forEach((doc) => {
const collection = doc.data() const collection = doc.data()
collection.id = doc.id collection.id = doc.id
collections.push(collection) collections.push(collection)
}) })
// Prevent infinite ping-pong of updates // Prevent infinite ping-pong of updates
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)
) )
} }
loadedGraphqlCollections = true loadedGraphqlCollections = true
} }
) )
} }
}) })
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()
}
}
)
} }
 End of changes. 7 change blocks. 
6 lines changed or deleted 26 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)