refactor: packageprovider

This commit is contained in:
Aman Harwara
2023-06-25 23:53:23 +05:30
parent 7c3b8d4534
commit 046eaac548
2 changed files with 7 additions and 22 deletions

View File

@@ -1,19 +1,14 @@
import { WebApplication } from '@/Application/WebApplication'
import { ClientDisplayableError, FeatureDescription } from '@standardnotes/snjs'
import { GetFeatures } from '@standardnotes/snjs'
import { makeAutoObservable, observable } from 'mobx'
import { AnyPackageType } from '../Types/AnyPackageType'
export class PackageProvider {
static async load(application: WebApplication): Promise<PackageProvider | undefined> {
const response = await application.getAvailableSubscriptions()
if (!response || response instanceof ClientDisplayableError) {
return undefined
}
static async load(): Promise<PackageProvider | undefined> {
const versionMap: Map<string, string> = new Map()
collectFeatures(response.PLUS_PLAN?.features as FeatureDescription[], versionMap)
collectFeatures(response.PRO_PLAN?.features as FeatureDescription[], versionMap)
GetFeatures().forEach((feature) => {
versionMap.set(feature.identifier, 'Latest')
})
return new PackageProvider(versionMap)
}
@@ -28,13 +23,3 @@ export class PackageProvider {
return this.latestVersionsMap.get(extension.package_info.identifier)
}
}
function collectFeatures(features: FeatureDescription[] | undefined, versionMap: Map<string, string>) {
if (features == undefined) {
return
}
for (const feature of features) {
versionMap.set(feature.identifier, 'Latest')
}
}

View File

@@ -67,7 +67,7 @@ export class PreferencesMenu {
}
private loadLatestVersions(): void {
PackageProvider.load(this.application)
PackageProvider.load()
.then((versions) => {
if (versions) {
this._extensionLatestVersions = versions