From d7508345eb85ecc5476650d6ac8c1a705c8dfde6 Mon Sep 17 00:00:00 2001 From: Aaron Greenspan Date: Wed, 13 Jan 2021 18:02:00 -0700 Subject: [PATCH] timestamp sorting --- ui/src/app/models/app-types.ts | 1 + .../app-available-list/app-available-list.page.ts | 4 +++- ui/src/app/services/api/live-api.service.ts | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ui/src/app/models/app-types.ts b/ui/src/app/models/app-types.ts index a73503af5..6fd9caab2 100644 --- a/ui/src/app/models/app-types.ts +++ b/ui/src/app/models/app-types.ts @@ -14,6 +14,7 @@ export interface BaseApp { export interface AppAvailablePreview extends BaseApp { versionLatest: string descriptionShort: string + latestVersionTimestamp: Date } export type AppAvailableFull = diff --git a/ui/src/app/pages/apps-routes/app-available-list/app-available-list.page.ts b/ui/src/app/pages/apps-routes/app-available-list/app-available-list.page.ts index 912931566..9c3eb5852 100644 --- a/ui/src/app/pages/apps-routes/app-available-list/app-available-list.page.ts +++ b/ui/src/app/pages/apps-routes/app-available-list/app-available-list.page.ts @@ -74,7 +74,9 @@ export class AppAvailableListPage { async getApps (): Promise { try { this.apps = await this.apiService.getAvailableApps().then(apps => - apps.map(a => ({ id: a.id, subject: initPropertySubject(a) })), + apps + .sort( (a1, a2) => a2.latestVersionTimestamp.getTime() - a1.latestVersionTimestamp.getTime()) + .map(a => ({ id: a.id, subject: initPropertySubject(a) })), ) this.appModel.getContents().forEach(appInstalled => this.mergeInstalledProps(appInstalled.id)) } catch (e) { diff --git a/ui/src/app/services/api/live-api.service.ts b/ui/src/app/services/api/live-api.service.ts index e46de10b0..236934814 100644 --- a/ui/src/app/services/api/live-api.service.ts +++ b/ui/src/app/services/api/live-api.service.ts @@ -83,7 +83,12 @@ export class LiveApiService extends ApiService { } async getAvailableApps (): Promise { - return this.authRequest({ method: Method.GET, url: '/apps/store' }) + const res = await this.authRequest({ method: Method.GET, url: '/apps/store' }) + return res.map(a => { + const latestVersionTimestamp = new Date(a.latestVersionTimestamp) + if (isNaN(latestVersionTimestamp as any)) throw new Error(`Invalid latestVersionTimestamp ${a.latestVersionTimestamp}`) + return { ...a, latestVersionTimestamp } + }) } async getAvailableApp (appId: string): Promise {