web: load turnstile only in save tab and only once

turnstile will stay in background after being loaded once (just like before), but now it will not load on pages other than save if they are opened first
This commit is contained in:
wukko
2024-09-05 00:04:41 +06:00
parent f0f5d7be7e
commit 49460bd16d
3 changed files with 19 additions and 12 deletions

View File

@ -2,7 +2,7 @@
import env from "$lib/env";
import { onMount } from "svelte";
import { turnstileLoaded } from "$lib/state/turnstile";
import { turnstileLoaded, turnstileCreated } from "$lib/state/turnstile";
let turnstileElement: HTMLElement;
let turnstileScript: HTMLElement;
@ -10,6 +10,9 @@
onMount(() => {
const sitekey = env.TURNSTILE_KEY;
if (!sitekey) return;
$turnstileCreated = true;
const setup = () => {
window.turnstile?.render(turnstileElement, {
sitekey,