Seed patchdb UI data (#1835)

* adjust types
for patchdb ui data and create seed file

* feat: For init and the migration use defaults

* fix update path

* update build for ui seed file

* fix accidential revert

* chore: Convert to do during the init

* chore: Update the commit message

Co-authored-by: BluJ <mogulslayer@gmail.com>
This commit is contained in:
Lucy C
2022-09-26 17:36:37 -06:00
committed by GitHub
parent 31c5aebe90
commit 1702c07481
13 changed files with 113 additions and 67 deletions

View File

@@ -0,0 +1,17 @@
{
"name": null,
"auto-check-updates": true,
"pkg-order": [],
"ack-welcome": "0.3.0",
"marketplace": {
"selected-id": null,
"known-hosts": {}
},
"dev": {},
"gaming": {
"snake": {
"high-score": 0
}
},
"ack-instructions": {}
}

View File

@@ -39,8 +39,8 @@ export class SnekDirective {
try {
await this.embassyApi.setDbValue({
pointer: '/gaming',
value: { snake: { 'high-score': data.highScore } },
pointer: '/gaming/snake/high-score',
value: data.highScore,
})
} catch (e: any) {
this.errToast.present(e)

View File

@@ -49,7 +49,7 @@ export class DeveloperListPage {
}
async openCreateProjectModal() {
const projNumber = Object.keys(this.devData || {}).length + 1
const projNumber = Object.keys(this.devData).length + 1
const options: GenericInputOptions = {
title: 'Add new project',
message: 'Create a new dev project.',
@@ -130,7 +130,7 @@ export class DeveloperListPage {
async createProject(name: string) {
// fail silently if duplicate project name
if (
Object.values(this.devData || {})
Object.values(this.devData)
.map(v => v.name)
.includes(name)
)
@@ -148,11 +148,7 @@ export class DeveloperListPage {
.replace(/warning:/g, '# Optional\n warning:')
const def = { name, config, instructions: SAMPLE_INSTUCTIONS }
if (this.devData) {
await this.api.setDbValue({ pointer: `/dev/${id}`, value: def })
} else {
await this.api.setDbValue({ pointer: `/dev`, value: { [id]: def } })
}
await this.api.setDbValue({ pointer: `/dev/${id}`, value: def })
} catch (e: any) {
this.errToast.present(e)
} finally {

View File

@@ -66,7 +66,7 @@ export class MarketplacesPage {
this.patch
.watch$('ui', 'marketplace')
.pipe(distinctUntilChanged(), takeUntil(this.destroy$))
.subscribe((mp: UIMarketplaceData | undefined) => {
.subscribe((mp: UIMarketplaceData) => {
let marketplaces: Marketplaces = [
{
id: null,
@@ -74,17 +74,15 @@ export class MarketplacesPage {
url: this.config.marketplace.url,
},
]
if (mp) {
this.selectedId = mp['selected-id']
const alts = Object.entries(mp['known-hosts']).map(([k, v]) => {
return {
id: k,
name: v.name,
url: v.url,
}
})
marketplaces = marketplaces.concat(alts)
}
this.selectedId = mp['selected-id']
const alts = Object.entries(mp['known-hosts']).map(([k, v]) => {
return {
id: k,
name: v.name,
url: v.url,
}
})
marketplaces = marketplaces.concat(alts)
this.marketplaces = marketplaces
})
}

View File

@@ -23,6 +23,12 @@ export const mockPatchData: DataModel = {
},
},
},
dev: {},
gaming: {
snake: {
'high-score': 0,
},
},
'ack-instructions': {},
},
'server-info': {

View File

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

View File

@@ -11,13 +11,13 @@ export interface DataModel {
}
export interface UIData {
name: string
name: string | null
'auto-check-updates': boolean
'pkg-order': string[]
'ack-welcome': string // EOS version
marketplace?: UIMarketplaceData
dev?: DevData
gaming?: {
'ack-welcome': string // EOS emver
marketplace: UIMarketplaceData
dev: DevData
gaming: {
snake: {
'high-score': number
}

View File

@@ -8,15 +8,5 @@ import { firstValueFrom, map } from 'rxjs'
export function getMarketplace(
patch: PatchDB<DataModel>,
): Promise<UIMarketplaceData> {
return firstValueFrom(
patch.watch$('ui', 'marketplace').pipe(
map(
m =>
m || {
'selected-id': null,
'known-hosts': {},
},
),
),
)
return firstValueFrom(patch.watch$('ui', 'marketplace'))
}