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:
parent
977843cbc6
commit
c2074c1581
1 changed files with 12 additions and 1 deletions
|
@ -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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue