Skip to content

Commit 3b39362

Browse files
feat(tracker): add loading skeleton in the tracker
1 parent aa2a890 commit 3b39362

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

src/routes/tracker/[org]/[repo]/+layout.svelte

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script lang="ts">
22
import { onNavigate } from "$app/navigation";
3-
import { page } from "$app/state";
4-
import { Menu } from "@lucide/svelte";
3+
import { navigating, page } from "$app/state";
4+
import { LoaderCircle, Menu } from "@lucide/svelte";
55
import { uniqueRepos } from "$lib/repositories";
66
import { Button } from "$lib/components/ui/button";
77
import * as Sheet from "$lib/components/ui/sheet";
8+
import { Skeleton } from "$lib/components/ui/skeleton";
89
import RepoSidePanel from "./RepoSidePanel.svelte";
910
1011
let { children } = $props();
@@ -15,6 +16,18 @@
1516
});
1617
1718
let open = $state(false);
19+
20+
/**
21+
* The classic function that generates a random integer
22+
* between the specified minimum and maximum values, inclusive.
23+
*
24+
* @param min - The minimum value in the range.
25+
* @param max - The maximum value in the range.
26+
* @returns A random integer within the range [min, max].
27+
*/
28+
function random(min: number, max: number) {
29+
return Math.floor(Math.random() * (max - min + 1)) + min;
30+
}
1831
</script>
1932

2033
{#snippet repoList()}
@@ -39,9 +52,32 @@
3952
{/snippet}
4053

4154
<div class="relative flex gap-8">
42-
<div class="min-w-0">
43-
{@render children()}
44-
</div>
55+
{#if navigating.to}
56+
<div class="flex w-full flex-col">
57+
<div class="mt-8 space-y-2">
58+
<Skeleton class="h-16 w-72" />
59+
<Skeleton class="h-8 w-56" />
60+
</div>
61+
<div class="relative w-full space-y-2">
62+
<p
63+
class="absolute top-44 left-1/2 z-10 inline-flex -translate-x-1/2 -translate-y-1/2 justify-center text-xl"
64+
>
65+
<LoaderCircle class="mr-2 h-lh shrink-0 animate-spin" />
66+
Gathering all the data, this may take some time...
67+
</p>
68+
{#each Array(3), i (i)}
69+
<Skeleton class="mt-16 mb-4 h-12 w-52" />
70+
{#each Array(random(1, 6)), j (j)}
71+
<Skeleton class="h-24 w-full" />
72+
{/each}
73+
{/each}
74+
</div>
75+
</div>
76+
{:else}
77+
<div class="min-w-0">
78+
{@render children()}
79+
</div>
80+
{/if}
4581

4682
<Sheet.Root bind:open>
4783
<Sheet.Trigger>

src/routes/tracker/[org]/[repo]/+page.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export async function load({ params }) {
2727
githubCache.getAllDiscussions(params.org, params.repo)
2828
]);
2929
return {
30+
params,
3031
prs: unfilteredPRs
3132
.filter(({ user, body, updated_at }) => {
3233
if (new Date(updated_at).getFullYear() < now.getFullYear() - 1) return false;

src/routes/tracker/[org]/[repo]/+page.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts">
2-
import { page } from "$app/state";
32
import { Image, Info } from "@lucide/svelte";
43
import { Transparent } from "svelte-exmarkdown";
54
import { buttonVariants } from "$lib/components/ui/button";
@@ -146,13 +145,13 @@
146145
<div class="my-8">
147146
<h1 class="text-3xl font-semibold text-shadow-sm md:text-5xl">
148147
<a
149-
href="https://github.com/{page.params.org}/{page.params.repo}"
148+
href="https://github.com/{data.params.org}/{data.params.repo}"
150149
target="_blank"
151150
class="group *:underline-offset-4 after:ml-0.5 after:inline-block after:-translate-x-2 after:font-sans after:text-2xl after:opacity-0 after:transition after:content-['↗'] hover:after:translate-x-0 hover:after:opacity-100"
152151
>
153-
<span class="text-primary group-hover:underline">{page.params.org}</span><span
152+
<span class="text-primary group-hover:underline">{data.params.org}</span><span
154153
class="text-foreground no-underline">/</span
155-
><wbr /><span class="text-primary group-hover:underline">{page.params.repo}</span>
154+
><wbr /><span class="text-primary group-hover:underline">{data.params.repo}</span>
156155
</a>
157156
</h1>
158157
<div class="flex items-center gap-2">

0 commit comments

Comments
 (0)