chore: move collections sync system to platform (#2940)

This commit is contained in:
Akash K
2023-03-13 17:08:05 +05:30
committed by GitHub
parent ae9b7183b5
commit 7e1b26c6a9
7 changed files with 46 additions and 47 deletions

View File

@@ -1,7 +1,6 @@
import { initializeApp } from "firebase/app"
import { platform } from "~/platform"
import { initAnalytics } from "./analytics"
import { initCollections } from "./collections"
import { initHistory } from "./history"
import { initSettings } from "./settings"
@@ -25,7 +24,7 @@ export function initializeFirebase() {
platform.auth.performAuthInit()
initSettings()
initCollections()
platform.sync.collections.initCollectionsSync()
initHistory()
platform.sync.environments.initEnvironmentsSync()
initAnalytics()

View File

@@ -0,0 +1,3 @@
export type CollectionsPlatformDef = {
initCollectionsSync: () => void
}

View File

@@ -1,12 +1,14 @@
import { AuthPlatformDef } from "./auth"
import { UIPlatformDef } from "./ui"
import { EnvironmentsPlatformDef } from "./environments"
import { CollectionsPlatformDef } from "./collections"
export type PlatformDef = {
ui?: UIPlatformDef
auth: AuthPlatformDef
sync: {
environments: EnvironmentsPlatformDef
collections: CollectionsPlatformDef
}
}

View File

@@ -28,7 +28,8 @@
"stream-browserify": "^3.0.0",
"util": "^0.12.4",
"vue": "^3.2.41",
"workbox-window": "^6.5.4"
"workbox-window": "^6.5.4",
"@hoppscotch/data": "workspace:^0.4.4"
},
"devDependencies": {
"@intlify/vite-plugin-vue-i18n": "^6.0.1",

View File

@@ -9,14 +9,22 @@ import {
translateToNewRESTCollection,
translateToNewGQLCollection,
} from "@hoppscotch/data"
import { platform } from "~/platform"
import { def as platformAuth } from "./firebase/auth"
import {
restCollections$,
graphqlCollections$,
setRESTCollections,
setGraphqlCollections,
} from "~/newstore/collections"
import { getSettingSubject, settingsStore } from "~/newstore/settings"
} from "@hoppscotch/common/newstore/collections"
import {
getSettingSubject,
settingsStore,
} from "@hoppscotch/common/newstore/settings"
import { CollectionsPlatformDef } from "@hoppscotch/common/platform/collections"
type CollectionFlags = "collectionsGraphql" | "collections"
@@ -40,11 +48,8 @@ let loadedRESTCollections = false
*/
let loadedGraphqlCollections = false
export async function writeCollections(
collection: any[],
flag: CollectionFlags
) {
const currentUser = platform.auth.getCurrentUser()
async function writeCollections(collection: any[], flag: CollectionFlags) {
const currentUser = platformAuth.getCurrentUser()
if (currentUser === null)
throw new Error("User not logged in to write collections")
@@ -68,11 +73,11 @@ export async function writeCollections(
}
}
export function initCollections() {
const currentUser$ = platform.auth.getCurrentUserStream()
function initCollectionsSync() {
const currentUser$ = platformAuth.getCurrentUserStream()
const restCollSub = restCollections$.subscribe((collections) => {
const currentUser = platform.auth.getCurrentUser()
const currentUser = platformAuth.getCurrentUser()
if (
loadedRESTCollections &&
@@ -84,7 +89,7 @@ export function initCollections() {
})
const gqlCollSub = graphqlCollections$.subscribe((collections) => {
const currentUser = platform.auth.getCurrentUser()
const currentUser = platformAuth.getCurrentUser()
if (
loadedGraphqlCollections &&
@@ -177,8 +182,12 @@ export function initCollections() {
gqlCollSub.unsubscribe()
currentUserSub.unsubscribe()
initCollections()
initCollectionsSync()
}
}
)
}
export const def: CollectionsPlatformDef = {
initCollectionsSync,
}

View File

@@ -1,10 +1,12 @@
import { createHoppApp } from "@hoppscotch/common"
import { def as authDef } from "./firebase/auth"
import { def as envDef } from "./environments"
import { def as collectionsDef } from "./collections"
createHoppApp("#app", {
auth: authDef,
sync: {
environments: envDef,
collections: collectionsDef,
},
})