From 894ad9aaa680f4d95855731c1ffc5697b5b69952 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Wed, 5 Feb 2025 22:14:57 +0100 Subject: [PATCH] Racepicks: Use Promise.all for nested {#await} blocks --- src/routes/racepicks/+page.svelte | 358 ++++++++++++++---------------- 1 file changed, 164 insertions(+), 194 deletions(-) diff --git a/src/routes/racepicks/+page.svelte b/src/routes/racepicks/+page.svelte index b76e3eb..d253fc8 100644 --- a/src/routes/racepicks/+page.svelte +++ b/src/routes/racepicks/+page.svelte @@ -128,85 +128,73 @@ {#if data.user} - {#await data.graphics then graphics} - {#await data.drivers then drivers} - {#await racepick then pick} -
-
-

Your P{data.currentrace.pxx} Pick:

- -
-
-

Your DNF Pick:

- -
-
- {/await} - {/await} + {#await Promise.all( [data.graphics, data.drivers, racepick], ) then [graphics, drivers, pick]} +
+
+

Your P{data.currentrace.pxx} Pick:

+ +
+
+

Your DNF Pick:

+ +
+
{/await} {/if} - {#await data.currentpickedusers then currentpicked} + {#await Promise.all( [data.graphics, data.currentpickedusers, pickedusers, outstandingusers], ) then [graphics, currentpicked, picked, outstanding]}
- {#await pickedusers then picked} -
-

- Picked ({picked.length}/{currentpicked.length}): -

-
- {#await data.graphics then graphics} - {#each picked.slice(0, 16) as user} - - {/each} - {/await} -
+
+

+ Picked ({picked.length}/{currentpicked.length}): +

+
+ {#each picked.slice(0, 16) as user} + + {/each}
- {/await} - {#await outstandingusers then outstanding} -
-

- Outstanding ({outstanding.length}/{currentpicked.length}): -

-
- {#await data.graphics then graphics} - {#each outstanding.slice(0, 16) as user} - - {/each} - {/await} -
+
+
+

+ Outstanding ({outstanding.length}/{currentpicked.length}): +

+
+ {#each outstanding.slice(0, 16) as user} + + {/each}
- {/await} +
{/await}
@@ -259,137 +247,119 @@
- {#await data.races then races} - {#await data.raceresults then raceresults} - {#each raceresults as result} - {@const race = get_by_value(races, "id", result.race)} + {#await Promise.all( [data.races, data.raceresults, data.drivers], ) then [races, raceresults, drivers]} + {#each raceresults as result} + {@const race = get_by_value(races, "id", result.race)} -
- - - {race?.name.slice(0, 8)}{(race?.name.length ?? 8) > 8 ? "." : ""} - - - +
+ + + {race?.name.slice(0, 8)}{(race?.name.length ?? 8) > 8 ? "." : ""} + + + +
+ + +
+ Result: +
+ {#each result.pxxs as pxx, index} + {@const driver = get_by_value(drivers, "id", pxx)} +
+ P{(race?.pxx ?? -100) - 3 + index}: + + {driver?.code} + +
+ {/each} + + {#if result.dnfs.length > 0} +
+ {/if} + + {#each result.dnfs as dnf} + {@const driver = get_by_value(drivers, "id", dnf)} +
+ DNF: + + {driver?.code} + +
+ {/each}
- - -
- Result: -
- {#await data.drivers then drivers} - {#each result.pxxs as pxx, index} - {@const driver = get_by_value(drivers, "id", pxx)} -
- P{(race?.pxx ?? -100) - 3 + index}: - - {driver?.code} - -
- {/each} - - {#if result.dnfs.length > 0} -
- {/if} - - {#each result.dnfs as dnf} - {@const driver = get_by_value(drivers, "id", dnf)} -
- DNF: - - {driver?.code} - -
- {/each} - {/await} -
-
- {/each} - {/await} +
+ {/each} {/await}
- - {#await data.currentpickedusers then currentpicked} - {#await data.racepicks then racepicks} - {#await data.races then races} - {#await data.drivers then drivers} - {#await data.raceresults then raceresults} - {#each currentpicked as user} - {@const picks = racepicks.filter((pick: RacePick) => pick.user === user.id)} + {#await Promise.all( [data.currentpickedusers, data.racepicks, data.races, data.drivers, data.raceresults], ) then [currentpicked, racepicks, races, drivers, raceresults]} + {#each currentpicked as user} + {@const picks = racepicks.filter((pick: RacePick) => pick.user === user.id)} -
- -
- {#await data.graphics then graphics} - - {/await} - -
- - {#each raceresults as result} - {@const race = get_by_value(races, "id", result.race)} - {@const pick = picks.filter((pick: RacePick) => pick.race === race?.id)[0]} - {@const pxxcolor = PXX_COLORS[result.pxxs.indexOf(pick?.pxx ?? "Invalid")]} - {@const dnfcolor = - result.dnfs.indexOf(pick?.dnf ?? "Invalid") >= 0 - ? PXX_COLORS[3] - : PXX_COLORS[-1]} - - {#if pick} -
-
- - {get_by_value(drivers, "id", pick?.pxx ?? "")?.code} - - - {get_by_value(drivers, "id", pick?.dnf ?? "")?.code} - -
-
- {:else} -
- {/if} - {/each} -
- {/each} +
+ +
+ {#await data.graphics then graphics} + {/await} - {/await} - {/await} - {/await} + +
+ + {#each raceresults as result} + {@const race = get_by_value(races, "id", result.race)} + {@const pick = picks.filter((pick: RacePick) => pick.race === race?.id)[0]} + {@const pxxcolor = PXX_COLORS[result.pxxs.indexOf(pick?.pxx ?? "Invalid")]} + {@const dnfcolor = + result.dnfs.indexOf(pick?.dnf ?? "Invalid") >= 0 ? PXX_COLORS[3] : PXX_COLORS[-1]} + + {#if pick} +
+
+ + {get_by_value(drivers, "id", pick?.pxx ?? "")?.code} + + + {get_by_value(drivers, "id", pick?.dnf ?? "")?.code} + +
+
+ {:else} +
+ {/if} + {/each} +
+ {/each} {/await}