From 8e2f4059f0968039ea019e9bb122dccb5a13c471 Mon Sep 17 00:00:00 2001 From: Mathieu Schimmerling Date: Sun, 27 Oct 2024 13:24:28 +0100 Subject: [PATCH] feat(vitals): improve CLS (#271) * feat(snippet): add skeleton while loading * feat(snippet): add skeleton while loading --- README.md | 2 +- src/Index.svelte | 95 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 76 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index ca90a28d..db755239 100644 --- a/README.md +++ b/README.md @@ -601,7 +601,7 @@ pnpm i pnpm run dev ``` -This project requires Node.js to be `v16.0.0` or higher. +This project requires Node.js to be `v20` or higher. ### Principle when add/edit a framework snippet diff --git a/src/Index.svelte b/src/Index.svelte index e84a36bb..0df19f6c 100644 --- a/src/Index.svelte +++ b/src/Index.svelte @@ -144,15 +144,29 @@ saveFrameworkIdsSelectedOnStorage(); } + let snippetsByFrameworkIdLoading = $state(new SvelteSet()); + let snippetsByFrameworkIdError = $state(new SvelteSet()); + $effect(async () => { - for (const frameworkId of [...frameworkIdsSelected]) { - if (!snippetsByFrameworkId.has(frameworkId)) { - const frameworkSnippets = ( + Promise.all( + [...frameworkIdsSelected].map(async (frameworkId) => { + if (!snippetsByFrameworkId.has(frameworkId)) { + snippetsByFrameworkIdError.delete(frameworkId); + snippetsByFrameworkIdLoading.add(frameworkId); + await snippetsImporterByFrameworkId[frameworkId]() - ).default; - snippetsByFrameworkId.set(frameworkId, frameworkSnippets); - } - } + .then(({ default: frameworkSnippets }) => { + snippetsByFrameworkId.set(frameworkId, frameworkSnippets); + }) + .catch(() => { + snippetsByFrameworkIdError.add(frameworkId); + }) + .finally(() => { + snippetsByFrameworkIdLoading.delete(frameworkId); + }); + } + }) + ); }); const MAX_FRAMEWORK_NB_INITIAL_DISPLAYED = 10; @@ -332,16 +346,21 @@ {@const frameworkSnippet = snippetsByFrameworkId .get(frameworkId) ?.find((s) => s.snippetId === snippet.snippetId)} - {#if frameworkSnippet} -
-
+
+

-

- -

+ + + {#if frameworkSnippet}
{#if frameworkSnippet.playgroundURL} {/if}
-
-
+ {/if} +
+
+ {#if frameworkSnippet} {#if frameworkSnippet.files.length > 0}
{/if} -
+ {:else if frameworkSnippetIsLoading} +
+
+
+
+
+
+
+
+
+
+ Loading... +
+
+
+ {:else if frameworkSnippetIsError} +

+ Error loading snippets. Please reload the + page. +

+ {/if}
- {/if} + {/each} {/if}