|
10 | 10 |
|
11 | 11 | let adventures: Adventure[] = []; |
12 | 12 |
|
| 13 | + let isLoading: boolean = true; |
| 14 | +
|
13 | 15 | export let user: User | null; |
14 | 16 |
|
15 | 17 | onMount(async () => { |
16 | 18 | modal = document.getElementById('my_modal_1') as HTMLDialogElement; |
17 | 19 | if (modal) { |
18 | 20 | modal.showModal(); |
19 | 21 | } |
20 | | - let formData = new FormData(); |
21 | | - formData.append('include_collections', 'false'); |
22 | | - let res = await fetch(`/adventures?/all`, { |
23 | | - method: 'POST', |
24 | | - body: formData |
| 22 | + let res = await fetch(`/api/adventures/all/?include_collections=false`, { |
| 23 | + method: 'GET' |
25 | 24 | }); |
26 | 25 |
|
27 | | - const result: ActionResult = deserialize(await res.text()); |
28 | | - console.log(result); |
| 26 | + const newAdventures = await res.json(); |
29 | 27 |
|
30 | | - if (result.type === 'success' && result.data) { |
31 | | - adventures = result.data.adventures as Adventure[]; |
| 28 | + if (res.ok && adventures) { |
| 29 | + adventures = newAdventures; |
32 | 30 | } |
| 31 | + isLoading = false; |
33 | 32 | }); |
34 | 33 |
|
35 | 34 | function close() { |
|
53 | 52 | <!-- svelte-ignore a11y-no-noninteractive-tabindex --> |
54 | 53 | <div class="modal-box w-11/12 max-w-5xl" role="dialog" on:keydown={handleKeydown} tabindex="0"> |
55 | 54 | <h1 class="text-center font-bold text-4xl mb-6">My Adventures</h1> |
| 55 | + {#if isLoading} |
| 56 | + <div class="flex justify-center items-center w-full mt-16"> |
| 57 | + <span class="loading loading-spinner w-24 h-24"></span> |
| 58 | + </div> |
| 59 | + {/if} |
56 | 60 | <div class="flex flex-wrap gap-4 mr-4 justify-center content-center"> |
57 | 61 | {#each adventures as adventure} |
58 | 62 | <AdventureCard user={user ?? null} type="link" {adventure} on:link={add} /> |
59 | 63 | {/each} |
60 | | - {#if adventures.length === 0} |
| 64 | + {#if adventures.length === 0 && !isLoading} |
61 | 65 | <p class="text-center text-lg"> |
62 | 66 | No adventures found that can be linked to this collection. |
63 | 67 | </p> |
|
0 commit comments