timestamp sorting

This commit is contained in:
Aaron Greenspan
2021-01-13 18:02:00 -07:00
committed by Aiden McClelland
parent 90b412384a
commit d7508345eb
3 changed files with 10 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ export interface BaseApp {
export interface AppAvailablePreview extends BaseApp {
versionLatest: string
descriptionShort: string
latestVersionTimestamp: Date
}
export type AppAvailableFull =

View File

@@ -74,7 +74,9 @@ export class AppAvailableListPage {
async getApps (): Promise<void> {
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) {

View File

@@ -83,7 +83,12 @@ export class LiveApiService extends ApiService {
}
async getAvailableApps (): Promise<AppAvailablePreview[]> {
return this.authRequest<ReqRes.GetAppsAvailableRes>({ method: Method.GET, url: '/apps/store' })
const res = await this.authRequest<ReqRes.GetAppsAvailableRes>({ 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<AppAvailableFull> {