From fe4ac883280038400af98b5ec536df79c87b4251 Mon Sep 17 00:00:00 2001 From: waterplea Date: Tue, 21 Jun 2022 13:09:58 +0300 Subject: [PATCH 1/7] refactor(patch-db): use PatchDB class declaratively --- frontend/projects/ui/src/app/app.component.ts | 14 +++++- frontend/projects/ui/src/app/app.module.ts | 2 + frontend/projects/ui/src/app/app.providers.ts | 31 +++++++------ .../ui/src/app/app/global/global.module.ts | 20 +++------ .../developer-menu/developer-menu.page.ts | 2 +- .../notifications/notifications.page.html | 10 +++-- .../app/services/patch-db/patch-db.factory.ts | 18 +++++--- .../app/services/patch-db/patch-db.module.ts | 45 +++++++++++++++++++ .../app/services/patch-db/patch-db.service.ts | 35 ++++++--------- 9 files changed, 113 insertions(+), 64 deletions(-) create mode 100644 frontend/projects/ui/src/app/services/patch-db/patch-db.module.ts diff --git a/frontend/projects/ui/src/app/app.component.ts b/frontend/projects/ui/src/app/app.component.ts index 7458ca9f54..b19ac5d686 100644 --- a/frontend/projects/ui/src/app/app.component.ts +++ b/frontend/projects/ui/src/app/app.component.ts @@ -1,14 +1,20 @@ -import { Component } from '@angular/core' +import { Component, Inject, OnDestroy } from '@angular/core' import { AuthService } from './services/auth.service' import { SplitPaneTracker } from './services/split-pane.service' +import { merge, Observable } from 'rxjs' +import { GLOBAL_SERVICE } from './app/global/global.module' @Component({ selector: 'app-root', templateUrl: 'app.component.html', styleUrls: ['app.component.scss'], }) -export class AppComponent { +export class AppComponent implements OnDestroy { + readonly subscription = merge(...this.services).subscribe() + constructor( + @Inject(GLOBAL_SERVICE) + private readonly services: readonly Observable[], readonly authService: AuthService, private readonly splitPane: SplitPaneTracker, ) {} @@ -16,4 +22,8 @@ export class AppComponent { splitPaneVisible({ detail }: any) { this.splitPane.sidebarOpen$.next(detail.visible) } + + ngOnDestroy() { + this.subscription.unsubscribe() + } } diff --git a/frontend/projects/ui/src/app/app.module.ts b/frontend/projects/ui/src/app/app.module.ts index 36911efbdd..dee86adc83 100644 --- a/frontend/projects/ui/src/app/app.module.ts +++ b/frontend/projects/ui/src/app/app.module.ts @@ -18,6 +18,7 @@ import { MenuModule } from './app/menu/menu.module' import { EnterModule } from './app/enter/enter.module' import { APP_PROVIDERS } from './app.providers' import { GlobalModule } from './app/global/global.module' +import { PatchDbModule } from './services/patch-db/patch-db.module' @NgModule({ declarations: [AppComponent], @@ -46,6 +47,7 @@ import { GlobalModule } from './app/global/global.module' SharedPipesModule, MarketplaceModule, GlobalModule, + PatchDbModule, ], providers: APP_PROVIDERS, bootstrap: [AppComponent], diff --git a/frontend/projects/ui/src/app/app.providers.ts b/frontend/projects/ui/src/app/app.providers.ts index 038e09f698..ae62cba180 100644 --- a/frontend/projects/ui/src/app/app.providers.ts +++ b/frontend/projects/ui/src/app/app.providers.ts @@ -1,4 +1,4 @@ -import { DOCUMENT } from '@angular/common' +import { Bootstrapper, DBCache } from 'patch-db-client' import { APP_INITIALIZER, ErrorHandler, Provider } from '@angular/core' import { FormBuilder } from '@angular/forms' import { Router, RouteReuseStrategy } from '@angular/router' @@ -9,15 +9,11 @@ import { WorkspaceConfig } from '@start9labs/shared' import { ApiService } from './services/api/embassy-api.service' import { MockApiService } from './services/api/embassy-mock-api.service' import { LiveApiService } from './services/api/embassy-live-api.service' -import { - PATCH_SOURCE, - mockSourceFactory, - realSourceFactory, -} from './services/patch-db/patch-db.factory' -import { ConfigService } from './services/config.service' +import { BOOTSTRAPPER, PATCH_CACHE } from './services/patch-db/patch-db.factory' import { GlobalErrorHandler } from './services/global-error-handler.service' import { AuthService } from './services/auth.service' import { LocalStorageService } from './services/local-storage.service' +import { DataModel } from './services/patch-db/data-model' const { useMocks } = require('../../../../config.json') as WorkspaceConfig @@ -32,18 +28,20 @@ export const APP_PROVIDERS: Provider[] = [ provide: ApiService, useClass: useMocks ? MockApiService : LiveApiService, }, - { - provide: PATCH_SOURCE, - deps: [ApiService, ConfigService, DOCUMENT], - useFactory: useMocks ? mockSourceFactory : realSourceFactory, - }, { provide: ErrorHandler, useClass: GlobalErrorHandler, }, { provide: APP_INITIALIZER, - deps: [Storage, AuthService, LocalStorageService, Router], + deps: [ + Storage, + AuthService, + LocalStorageService, + Router, + BOOTSTRAPPER, + PATCH_CACHE, + ], useFactory: appInitializer, multi: true, }, @@ -54,12 +52,19 @@ export function appInitializer( auth: AuthService, localStorage: LocalStorageService, router: Router, + bootstrapper: Bootstrapper, + cache: DBCache, ): () => Promise { return async () => { await storage.create() await auth.init() await localStorage.init() + const localCache = await bootstrapper.init() + + cache.sequence = localCache.sequence + cache.data = localCache.data + router.initialNavigation() } } diff --git a/frontend/projects/ui/src/app/app/global/global.module.ts b/frontend/projects/ui/src/app/app/global/global.module.ts index 27800f21f8..e5c3eadbff 100644 --- a/frontend/projects/ui/src/app/app/global/global.module.ts +++ b/frontend/projects/ui/src/app/app/global/global.module.ts @@ -17,10 +17,11 @@ import { UnreadToastService } from './services/unread-toast.service' import { RefreshToastService } from './services/refresh-toast.service' import { UpdateToastService } from './services/update-toast.service' -const GLOBAL_SERVICE = new InjectionToken[]>( - 'A multi token of global Observable services', -) +export const GLOBAL_SERVICE = new InjectionToken< + readonly Observable[] +>('A multi token of global Observable services') +// This module is purely for providers organization purposes @NgModule({ providers: [ [ @@ -34,18 +35,7 @@ const GLOBAL_SERVICE = new InjectionToken[]>( [PatchDataService, PatchMonitorService].map(useExisting), ], }) -export class GlobalModule implements OnDestroy { - readonly subscription = merge(...this.services).subscribe() - - constructor( - @Inject(GLOBAL_SERVICE) - private readonly services: readonly Observable[], - ) {} - - ngOnDestroy() { - this.subscription.unsubscribe() - } -} +export class GlobalModule {} function useClass(useClass: Type): ClassProvider { return { diff --git a/frontend/projects/ui/src/app/pages/developer-routes/developer-menu/developer-menu.page.ts b/frontend/projects/ui/src/app/pages/developer-routes/developer-menu/developer-menu.page.ts index e50b230f5f..4a8072a707 100644 --- a/frontend/projects/ui/src/app/pages/developer-routes/developer-menu/developer-menu.page.ts +++ b/frontend/projects/ui/src/app/pages/developer-routes/developer-menu/developer-menu.page.ts @@ -32,7 +32,7 @@ export class DeveloperMenuPage { ) {} get name(): string { - return this.patchDb.data.ui?.dev?.[this.projectId]?.name || '' + return this.patchDb.getData().ui?.dev?.[this.projectId]?.name || '' } ngOnInit() { diff --git a/frontend/projects/ui/src/app/pages/notifications/notifications.page.html b/frontend/projects/ui/src/app/pages/notifications/notifications.page.html index 184fc82b71..6d008b222d 100644 --- a/frontend/projects/ui/src/app/pages/notifications/notifications.page.html +++ b/frontend/projects/ui/src/app/pages/notifications/notifications.page.html @@ -75,10 +75,12 @@

Inbox Empty

- - {{ patch.data['package-data'][not['package-id']] ? - patch.data['package-data'][not['package-id']].manifest.title : - not['package-id'] }} - + + {{ patch.getData()['package-data'][not['package-id']] ? + patch.getData()['package-data'][not['package-id']].manifest.title + : not['package-id'] }} - {{ not.title }} diff --git a/frontend/projects/ui/src/app/services/patch-db/patch-db.factory.ts b/frontend/projects/ui/src/app/services/patch-db/patch-db.factory.ts index bbc832a8e0..5710b40f7c 100644 --- a/frontend/projects/ui/src/app/services/patch-db/patch-db.factory.ts +++ b/frontend/projects/ui/src/app/services/patch-db/patch-db.factory.ts @@ -1,8 +1,9 @@ -import { inject, InjectionToken } from '@angular/core' +import { InjectionToken } from '@angular/core' import { exists } from '@start9labs/shared' import { filter } from 'rxjs/operators' import { Bootstrapper, + DBCache, MockSource, PollSource, Source, @@ -10,17 +11,20 @@ import { } from 'patch-db-client' import { ConfigService } from '../config.service' -import { LocalStorageBootstrap } from './local-storage-bootstrap' import { ApiService } from '../api/embassy-api.service' import { MockApiService } from '../api/embassy-mock-api.service' import { DataModel } from './data-model' +import { BehaviorSubject } from 'rxjs' -export const PATCH_SOURCE = new InjectionToken[]>( - '[wsSources, pollSources]', -) -export const BOOTSTRAPPER = new InjectionToken>('', { - factory: () => inject(LocalStorageBootstrap), +// [wsSources, pollSources] +export const PATCH_SOURCE = new InjectionToken[]>('') +export const PATCH_SOURCE$ = new InjectionToken< + BehaviorSubject[]> +>('') +export const PATCH_CACHE = new InjectionToken>('', { + factory: () => ({} as any), }) +export const BOOTSTRAPPER = new InjectionToken>('') export function mockSourceFactory({ mockPatch$, diff --git a/frontend/projects/ui/src/app/services/patch-db/patch-db.module.ts b/frontend/projects/ui/src/app/services/patch-db/patch-db.module.ts new file mode 100644 index 0000000000..e788ee7a58 --- /dev/null +++ b/frontend/projects/ui/src/app/services/patch-db/patch-db.module.ts @@ -0,0 +1,45 @@ +import { PatchDB } from 'patch-db-client' +import { NgModule } from '@angular/core' +import { DOCUMENT } from '@angular/common' +import { WorkspaceConfig } from '@start9labs/shared' + +import { + BOOTSTRAPPER, + mockSourceFactory, + PATCH_CACHE, + PATCH_SOURCE, + PATCH_SOURCE$, + realSourceFactory, +} from './patch-db.factory' +import { LocalStorageBootstrap } from './local-storage-bootstrap' +import { ApiService } from '../api/embassy-api.service' +import { ConfigService } from '../config.service' +import { BehaviorSubject } from 'rxjs' + +const { useMocks } = require('../../../../../../config.json') as WorkspaceConfig + +// This module is purely for providers organization purposes +@NgModule({ + providers: [ + { + provide: BOOTSTRAPPER, + useExisting: LocalStorageBootstrap, + }, + { + provide: PATCH_SOURCE, + deps: [ApiService, ConfigService, DOCUMENT], + useFactory: useMocks ? mockSourceFactory : realSourceFactory, + }, + { + provide: PATCH_SOURCE$, + deps: [PATCH_SOURCE], + useClass: BehaviorSubject, + }, + { + provide: PatchDB, + deps: [PATCH_SOURCE$, ApiService, PATCH_CACHE], + useClass: PatchDB, + }, + ], +}) +export class PatchDbModule {} diff --git a/frontend/projects/ui/src/app/services/patch-db/patch-db.service.ts b/frontend/projects/ui/src/app/services/patch-db/patch-db.service.ts index 15fe984636..4b4130932c 100644 --- a/frontend/projects/ui/src/app/services/patch-db/patch-db.service.ts +++ b/frontend/projects/ui/src/app/services/patch-db/patch-db.service.ts @@ -23,7 +23,7 @@ import { isEmptyObject, pauseFor } from '@start9labs/shared' import { DataModel } from './data-model' import { ApiService } from '../api/embassy-api.service' import { AuthService } from '../auth.service' -import { BOOTSTRAPPER, PATCH_SOURCE } from './patch-db.factory' +import { BOOTSTRAPPER, PATCH_SOURCE, PATCH_SOURCE$ } from './patch-db.factory' export enum PatchConnection { Initializing = 'initializing', @@ -39,13 +39,8 @@ export class PatchDbService { private patchConnection$ = new ReplaySubject(1) private wsSuccess$ = new BehaviorSubject(false) private polling$ = new BehaviorSubject(false) - private patchDb: PatchDB private subs: Subscription[] = [] - private sources$: BehaviorSubject[]> = new BehaviorSubject([ - this.sources[0], - ]) - data: DataModel errors = 0 getData() { @@ -65,23 +60,16 @@ export class PatchDbService { @Inject(PATCH_SOURCE) private readonly sources: Source[], @Inject(BOOTSTRAPPER) private readonly bootstrapper: Bootstrapper, + @Inject(PATCH_SOURCE$) + private readonly sources$: BehaviorSubject[]>, private readonly http: ApiService, private readonly auth: AuthService, private readonly storage: Storage, + private readonly patchDb: PatchDB, ) {} - async init(): Promise { - const cache = await this.bootstrapper.init() - this.sources$.next([this.sources[0], this.http]) - - this.patchDb = new PatchDB(this.sources$, this.http, cache) - - this.patchConnection$.next(PatchConnection.Initializing) - this.data = this.patchDb.store.cache.data - } - async start(): Promise { - await this.init() + this.reset() this.subs.push( // Connection Error @@ -165,11 +153,9 @@ export class PatchDbService { } stop(): void { - if (this.patchDb) { - console.log('patchDB: STOPPING') - this.patchConnection$.next(PatchConnection.Initializing) - this.patchDb.store.reset() - } + console.log('patchDB: STOPPING') + this.reset() + this.patchDb.store.reset() this.subs.forEach(x => x.unsubscribe()) this.subs = [] } @@ -196,4 +182,9 @@ export class PatchDbService { finalize(() => console.log('patchDB: UNSUBSCRIBING', argsString)), ) } + + private reset() { + this.patchConnection$.next(PatchConnection.Initializing) + this.sources$.next([this.sources[0], this.http]) + } } From 9d8291f192c1716b5b2422063a686a0537be64ce Mon Sep 17 00:00:00 2001 From: waterplea Date: Tue, 21 Jun 2022 13:35:19 +0300 Subject: [PATCH 2/7] chore: remove initial source before init --- .../src/app/services/patch-db/patch-db.module.ts | 5 ++--- .../src/app/services/patch-db/patch-db.service.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/frontend/projects/ui/src/app/services/patch-db/patch-db.module.ts b/frontend/projects/ui/src/app/services/patch-db/patch-db.module.ts index e788ee7a58..4a67975e68 100644 --- a/frontend/projects/ui/src/app/services/patch-db/patch-db.module.ts +++ b/frontend/projects/ui/src/app/services/patch-db/patch-db.module.ts @@ -14,7 +14,7 @@ import { import { LocalStorageBootstrap } from './local-storage-bootstrap' import { ApiService } from '../api/embassy-api.service' import { ConfigService } from '../config.service' -import { BehaviorSubject } from 'rxjs' +import { ReplaySubject } from 'rxjs' const { useMocks } = require('../../../../../../config.json') as WorkspaceConfig @@ -32,8 +32,7 @@ const { useMocks } = require('../../../../../../config.json') as WorkspaceConfig }, { provide: PATCH_SOURCE$, - deps: [PATCH_SOURCE], - useClass: BehaviorSubject, + useValue: new ReplaySubject(1), }, { provide: PatchDB, diff --git a/frontend/projects/ui/src/app/services/patch-db/patch-db.service.ts b/frontend/projects/ui/src/app/services/patch-db/patch-db.service.ts index 4b4130932c..15148a7889 100644 --- a/frontend/projects/ui/src/app/services/patch-db/patch-db.service.ts +++ b/frontend/projects/ui/src/app/services/patch-db/patch-db.service.ts @@ -68,8 +68,13 @@ export class PatchDbService { private readonly patchDb: PatchDB, ) {} + init() { + this.sources$.next([this.sources[0], this.http]) + this.patchConnection$.next(PatchConnection.Initializing) + } + async start(): Promise { - this.reset() + this.init() this.subs.push( // Connection Error @@ -154,7 +159,7 @@ export class PatchDbService { stop(): void { console.log('patchDB: STOPPING') - this.reset() + this.patchConnection$.next(PatchConnection.Initializing) this.patchDb.store.reset() this.subs.forEach(x => x.unsubscribe()) this.subs = [] @@ -182,9 +187,4 @@ export class PatchDbService { finalize(() => console.log('patchDB: UNSUBSCRIBING', argsString)), ) } - - private reset() { - this.patchConnection$.next(PatchConnection.Initializing) - this.sources$.next([this.sources[0], this.http]) - } } From 85310d94a58df50df838570f20211a2a48db4d2d Mon Sep 17 00:00:00 2001 From: waterplea Date: Tue, 21 Jun 2022 14:30:38 +0300 Subject: [PATCH 3/7] chore: show spinner --- .../ui/src/app/pages/apps-routes/app-list/app-list.page.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/projects/ui/src/app/pages/apps-routes/app-list/app-list.page.html b/frontend/projects/ui/src/app/pages/apps-routes/app-list/app-list.page.html index 3df3efa781..0c7b945e2c 100644 --- a/frontend/projects/ui/src/app/pages/apps-routes/app-list/app-list.page.html +++ b/frontend/projects/ui/src/app/pages/apps-routes/app-list/app-list.page.html @@ -10,7 +10,7 @@ From 6951bfeaca6dbf18ef57b1aa73919c79f1c4002a Mon Sep 17 00:00:00 2001 From: waterplea Date: Wed, 22 Jun 2022 10:49:09 +0300 Subject: [PATCH 4/7] fix: show Connecting to Embassy spinner until first connection --- .../apps-routes/app-list/app-list.page.html | 11 +++++------ .../pages/apps-routes/app-list/app-list.page.ts | 10 ++++------ .../marketplace-list/marketplace-list.page.html | 2 +- .../marketplace-list/marketplace-list.page.ts | 6 ++---- .../server-show/server-show.page.html | 13 ++++++------- .../server-show/server-show.page.ts | 5 +++-- .../app/services/patch-db/patch-db.service.ts | 17 ++++++++--------- 7 files changed, 29 insertions(+), 35 deletions(-) diff --git a/frontend/projects/ui/src/app/pages/apps-routes/app-list/app-list.page.html b/frontend/projects/ui/src/app/pages/apps-routes/app-list/app-list.page.html index 0c7b945e2c..430aa9710a 100644 --- a/frontend/projects/ui/src/app/pages/apps-routes/app-list/app-list.page.html +++ b/frontend/projects/ui/src/app/pages/apps-routes/app-list/app-list.page.html @@ -9,13 +9,12 @@ - + + + - + - + diff --git a/frontend/projects/ui/src/app/pages/apps-routes/app-list/app-list.page.ts b/frontend/projects/ui/src/app/pages/apps-routes/app-list/app-list.page.ts index 906c66e526..75c88504e9 100644 --- a/frontend/projects/ui/src/app/pages/apps-routes/app-list/app-list.page.ts +++ b/frontend/projects/ui/src/app/pages/apps-routes/app-list/app-list.page.ts @@ -18,18 +18,17 @@ export class AppListPage { recoveredPkgs: readonly RecoveredInfo[] = [] order: readonly string[] = [] reordering = false - loading = true + + readonly connected$ = this.patch.connected$ constructor( private readonly api: ApiService, private readonly destroy$: DestroyService, - public readonly patch: PatchDbService, + private readonly patch: PatchDbService, ) {} get empty(): boolean { - return ( - !this.loading && !this.pkgs.length && isEmptyObject(this.recoveredPkgs) - ) + return !this.pkgs.length && isEmptyObject(this.recoveredPkgs) } ngOnInit() { @@ -43,7 +42,6 @@ export class AppListPage { this.pkgs = pkgs this.recoveredPkgs = recoveredPkgs this.order = order - this.loading = false // set order in UI DB if there were unknown packages if (order.length < pkgs.length) { diff --git a/frontend/projects/ui/src/app/pages/marketplace-routes/marketplace-list/marketplace-list.page.html b/frontend/projects/ui/src/app/pages/marketplace-routes/marketplace-list/marketplace-list.page.html index a85b6d5918..059ae68d75 100644 --- a/frontend/projects/ui/src/app/pages/marketplace-routes/marketplace-list/marketplace-list.page.html +++ b/frontend/projects/ui/src/app/pages/marketplace-routes/marketplace-list/marketplace-list.page.html @@ -8,7 +8,7 @@ > = this.patch .watch$('package-data') .pipe( @@ -44,8 +46,4 @@ export class MarketplaceListPage { private readonly patch: PatchDbService, private readonly marketplaceService: AbstractMarketplaceService, ) {} - - get loaded(): boolean { - return this.patch.loaded - } } diff --git a/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.html b/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.html index dadfe79ff6..7ddbc3f360 100644 --- a/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.html +++ b/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.html @@ -1,6 +1,6 @@ - + {{ (ui$ | async)?.name || "Embassy-" + (server$ | async)?.id }} @@ -14,13 +14,12 @@ - + + + - +
@@ -98,5 +97,5 @@

{{ button.title }}

-
+
diff --git a/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.ts b/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.ts index 89384de6ce..fee14ed474 100644 --- a/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.ts +++ b/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.ts @@ -10,7 +10,7 @@ import { ApiService } from 'src/app/services/api/embassy-api.service' import { ActivatedRoute } from '@angular/router' import { PatchDbService } from 'src/app/services/patch-db/patch-db.service' import { Observable, of } from 'rxjs' -import { filter, map, take } from 'rxjs/operators' +import { filter, take } from 'rxjs/operators' import { exists, isEmptyObject, ErrorToastService } from '@start9labs/shared' import { EOSService } from 'src/app/services/eos.service' import { LocalStorageService } from 'src/app/services/local-storage.service' @@ -28,6 +28,7 @@ export class ServerShowPage { readonly server$ = this.patch.watch$('server-info') readonly ui$ = this.patch.watch$('ui') + readonly connected$ = this.patch.connected$ constructor( private readonly alertCtrl: AlertController, @@ -37,8 +38,8 @@ export class ServerShowPage { private readonly embassyApi: ApiService, private readonly navCtrl: NavController, private readonly route: ActivatedRoute, + private readonly patch: PatchDbService, public readonly eosService: EOSService, - public readonly patch: PatchDbService, public readonly localStorageService: LocalStorageService, ) {} diff --git a/frontend/projects/ui/src/app/services/patch-db/patch-db.service.ts b/frontend/projects/ui/src/app/services/patch-db/patch-db.service.ts index 15148a7889..d74477eda6 100644 --- a/frontend/projects/ui/src/app/services/patch-db/patch-db.service.ts +++ b/frontend/projects/ui/src/app/services/patch-db/patch-db.service.ts @@ -14,12 +14,13 @@ import { filter, finalize, mergeMap, + shareReplay, switchMap, take, tap, withLatestFrom, } from 'rxjs/operators' -import { isEmptyObject, pauseFor } from '@start9labs/shared' +import { pauseFor } from '@start9labs/shared' import { DataModel } from './data-model' import { ApiService } from '../api/embassy-api.service' import { AuthService } from '../auth.service' @@ -41,20 +42,18 @@ export class PatchDbService { private polling$ = new BehaviorSubject(false) private subs: Subscription[] = [] + readonly connected$ = this.watchPatchConnection$().pipe( + filter(status => status === PatchConnection.Connected), + take(1), + shareReplay(), + ) + errors = 0 getData() { return this.patchDb.store.cache.data } - // TODO: Refactor to use `Observable` so that we can react to PatchDb becoming loaded - get loaded(): boolean { - return ( - this.patchDb?.store?.cache?.data && - !isEmptyObject(this.patchDb.store.cache.data) - ) - } - constructor( // [wsSources, pollSources] @Inject(PATCH_SOURCE) private readonly sources: Source[], From 9e92cf74e026edfd85149dd58b57114801ec22e4 Mon Sep 17 00:00:00 2001 From: waterplea Date: Wed, 22 Jun 2022 11:19:15 +0300 Subject: [PATCH 5/7] fix: switching marketplaces --- .../ui/src/app/components/app-wizard/wizard-defs.ts | 3 --- .../marketplace-show-controls.component.ts | 2 -- .../projects/ui/src/app/services/marketplace.service.ts | 9 ++++----- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/frontend/projects/ui/src/app/components/app-wizard/wizard-defs.ts b/frontend/projects/ui/src/app/components/app-wizard/wizard-defs.ts index 0fae49742d..3267ac3a90 100644 --- a/frontend/projects/ui/src/app/components/app-wizard/wizard-defs.ts +++ b/frontend/projects/ui/src/app/components/app-wizard/wizard-defs.ts @@ -6,7 +6,6 @@ import { ApiService } from '../../services/api/embassy-api.service' import { AppWizardComponent, SlideDefinition } from './app-wizard.component' import { ConfigService } from 'src/app/services/config.service' import { MarketplaceService } from 'src/app/services/marketplace.service' -import { first } from 'rxjs/operators' @Injectable({ providedIn: 'root' }) export class WizardDefs { @@ -45,7 +44,6 @@ export class WizardDefs { id, 'version-spec': version ? `=${version}` : undefined, }) - .pipe(first()) .toPromise(), }, }, @@ -87,7 +85,6 @@ export class WizardDefs { id, 'version-spec': version ? `=${version}` : undefined, }) - .pipe(first()) .toPromise(), }, }, diff --git a/frontend/projects/ui/src/app/pages/marketplace-routes/marketplace-show/marketplace-show-controls/marketplace-show-controls.component.ts b/frontend/projects/ui/src/app/pages/marketplace-routes/marketplace-show/marketplace-show-controls/marketplace-show-controls.component.ts index 90342576aa..7ee5745f79 100644 --- a/frontend/projects/ui/src/app/pages/marketplace-routes/marketplace-show/marketplace-show-controls/marketplace-show-controls.component.ts +++ b/frontend/projects/ui/src/app/pages/marketplace-routes/marketplace-show/marketplace-show-controls/marketplace-show-controls.component.ts @@ -21,7 +21,6 @@ import { LocalStorageService } from 'src/app/services/local-storage.service' import { MarketplaceService } from 'src/app/services/marketplace.service' import { hasCurrentDeps } from 'src/app/util/has-deps' import { Emver } from '../../../../../../../shared/src/services/emver.service' -import { first } from 'rxjs/operators' import { ErrorToastService } from '../../../../../../../shared/src/services/error-toast.service' import { ApiService } from 'src/app/services/api/embassy-api.service' import { isEmptyObject } from '../../../../../../../shared/src/util/misc.util' @@ -145,7 +144,6 @@ export class MarketplaceShowControlsComponent { id, 'version-spec': `=${version}`, }) - .pipe(first()) .toPromise() } catch (e: any) { this.errToast.present(e) diff --git a/frontend/projects/ui/src/app/services/marketplace.service.ts b/frontend/projects/ui/src/app/services/marketplace.service.ts index 8088a26e2f..6bcb6cb920 100644 --- a/frontend/projects/ui/src/app/services/marketplace.service.ts +++ b/frontend/projects/ui/src/app/services/marketplace.service.ts @@ -6,7 +6,7 @@ import { AbstractMarketplaceService, Marketplace, } from '@start9labs/marketplace' -import { defer, from, Observable, of } from 'rxjs' +import { from, Observable, of } from 'rxjs' import { RR } from 'src/app/services/api/api.types' import { ApiService } from 'src/app/services/api/embassy-api.service' import { ConfigService } from 'src/app/services/config.service' @@ -32,7 +32,7 @@ export class MarketplaceService extends AbstractMarketplaceService { private readonly altMarketplaceData$: Observable< UIMarketplaceData | undefined - > = this.patch.watch$('ui', 'marketplace').pipe(shareReplay()) + > = this.patch.watch$('ui', 'marketplace').pipe(shareReplay(1)) private readonly marketplace$ = this.altMarketplaceData$.pipe( map(data => this.toMarketplace(data)), @@ -51,7 +51,7 @@ export class MarketplaceService extends AbstractMarketplaceService { ), ), map(({ categories }) => categories), - shareReplay(), + shareReplay(1), ) private readonly pkg$: Observable = @@ -74,7 +74,7 @@ export class MarketplaceService extends AbstractMarketplaceService { return of([]) }), - shareReplay(), + shareReplay(1), ) constructor( @@ -149,7 +149,6 @@ export class MarketplaceService extends AbstractMarketplaceService { req: Omit, ): Observable { return this.getMarketplace().pipe( - take(1), switchMap(({ url }) => from( this.api.installPackage({ From c144597c07fc6b5bc3231e544361f2987b2c5d11 Mon Sep 17 00:00:00 2001 From: Lucy Cifferello <12953208+elvece@users.noreply.github.com> Date: Wed, 22 Jun 2022 15:25:26 -0600 Subject: [PATCH 6/7] allow for subscription to end with take when installing a package --- frontend/projects/ui/src/app/services/marketplace.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/projects/ui/src/app/services/marketplace.service.ts b/frontend/projects/ui/src/app/services/marketplace.service.ts index 6bcb6cb920..09e61c3cb0 100644 --- a/frontend/projects/ui/src/app/services/marketplace.service.ts +++ b/frontend/projects/ui/src/app/services/marketplace.service.ts @@ -149,6 +149,7 @@ export class MarketplaceService extends AbstractMarketplaceService { req: Omit, ): Observable { return this.getMarketplace().pipe( + take(1), switchMap(({ url }) => from( this.api.installPackage({ From 5ab24eca5a7e504d157dfb4a1e62daa0f21541b0 Mon Sep 17 00:00:00 2001 From: Lucy Cifferello <12953208+elvece@users.noreply.github.com> Date: Wed, 22 Jun 2022 15:25:55 -0600 Subject: [PATCH 7/7] update patchdb --- patch-db | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patch-db b/patch-db index e138b88e75..9a28793f27 160000 --- a/patch-db +++ b/patch-db @@ -1 +1 @@ -Subproject commit e138b88e75086acd5dc006a901cab7d665c56097 +Subproject commit 9a28793f2788ac7506d3d31793c49f78485dd4a2