fix mrketplace swtiching (#1810)

This commit is contained in:
Matt Hill
2022-09-19 12:59:29 -06:00
committed by GitHub
parent 53463077df
commit f04b90d9c6
6 changed files with 21 additions and 14 deletions

View File

@@ -65,7 +65,9 @@ export class AppConfigPage {
async ngOnInit() {
try {
this.pkg = await getPackage(this.patch, this.pkgId)
const pkg = await getPackage(this.patch, this.pkgId)
if (!pkg) return
this.pkg = pkg
if (!this.pkg.manifest.config) return

View File

@@ -34,6 +34,8 @@ export class AppInterfacesPage {
async ngOnInit() {
const pkg = await getPackage(this.patch, this.pkgId)
if (!pkg) return
const interfaces = pkg.manifest.interfaces
const uiKey = getUiInterfaceKey(interfaces)

View File

@@ -117,7 +117,6 @@ export class MarketplacesPage {
async presentAction(id: string | null) {
// no need to view actions if is selected marketplace
const marketplace = await getMarketplace(this.patch)
if (id === marketplace['selected-id']) return
const buttons: ActionSheetButton[] = [

View File

@@ -37,11 +37,13 @@ export class MarketplaceService extends AbstractMarketplaceService {
private readonly uiMarketplaceData$ = this.patch
.watch$('ui', 'marketplace')
.pipe(
filter(Boolean),
startWith({
'selected-id': null,
'known-hosts': {},
}),
map(
m =>
m || {
'selected-id': null,
'known-hosts': {},
},
),
distinctUntilChanged(
(prev, curr) => prev['selected-id'] === curr['selected-id'],
),

View File

@@ -3,18 +3,20 @@ import {
DataModel,
UIMarketplaceData,
} from 'src/app/services/patch-db/data-model'
import { filter, firstValueFrom, startWith } from 'rxjs'
import { firstValueFrom, map } from 'rxjs'
export function getMarketplace(
patch: PatchDB<DataModel>,
): Promise<UIMarketplaceData> {
return firstValueFrom(
patch.watch$('ui', 'marketplace').pipe(
filter(Boolean),
startWith({
'selected-id': null,
'known-hosts': {},
}),
map(
m =>
m || {
'selected-id': null,
'known-hosts': {},
},
),
),
)
}

View File

@@ -8,7 +8,7 @@ import { filter, firstValueFrom } from 'rxjs'
export function getPackage(
patch: PatchDB<DataModel>,
id: string,
): Promise<PackageDataEntry> {
): Promise<PackageDataEntry | undefined> {
return firstValueFrom(patch.watch$('package-data', id))
}