From a218d099601751b51f6349da854cf96ccc2ea46b Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sat, 5 Oct 2024 10:49:28 +0530 Subject: [PATCH] Tweak --- web/packages/new/photos/services/files.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/web/packages/new/photos/services/files.ts b/web/packages/new/photos/services/files.ts index ae9c71c81d..0c48c7b449 100644 --- a/web/packages/new/photos/services/files.ts +++ b/web/packages/new/photos/services/files.ts @@ -38,9 +38,18 @@ export const setLocalFiles = async ( await localForage.setItem(tableName, files); }; -export function sortFiles(files: EnteFile[], sortAsc = false) { - // sort based on the time of creation time of the file, - // for files with same creation time, sort based on the time of last modification +/** + * Sort the given list of {@link EnteFile}s. + * + * By default, files are sorted so that the newest one is first. The optional + * {@link sortAsc} flag can be set to `true` to sort them so that the oldest one + * is first. + */ +export const sortFiles = (files: EnteFile[], sortAsc = false) => { + // Sort based on the time of creation time of the file. + // + // For files with same creation time, sort based on the time of last + // modification. const factor = sortAsc ? -1 : 1; return files.sort((a, b) => { if (a.metadata.creationTime === b.metadata.creationTime) { @@ -51,8 +60,7 @@ export function sortFiles(files: EnteFile[], sortAsc = false) { } return factor * (b.metadata.creationTime - a.metadata.creationTime); }); -} - +}; export const TRASH = "file-trash";