From 8e996683eaa9de7e24922c4088258fd8b8202a87 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sun, 10 Apr 2022 20:04:29 -0700 Subject: [PATCH] Sort thumbnails most recent to least recent. --- src/components/timeline.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/timeline.ts b/src/components/timeline.ts index b42af0f0..6d8459a1 100644 --- a/src/components/timeline.ts +++ b/src/components/timeline.ts @@ -521,10 +521,26 @@ export class FrigateCardTimelineCore extends LitElement { return; } + /** + * Sort the timeline items most recent to least recent. + * @param a The first item. + * @param b The second item. + * @returns -1, 0, 1 (standard array sort function configuration). + */ + const sortEvent = (a: FrigateCardTimelineItem, b: FrigateCardTimelineItem): number => { + if (a.start < b.start) { + return 1; + } + if (a.start > b.start) { + return -1; + } + return 0; + } + const selected = this._timeline.getSelection(); let childIndex = -1; const children: FrigateBrowseMediaSource[] = []; - this._events.dataset.get({ order: 'start' }).forEach((item) => { + this._events.dataset.get({ order: sortEvent }).forEach((item) => { if (this.timelineConfig) { let added = false; if (