|
| 1 | +<script lang="ts"> |
| 2 | + import { Icon } from '@steeze-ui/svelte-icon'; |
| 3 | + import { Check, X } from '@steeze-ui/tabler-icons'; |
| 4 | + import { onMount } from 'svelte'; |
| 5 | + import { slide } from 'svelte/transition'; |
| 6 | + import { initializeObservability } from './observability'; |
| 7 | +
|
| 8 | + const initConsent = async () => { |
| 9 | + await initializeObservability(); |
| 10 | + shouldShow = false; |
| 11 | + }; |
| 12 | +
|
| 13 | + const acceptConsent = () => { |
| 14 | + localStorage.setItem('MMS:telemetry_consent', 'true'); |
| 15 | + initConsent(); |
| 16 | + }; |
| 17 | +
|
| 18 | + const declineConsent = () => { |
| 19 | + localStorage.setItem('MMS:telemetry_consent', 'false'); |
| 20 | + shouldShow = false; |
| 21 | + }; |
| 22 | +
|
| 23 | + let shouldShow = $state(false); |
| 24 | + let timeout = $state(0); |
| 25 | + const TIMEOUT_MAX = 30000; |
| 26 | + let animateIdx = 0; // prevent multiple running when |
| 27 | + onMount(() => { |
| 28 | + const consent = localStorage.getItem('MMS:telemetry_consent'); |
| 29 | + if (!consent) { |
| 30 | + shouldShow = true; |
| 31 | + timeout = TIMEOUT_MAX; |
| 32 | + let current = performance.now(); |
| 33 | + const idx = ++animateIdx; |
| 34 | + const animate = () => { |
| 35 | + if (animateIdx !== idx) return; |
| 36 | + const elapsed = performance.now() - current; |
| 37 | + timeout -= elapsed; |
| 38 | + timeout = Math.max(timeout, 0); |
| 39 | + current = performance.now(); |
| 40 | + if (timeout > 0) { |
| 41 | + requestAnimationFrame(animate); |
| 42 | + } else { |
| 43 | + console.log('Done?'); |
| 44 | + } |
| 45 | + }; |
| 46 | + animate(); |
| 47 | + } else if (consent.toLowerCase() === 'true') { |
| 48 | + initConsent().catch(console.error); |
| 49 | + } |
| 50 | + }); |
| 51 | +</script> |
| 52 | + |
| 53 | +{#if shouldShow} |
| 54 | + <div |
| 55 | + class="flex max-h-svh w-svw justify-between bg-slate-300 px-32 py-4" |
| 56 | + transition:slide={{ duration: 500, delay: 500 }} |
| 57 | + > |
| 58 | + <p> |
| 59 | + This website can leverage |
| 60 | + <a href="https://grafana.com/products/cloud/frontend-observability/" target="_blank" |
| 61 | + >Grafana Frontend Observability</a |
| 62 | + > |
| 63 | + to gather performance and error insights. |
| 64 | + <br /> |
| 65 | + <strong |
| 66 | + >Your privacy is important to us, and this will NOT be activated unless you consent.</strong |
| 67 | + > |
| 68 | + </p> |
| 69 | + |
| 70 | + <div class="flex min-h-0 items-center gap-4"> |
| 71 | + <button |
| 72 | + class="relative flex h-12 items-center gap-2 bg-green-400 px-4 py-1 text-lg font-bold text-green-950 hover:bg-green-600" |
| 73 | + onclick={() => acceptConsent()} |
| 74 | + > |
| 75 | + <Icon src={Check} class="size-6 stroke-4" /> |
| 76 | + Accept |
| 77 | + <div class="absolute bottom-0 left-0 h-1 w-full bg-green-300"> |
| 78 | + <div |
| 79 | + class="h-full bg-green-900" |
| 80 | + style:width="{100 - (timeout / TIMEOUT_MAX) * 100}%" |
| 81 | + ></div> |
| 82 | + </div> |
| 83 | + </button> |
| 84 | + <button |
| 85 | + class="flex h-12 items-center gap-2 bg-red-400 px-4 py-1 text-lg text-red-950 hover:bg-red-600" |
| 86 | + onclick={() => declineConsent()} |
| 87 | + > |
| 88 | + <div class="relative"> |
| 89 | + <Icon src={X} class="absolute top-1/2 left-1/2 h-4 w-4 -translate-1/2" /> |
| 90 | + </div> |
| 91 | + Decline |
| 92 | + </button> |
| 93 | + </div> |
| 94 | + </div> |
| 95 | +{/if} |
0 commit comments