mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-03-28 17:42:40 +01:00
#200 - media file sorting fix
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
### 🐞 Fixes
|
||||
|
||||
- [#191](https://github.com/estruyf/vscode-front-matter/issues/191): Fix beta settings page
|
||||
- [#200](https://github.com/estruyf/vscode-front-matter/issues/200): Fix last modified date sorting for media files
|
||||
- [#201](https://github.com/estruyf/vscode-front-matter/issues/201): Fix overflow issue with the media filename
|
||||
- [#202](https://github.com/estruyf/vscode-front-matter/issues/202): Fix checkbox label color for light themes
|
||||
|
||||
|
||||
@@ -434,7 +434,7 @@ export class Dashboard {
|
||||
if (crntSort?.type === SortType.string) {
|
||||
allMedia = allMedia.sort(Sorting.alphabetically("fsPath"));
|
||||
} else if (crntSort?.type === SortType.date) {
|
||||
allMedia = allMedia.sort(Sorting.date("mtime"));
|
||||
allMedia = allMedia.sort(Sorting.dateWithFallback("mtime", "fsPath"));
|
||||
} else {
|
||||
allMedia = allMedia.sort(Sorting.alphabetically("fsPath"));
|
||||
}
|
||||
|
||||
@@ -34,6 +34,31 @@ export class Sorting {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Sort by date with a fallback
|
||||
* @param property
|
||||
* @returns
|
||||
*/
|
||||
public static dateWithFallback = (property: string, fallback: string) => {
|
||||
return (a: any, b: any) => {
|
||||
const dateA = DateHelper.tryParse(a[property]);
|
||||
const dateB = DateHelper.tryParse(b[property]);
|
||||
|
||||
// Sort by date
|
||||
var dCount = (dateA || new Date(0)).getTime() - (dateB || new Date(0)).getTime();
|
||||
if(dCount) return dCount;
|
||||
|
||||
// If there is a tie, sort by fallback property
|
||||
if (a[fallback] < b[fallback]) {
|
||||
return -1;
|
||||
}
|
||||
if (a[fallback] > b[fallback]) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Sort by number
|
||||
* @param property
|
||||
|
||||
Reference in New Issue
Block a user