refactor: packageprovider
This commit is contained in:
@@ -1,19 +1,14 @@
|
|||||||
import { WebApplication } from '@/Application/WebApplication'
|
import { GetFeatures } from '@standardnotes/snjs'
|
||||||
import { ClientDisplayableError, FeatureDescription } from '@standardnotes/snjs'
|
|
||||||
import { makeAutoObservable, observable } from 'mobx'
|
import { makeAutoObservable, observable } from 'mobx'
|
||||||
import { AnyPackageType } from '../Types/AnyPackageType'
|
import { AnyPackageType } from '../Types/AnyPackageType'
|
||||||
|
|
||||||
export class PackageProvider {
|
export class PackageProvider {
|
||||||
static async load(application: WebApplication): Promise<PackageProvider | undefined> {
|
static async load(): Promise<PackageProvider | undefined> {
|
||||||
const response = await application.getAvailableSubscriptions()
|
|
||||||
|
|
||||||
if (!response || response instanceof ClientDisplayableError) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
const versionMap: Map<string, string> = new Map()
|
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)
|
return new PackageProvider(versionMap)
|
||||||
}
|
}
|
||||||
@@ -28,13 +23,3 @@ export class PackageProvider {
|
|||||||
return this.latestVersionsMap.get(extension.package_info.identifier)
|
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')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export class PreferencesMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private loadLatestVersions(): void {
|
private loadLatestVersions(): void {
|
||||||
PackageProvider.load(this.application)
|
PackageProvider.load()
|
||||||
.then((versions) => {
|
.then((versions) => {
|
||||||
if (versions) {
|
if (versions) {
|
||||||
this._extensionLatestVersions = versions
|
this._extensionLatestVersions = versions
|
||||||
|
|||||||
Reference in New Issue
Block a user