Skip to content

Commit

Permalink
Sort area names based on numbers when starting with a number.
Browse files Browse the repository at this point in the history
But main lights are always first. #892
  • Loading branch information
theyosh committed Mar 14, 2024
1 parent ea12bef commit e8a800d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions gui/helpers/string-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,15 @@ export const enclosureNameSort = (a, b) => {
// Normal text compare
return a.localeCompare(b);
};

export const areaObjectSort = (a, b) => {
// Main lights area always first
if (a.type === 'lights' && a.setup.main_lights) {
return -1;
} else if (b.type === 'lights' && a.setup.main_lights) {
return 1;
}

// Normal text compare
return enclosureNameSort(a.name, b.name);
}
4 changes: 2 additions & 2 deletions gui/user-controls/EnclosureCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { fancyAppsLanguage } from '../constants/ui';
import { updateButton, isDarkInterface } from '../stores/terrariumpi';
import { isAuthenticated } from '../stores/authentication';
import { externalLinks } from '../helpers/string-helpers';
import { externalLinks, areaObjectSort } from '../helpers/string-helpers';
import Card from '../user-controls/Card.svelte';
import CardSettingsTools from '../components/common/CardSettingsTools.svelte';
Expand Down Expand Up @@ -92,7 +92,7 @@
</tr>
</thead>
<tbody>
{#each enclosure.areas.sort((a, b) => a.name.localeCompare(b.name)) as area}
{#each enclosure.areas.sort((a, b) => areaObjectSort(a,b)) as area}
<tr>
<td>
{area.name}
Expand Down

0 comments on commit e8a800d

Please sign in to comment.