From c2074c1581bb2bd1ec0d309c98d26fb9449003c5 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Sat, 14 Jun 2025 22:16:39 -0400 Subject: [PATCH] fix(collections): ensure linked collections are sorted correctly after fetching --- frontend/src/lib/components/CollectionLink.svelte | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/components/CollectionLink.svelte b/frontend/src/lib/components/CollectionLink.svelte index 75546a8..7f6ab0c 100644 --- a/frontend/src/lib/components/CollectionLink.svelte +++ b/frontend/src/lib/components/CollectionLink.svelte @@ -16,15 +16,26 @@ if (modal) { modal.showModal(); } + let res = await fetch(`/api/collections/all/`, { method: 'GET' }); let result = await res.json(); - collections = result as Collection[]; if (result.type === 'success' && result.data) { 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; + }); } });