Skip to content

Commit

Permalink
add loading animation
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaudiomv committed Feb 17, 2024
1 parent 61d1a5c commit a4b7c61
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/lib/DataConverter.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
<script lang="ts">
import { onDestroy } from 'svelte';
import { writable } from 'svelte/store';
import { fetchData, exportCSV, exportKML } from './DataUtils';
let query = '';
const processing = writable(false);
const errorMessage = writable('');
const loadingText = writable('');
let query = '';
let csvDownloadUrl = '';
let kmlDownloadUrl = '';
let interval: number | undefined;
function startLoadingAnimation() {
let dots = '';
interval = setInterval(() => {
if (dots.length < 4) {
dots += '.';
} else {
dots = '.';
}
loadingText.set(`Processing${dots}`);
}, 500); // 500 milliseconds
}
function stopLoadingAnimation() {
clearInterval(interval);
loadingText.set('');
}
async function handleExport() {
processing.set(true);
errorMessage.set('');
csvDownloadUrl = '';
kmlDownloadUrl = '';
startLoadingAnimation();
try {
const data = await fetchData(query);
Expand All @@ -32,8 +53,15 @@
}
} finally {
processing.set(false);
stopLoadingAnimation();
}
}
onDestroy(() => {
if (interval) {
clearInterval(interval);
}
});
</script>

<section>
Expand All @@ -47,6 +75,9 @@
placeholder="BMLT URL query..."
/>
<button on:click={handleExport} disabled={$processing}>Generate Export Data</button>
{#if $processing}
<div class="loading">{$loadingText}</div>
{/if}

{#if $errorMessage}
<p class="error" id="errorMessages">{$errorMessage}</p>
Expand Down Expand Up @@ -163,4 +194,11 @@
box-sizing: border-box;
text-align: center;
}
.loading {
color: #007bff;
text-align: center;
padding: 10px;
font-weight: bold;
}
</style>

0 comments on commit a4b7c61

Please sign in to comment.