Files
standardnotes-app-web/app/assets/javascripts/preferences/panes/extensions-segments/ExtensionsLatestVersions.ts
Gorjan Petrovski 31222e1236 feat(preferences): extension modals into extension panes (#683)
* feat(preferences): show inline extensions in extensions pane

* wip

* wip

* refactor: convert ComponentView to React component

* refactor: convert ComponentView to React component

* chore: fix merge conflicts

* feat: don't show features whose `area` is "room", update modal items' icons in Preferences menu

* chore: fix TS error

* feat: don't show 2FA Manager in modal-based component

* feat: remove `ExtendedDataReloadComplete` event, since Extensions Manger is being removed from the app

* chore: avoid hardcoded values in svg image, optimize `if` condition

* chore: remove remnant comment

* fix: fix typescript errors

Co-authored-by: vardanhakobyan <vardan_live@live.com>
2021-10-25 12:45:36 +04:00

36 lines
1.4 KiB
TypeScript

import { WebApplication } from "@/ui_models/application";
import { FeatureDescription } from "@standardnotes/features";
import { SNComponent } from "@standardnotes/snjs/dist/@types";
import { makeAutoObservable, observable } from "mobx";
export class ExtensionsLatestVersions {
static async load(application: WebApplication): Promise<ExtensionsLatestVersions> {
const map = await application.getAvailableSubscriptions()
.then(subscriptions => {
const versionMap: Map<string, string> = new Map();
collectFeatures(subscriptions?.CORE_PLAN?.features as FeatureDescription[], versionMap);
collectFeatures(subscriptions?.PLUS_PLAN?.features as FeatureDescription[], versionMap);
collectFeatures(subscriptions?.PRO_PLAN?.features as FeatureDescription[], versionMap);
return versionMap;
});
return new ExtensionsLatestVersions(map);
}
constructor(private readonly latestVersionsMap: Map<string, string>) {
makeAutoObservable<ExtensionsLatestVersions, 'latestVersionsMap'>(
this, { latestVersionsMap: observable.ref });
}
getVersion(extension: SNComponent): string | undefined {
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, feature.version);
}
}