Merge pull request #118 from appwrite/feat-progress-bar

feat: add progress bar
This commit is contained in:
Torsten Dittmann authored and GitHub committed 2022-11-09 09:59:46 +01:00
commit 7c62f0909c
3 files changed
+88 -2

No files matched your search

+1
View File
@@ -14,3 +14,4 @@ export { default as Breadcrumbs } from './breadcrumbs.svelte';
export { default as Unauthenticated } from './unauthenticated.svelte';
export { default as Usage, type UsagePeriods } from './usage.svelte';
export { default as Activity } from './activity.svelte';
export { default as Progress } from './progress.svelte';
+83
View File
@@ -0,0 +1,83 @@
<script lang="ts">
import { afterNavigate, beforeNavigate } from '$app/navigation';
let width: number;
let updater: ReturnType<typeof setTimeout>;
let completed = false;
const minimum = 0.08;
const maximum = 0.994;
const settleTime = 700;
const intervalTime = 800;
const stepSizes = [0, 0.005, 0.01, 0.02];
function animate(): void {
if (updater) {
clearInterval(updater);
}
updater = setInterval(() => {
const randomStep = stepSizes[Math.floor(Math.random() * stepSizes.length)];
const step = getIncrement(width) + randomStep;
if (width < maximum) {
width = width + step;
}
if (width > maximum) {
width = maximum;
stop();
}
}, intervalTime);
}
function start(): void {
width = minimum;
animate();
}
function complete(): void {
clearInterval(updater);
width = 1;
setTimeout(() => {
completed = true;
setTimeout(() => {
completed = false;
width = 0;
}, settleTime);
}, settleTime);
}
function getIncrement(number: number): number {
if (number >= 0 && number < 0.2) return 0.1;
else if (number >= 0.2 && number < 0.5) return 0.04;
else if (number >= 0.5 && number < 0.8) return 0.02;
else if (number >= 0.8 && number < 0.99) return 0.005;
return 0;
}
beforeNavigate(start);
afterNavigate(complete);
$: barStyle = (width && width * 100 && `width: ${width * 100}%;`) || '';
</script>
<svelte:head />
{#if width}
<div class="progress-bar" class:progress-bar-hiding={completed} style={barStyle} />
{/if}
<style>
.progress-bar {
position: fixed;
top: 0;
left: 0;
height: 2px;
transition: width 0.2s ease-in-out;
z-index: 5;
background: hsl(var(--color-primary-200));
}
.progress-bar-hiding {
transition: top 0.8s ease;
top: -8px;
}
</style>
+4 -2
View File
@@ -8,9 +8,9 @@
import { base } from '$app/paths';
import { browser, dev } from '$app/environment';
import { app } from '$lib/stores/app';
import Notifications from '$lib/layout/notifications.svelte';
import Loading from './loading.svelte';
import { Progress, Notifications } from '$lib/layout';
import { loading } from './store';
import Loading from './loading.svelte';
if (browser) {
window.VERCEL_ANALYTICS_ID = import.meta.env.VERCEL_ANALYTICS_ID?.toString() ?? false;
@@ -95,6 +95,8 @@
<Loading />
{/if}
<Progress />
<style lang="scss" global>
.tippy-box {
--p-tooltip-text-color: var(--color-neutral-10);