added warning for failed API call

This commit is contained in:
Christopher Bisset 2022-07-05 22:50:25 +10:00
parent 3839860ee8
commit fc4612159e
2 changed files with 6 additions and 4 deletions

View file

@ -12,7 +12,7 @@
visible = false;
} else {
visible = true;
if (ms > 0) timeout = window.setTimeout(() => {visible = false; $alert = ''}, ms); // and hide it after ms milliseconds
if (ms > 0) timeout = window.setTimeout(() => {$alert = ''}, ms); // and hide it after ms milliseconds
}
};
$: onMessageChange($alert, ms); // whenever the alert store or the ms props changes run onMessageChange
@ -20,7 +20,7 @@
</script>
{#if visible}
<div transition:slide class="absolute top-0 left-1/2 transform -translate-x-1/2 p-4 text-lg text-center shadow-xl rounded-b-lg bg-gray-200 max-w-lg" on:click={() => (visible = false)}>
<div transition:slide class="absolute top-0 left-1/2 transform bg-gray-100 -translate-x-1/2 p-4 text-lg text-center shadow-xl rounded-b-lg max-w-lg" on:click={() => {$alert = ''}}>
<p>{$alert}</p>
</div>
{/if}

View file

@ -8,6 +8,8 @@
let newUserCardVisible = false;
// The Form used for validating input
let newUserForm: HTMLFormElement;
function createUser(): void {
let headscaleURL = localStorage.getItem('headscaleURL') || '';
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
@ -30,7 +32,7 @@
});
} else {
response.json().then((data) => {
console.error(data);
$alert = data.message;
});
}
})
@ -57,7 +59,7 @@
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg></button
>
<button on:click={() => (newUserCardVisible = false)}
<button on:click={() => {newUserCardVisible = false; userName = ''}}
><svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 inline rounded-full hover:bg-gray-300" fill="none" viewBox="0 0 24 24" stroke="black" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg></button