Set delayed loading spinner and additional CSP headers

This commit is contained in:
thiloho
2024-09-25 16:02:12 +02:00
parent 0e3c0f094c
commit a9e2bd4cb7
14 changed files with 83 additions and 33 deletions

View File

@@ -27,6 +27,6 @@
border: var(--border-primary); border: var(--border-primary);
border-width: 0.125rem; border-width: 0.125rem;
border-block-start-color: var(--color-accent); border-block-start-color: var(--color-accent);
animation: spinner 0.6s linear infinite; animation: spinner 500ms linear infinite;
} }
</style> </style>

View File

@@ -7,6 +7,7 @@
const { form }: { form: ActionData } = $props(); const { form }: { form: ActionData } = $props();
let sending = $state(false); let sending = $state(false);
let loadingDelay: number;
</script> </script>
<SuccessOrError success={form?.success} message={form?.message} /> <SuccessOrError success={form?.success} message={form?.message} />
@@ -18,9 +19,10 @@
<form <form
method="POST" method="POST"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
sending = false; sending = false;
}; };
}} }}

View File

@@ -7,6 +7,7 @@
const { data, form }: { data: PageServerData; form: ActionData } = $props(); const { data, form }: { data: PageServerData; form: ActionData } = $props();
let sending = $state(false); let sending = $state(false);
let loadingDelay: number;
</script> </script>
<SuccessOrError success={form?.success} message={form?.message} /> <SuccessOrError success={form?.success} message={form?.message} />
@@ -37,9 +38,10 @@
<form <form
method="POST" method="POST"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
sending = false; sending = false;
}; };
}} }}

View File

@@ -10,6 +10,7 @@
const { form, data }: { form: ActionData; data: PageServerData } = $props(); const { form, data }: { form: ActionData; data: PageServerData } = $props();
let sending = $state(false); let sending = $state(false);
let loadingDelay: number;
</script> </script>
<SuccessOrError success={form?.success} message={form?.message} /> <SuccessOrError success={form?.success} message={form?.message} />
@@ -30,9 +31,10 @@
method="POST" method="POST"
action="?/createWebsite" action="?/createWebsite"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };
@@ -120,9 +122,10 @@
method="POST" method="POST"
action="?/updateWebsite" action="?/updateWebsite"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update({ reset: false }); await update({ reset: false });
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };
@@ -155,9 +158,10 @@
method="POST" method="POST"
action="?/deleteWebsite" action="?/deleteWebsite"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };

View File

@@ -8,6 +8,7 @@
const { data, form }: { data: PageServerData; form: ActionData } = $props(); const { data, form }: { data: PageServerData; form: ActionData } = $props();
let sending = $state(false); let sending = $state(false);
let loadingDelay: number;
</script> </script>
<SuccessOrError success={form?.success} message={form?.message} /> <SuccessOrError success={form?.success} message={form?.message} />
@@ -42,9 +43,10 @@
method="POST" method="POST"
action="?/logout" action="?/logout"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
sending = false; sending = false;
}; };
}} }}
@@ -70,9 +72,10 @@
method="POST" method="POST"
action="?/deleteAccount" action="?/deleteAccount"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };

View File

@@ -27,6 +27,7 @@
}; };
let sending = $state(false); let sending = $state(false);
let loadingDelay: number;
</script> </script>
<SuccessOrError success={form?.success} message={form?.message} /> <SuccessOrError success={form?.success} message={form?.message} />
@@ -52,9 +53,10 @@
method="POST" method="POST"
enctype="multipart/form-data" enctype="multipart/form-data"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update({ reset: false }); await update({ reset: false });
window.clearTimeout(loadingDelay);
sending = false; sending = false;
}; };
}} }}
@@ -108,9 +110,10 @@
method="POST" method="POST"
enctype="multipart/form-data" enctype="multipart/form-data"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update({ reset: false }); await update({ reset: false });
window.clearTimeout(loadingDelay);
sending = false; sending = false;
}; };
}} }}
@@ -160,9 +163,10 @@
action="?/updateHome" action="?/updateHome"
method="POST" method="POST"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update({ reset: false }); await update({ reset: false });
window.clearTimeout(loadingDelay);
sending = false; sending = false;
}; };
}} }}
@@ -193,9 +197,10 @@
action="?/updateFooter" action="?/updateFooter"
method="POST" method="POST"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update({ reset: false }); await update({ reset: false });
window.clearTimeout(loadingDelay);
sending = false; sending = false;
}; };
}} }}

View File

@@ -10,6 +10,7 @@
const { data, form }: { data: PageServerData; form: ActionData } = $props(); const { data, form }: { data: PageServerData; form: ActionData } = $props();
let sending = $state(false); let sending = $state(false);
let loadingDelay: number;
</script> </script>
<SuccessOrError success={form?.success} message={form?.message} /> <SuccessOrError success={form?.success} message={form?.message} />
@@ -36,9 +37,10 @@
method="POST" method="POST"
action="?/createArticle" action="?/createArticle"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };
@@ -135,9 +137,10 @@
method="POST" method="POST"
action="?/deleteArticle" action="?/deleteArticle"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };

View File

@@ -28,6 +28,7 @@
}; };
let sending = $state(false); let sending = $state(false);
let loadingDelay: number;
</script> </script>
<SuccessOrError success={form?.success} message={form?.message} /> <SuccessOrError success={form?.success} message={form?.message} />
@@ -54,9 +55,10 @@
action="?/editArticle" action="?/editArticle"
enctype="multipart/form-data" enctype="multipart/form-data"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update({ reset: false }); await update({ reset: false });
window.clearTimeout(loadingDelay);
sending = false; sending = false;
}; };
}} }}

View File

@@ -9,6 +9,7 @@
const { data, form }: { data: PageServerData; form: ActionData } = $props(); const { data, form }: { data: PageServerData; form: ActionData } = $props();
let sending = $state(false); let sending = $state(false);
let loadingDelay: number;
</script> </script>
<SuccessOrError success={form?.success} message={form?.message} /> <SuccessOrError success={form?.success} message={form?.message} />
@@ -35,9 +36,10 @@
method="POST" method="POST"
action="?/createCategory" action="?/createCategory"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };
@@ -79,9 +81,10 @@
method="POST" method="POST"
action="?/updateCategory" action="?/updateCategory"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update({ reset: false }); await update({ reset: false });
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };
@@ -117,9 +120,10 @@
method="POST" method="POST"
action="?/deleteCategory" action="?/deleteCategory"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };

View File

@@ -9,6 +9,7 @@
const { data, form }: { data: PageServerData; form: ActionData } = $props(); const { data, form }: { data: PageServerData; form: ActionData } = $props();
let sending = $state(false); let sending = $state(false);
let loadingDelay: number;
</script> </script>
<SuccessOrError success={form?.success} message={form?.message} /> <SuccessOrError success={form?.success} message={form?.message} />
@@ -35,9 +36,10 @@
method="POST" method="POST"
action="?/addCollaborator" action="?/addCollaborator"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };
@@ -83,9 +85,10 @@
method="POST" method="POST"
action="?/updateCollaborator" action="?/updateCollaborator"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update({ reset: false }); await update({ reset: false });
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };
@@ -114,9 +117,10 @@
method="POST" method="POST"
action="?/removeCollaborator" action="?/removeCollaborator"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };

View File

@@ -18,6 +18,7 @@
}; };
let sending = $state(false); let sending = $state(false);
let loadingDelay: number;
</script> </script>
<SuccessOrError success={form?.success} message={form?.message} /> <SuccessOrError success={form?.success} message={form?.message} />
@@ -62,9 +63,10 @@
method="POST" method="POST"
action="?/createUpdateLegalInformation" action="?/createUpdateLegalInformation"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update({ reset: false }); await update({ reset: false });
window.clearTimeout(loadingDelay);
sending = false; sending = false;
}; };
}} }}
@@ -93,9 +95,10 @@
action="?/deleteLegalInformation" action="?/deleteLegalInformation"
method="post" method="post"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };

View File

@@ -9,6 +9,7 @@
const { data, form }: { data: PageServerData; form: ActionData } = $props(); const { data, form }: { data: PageServerData; form: ActionData } = $props();
let sending = $state(false); let sending = $state(false);
let loadingDelay: number;
</script> </script>
<SuccessOrError success={form?.success} message={form?.message} /> <SuccessOrError success={form?.success} message={form?.message} />
@@ -37,9 +38,10 @@
method="POST" method="POST"
action="?/publishWebsite" action="?/publishWebsite"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
sending = false; sending = false;
}; };
}} }}
@@ -68,9 +70,10 @@
method="POST" method="POST"
action="?/createUpdateCustomDomainPrefix" action="?/createUpdateCustomDomainPrefix"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
sending = false; sending = false;
}; };
}} }}
@@ -96,9 +99,10 @@
action="?/deleteCustomDomainPrefix" action="?/deleteCustomDomainPrefix"
method="post" method="post"
use:enhance={() => { use:enhance={() => {
sending = true; loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => { return async ({ update }) => {
await update(); await update();
window.clearTimeout(loadingDelay);
window.location.hash = "!"; window.location.hash = "!";
sending = false; sending = false;
}; };

View File

@@ -14,9 +14,21 @@
? "Dashboard" ? "Dashboard"
: `${$page.url.pathname.charAt(1).toUpperCase()}${$page.url.pathname.slice(2)}` : `${$page.url.pathname.charAt(1).toUpperCase()}${$page.url.pathname.slice(2)}`
); );
let loading = $state(false);
let loadingDelay: number;
$effect(() => {
if ($navigating && ["link", "goto"].includes($navigating.type)) {
loadingDelay = window.setTimeout(() => (loading = true), 500);
} else {
window.clearTimeout(loadingDelay);
loading = false;
}
});
</script> </script>
{#if $navigating && ["link", "goto"].includes($navigating.type)} {#if loading}
<LoadingSpinner /> <LoadingSpinner />
{/if} {/if}

View File

@@ -15,15 +15,17 @@ const config = {
csp: { csp: {
mode: "auto", mode: "auto",
directives: { directives: {
"default-src": ["self"], "default-src": ["none"],
"script-src": ["self"], "script-src": ["self"],
"style-src": ["self", "https:", "http:", "unsafe-inline"], "style-src": ["self", "https:", "unsafe-inline"],
"img-src": ["self", "data:", "https:", "http:"], "img-src": ["self", "data:", "https:"],
"font-src": ["self", "https:", "http:"], "font-src": ["self", "https:"],
"connect-src": ["self"], "connect-src": ["self"],
"frame-src": ["self", "https:", "http:"], "frame-src": ["self", "https:"],
"object-src": ["none"], "object-src": ["none"],
"base-uri": ["self"] "base-uri": ["self"],
"frame-ancestors": ["none"],
"form-action": ["self"]
} }
} }
} }