1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-19 21:09:37 +02:00

fix(collections): ensure linked collections are sorted correctly after fetching

This commit is contained in:
Sean Morley 2025-06-14 22:16:39 -04:00
parent 977843cbc6
commit c2074c1581

View file

@ -16,15 +16,26 @@
if (modal) { if (modal) {
modal.showModal(); modal.showModal();
} }
let res = await fetch(`/api/collections/all/`, { let res = await fetch(`/api/collections/all/`, {
method: 'GET' method: 'GET'
}); });
let result = await res.json(); let result = await res.json();
collections = result as Collection[];
if (result.type === 'success' && result.data) { if (result.type === 'success' && result.data) {
collections = result.data.adventures as Collection[]; collections = result.data.adventures as Collection[];
} else {
collections = result as Collection[];
}
// Move linked collections to the front
if (linkedCollectionList) {
collections.sort((a, b) => {
const aLinked = linkedCollectionList?.includes(a.id);
const bLinked = linkedCollectionList?.includes(b.id);
return aLinked === bLinked ? 0 : aLinked ? -1 : 1;
});
} }
}); });