refactor: improve type safety, Svelte 5 reactivity, and API resilience
This commit is contained in:
@@ -1,28 +1,42 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
interface Props {
|
||||
log_lvl?: number;
|
||||
site_google_tracking_id?: string;
|
||||
}
|
||||
|
||||
let { log_lvl = 0, site_google_tracking_id = $bindable('') }: Props = $props();
|
||||
if (log_lvl) {
|
||||
console.log(`AE Analytics: site_google_tracking_id = `, site_google_tracking_id);
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
window.gtag = function gtag(): void {
|
||||
window.dataLayer.push(arguments);
|
||||
};
|
||||
window.gtag('js', new Date());
|
||||
window.gtag('config', site_google_tracking_id);
|
||||
if (log_lvl) {
|
||||
console.log(`AE Analytics: Google Analytics Tracking ID = `, site_google_tracking_id);
|
||||
declare global {
|
||||
interface Window {
|
||||
dataLayer: any[];
|
||||
gtag: (...args: any[]) => void;
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (browser && site_google_tracking_id) {
|
||||
if (log_lvl) {
|
||||
console.log(`AE Analytics: site_google_tracking_id = `, site_google_tracking_id);
|
||||
}
|
||||
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
window.gtag = window.gtag || function gtag() {
|
||||
window.dataLayer.push(arguments);
|
||||
};
|
||||
window.gtag('js', new Date());
|
||||
window.gtag('config', site_google_tracking_id);
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`AE Analytics: Google Analytics Tracking ID = `, site_google_tracking_id);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={site_google_tracking_id}">
|
||||
</script>
|
||||
{#if site_google_tracking_id}
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={site_google_tracking_id}"></script>
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
@@ -144,7 +144,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
$effect(async () => {
|
||||
$effect(() => {
|
||||
if (trigger_clear_access) {
|
||||
trigger_clear_access = false;
|
||||
if (log_lvl) {
|
||||
@@ -415,7 +415,7 @@
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row flex-wrap gap-1 items-end justify-end w-full transition-all">
|
||||
{#if $ae_loc?.access_type && $ae_loc?.access_type == 'anonymous' && 1 == 3}
|
||||
{#if $ae_loc?.access_type && $ae_loc?.access_type == 'anonymous'}
|
||||
<span>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -411,7 +411,7 @@
|
||||
class="input max-w-48"
|
||||
placeholder="Email Address"
|
||||
value={$ae_sess.auth__entered_email ?? ''}
|
||||
oninput={(e) => ($ae_sess.auth__entered_email = e.target.value)}
|
||||
oninput={(e) => ($ae_sess.auth__entered_email = (e.target as HTMLInputElement).value)}
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
@@ -668,14 +668,14 @@
|
||||
class="input max-w-36"
|
||||
placeholder="User ID"
|
||||
value={$ae_sess.auth__entered_user_id ?? ''}
|
||||
oninput={(e) => ($ae_sess.auth__entered_user_id = e.target.value)}
|
||||
oninput={(e) => ($ae_sess.auth__entered_user_id = (e.target as HTMLInputElement).value)}
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
class="input max-w-36"
|
||||
placeholder="Auth Key"
|
||||
value={$ae_sess.auth__entered_user_key ?? ''}
|
||||
oninput={(e) => ($ae_sess.auth__entered_user_key = e.target.value)}
|
||||
oninput={(e) => ($ae_sess.auth__entered_user_key = (e.target as HTMLInputElement).value)}
|
||||
/>
|
||||
{:else}
|
||||
<input
|
||||
@@ -683,14 +683,14 @@
|
||||
class="input max-w-48"
|
||||
placeholder="Username"
|
||||
value={$ae_sess.auth__entered_username ?? ''}
|
||||
oninput={(e) => ($ae_sess.auth__entered_username = e.target.value)}
|
||||
oninput={(e) => ($ae_sess.auth__entered_username = (e.target as HTMLInputElement).value)}
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
class="input max-w-48"
|
||||
placeholder="Password"
|
||||
value={$ae_sess.auth__entered_password ?? ''}
|
||||
oninput={(e) => ($ae_sess.auth__entered_password = e.target.value)}
|
||||
oninput={(e) => ($ae_sess.auth__entered_password = (e.target as HTMLInputElement).value)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user