feat: model ordering

This commit is contained in:
Timothy J. Baek
2024-05-31 13:11:04 -07:00
parent 9c67a94542
commit fc2b314c4f
4 changed files with 84 additions and 7 deletions

View File

@@ -29,8 +29,24 @@ export const getModels = async (token: string = '') => {
models = models
.filter((models) => models)
// Sort the models
.sort((a, b) => {
// Compare case-insensitively
// Check if models have position property
const aHasPosition = a.info?.meta?.position !== undefined;
const bHasPosition = b.info?.meta?.position !== undefined;
// If both a and b have the position property
if (aHasPosition && bHasPosition) {
return a.info.meta.position - b.info.meta.position;
}
// If only a has the position property, it should come first
if (aHasPosition) return -1;
// If only b has the position property, it should come first
if (bHasPosition) return 1;
// Compare case-insensitively by name for models without position property
const lowerA = a.name.toLowerCase();
const lowerB = b.name.toLowerCase();
@@ -39,8 +55,8 @@ export const getModels = async (token: string = '') => {
// If same case-insensitively, sort by original strings,
// lowercase will come before uppercase due to ASCII values
if (a < b) return -1;
if (a > b) return 1;
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
return 0; // They are equal
});