mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
fix: progress bar
This commit is contained in:
1 parent
e636f9a8d2
commit
4fb243f6b7
2 files changed
+62
-24
No files matched your search
@@ -1,22 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { navigating } from '$app/stores';
|
||||
|
||||
let width: number;
|
||||
let updater: ReturnType<typeof setTimeout>;
|
||||
let completed = false;
|
||||
import { afterNavigate, beforeNavigate } from '$app/navigation';
|
||||
|
||||
const minimum = 0.08;
|
||||
const maximum = 0.994;
|
||||
const settleTime = 700;
|
||||
const intervalTime = 800;
|
||||
const intervalTime = 700;
|
||||
const displayThresholdMs = 150;
|
||||
const stepSizes = [0, 0.005, 0.01, 0.02];
|
||||
|
||||
function animate(): void {
|
||||
let running: boolean = false;
|
||||
let updater: ReturnType<typeof setInterval> | null = null;
|
||||
let completed = false;
|
||||
let width: number = 0;
|
||||
|
||||
function getIncrement(n: number) {
|
||||
if (n >= 0 && n < 0.2) return 0.1;
|
||||
else if (n >= 0.2 && n < 0.5) return 0.04;
|
||||
else if (n >= 0.5 && n < 0.8) return 0.02;
|
||||
else if (n >= 0.8 && n < 0.99) return 0.005;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function reset() {
|
||||
width = minimum;
|
||||
running = true;
|
||||
}
|
||||
|
||||
function animate() {
|
||||
if (updater) {
|
||||
// prevent multiple intervals by clearing before making
|
||||
clearInterval(updater);
|
||||
}
|
||||
running = true;
|
||||
updater = setInterval(() => {
|
||||
const randomStep = stepSizes[Math.floor(Math.random() * stepSizes.length)];
|
||||
const randomStep = stepSizes[Math.floor(Math.random() * stepSizes.length)] ?? 0;
|
||||
const step = getIncrement(width) + randomStep;
|
||||
if (width < maximum) {
|
||||
width = width + step;
|
||||
@@ -28,36 +45,57 @@
|
||||
}, intervalTime);
|
||||
}
|
||||
|
||||
function start(): void {
|
||||
width = minimum;
|
||||
function start() {
|
||||
reset();
|
||||
animate();
|
||||
}
|
||||
|
||||
function complete(): void {
|
||||
clearInterval(updater);
|
||||
function stop() {
|
||||
if (updater) {
|
||||
clearInterval(updater);
|
||||
}
|
||||
}
|
||||
|
||||
function complete() {
|
||||
if (updater) clearInterval(updater);
|
||||
if (!running) return;
|
||||
width = 1;
|
||||
running = false;
|
||||
setTimeout(() => {
|
||||
// complete the bar first
|
||||
completed = true;
|
||||
setTimeout(() => {
|
||||
// after some time (long enough to finish the hide animation) reset it back to 0
|
||||
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;
|
||||
}
|
||||
let progressBarStartTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
beforeNavigate((nav) => {
|
||||
if (progressBarStartTimeout) {
|
||||
clearTimeout(progressBarStartTimeout);
|
||||
progressBarStartTimeout = null;
|
||||
}
|
||||
|
||||
$: if ($navigating) {
|
||||
start();
|
||||
} else {
|
||||
if (nav.to?.route.id) {
|
||||
// Internal navigation.
|
||||
if (displayThresholdMs > 0) {
|
||||
// Schedule a display of the progress bar in `displayThresholdMs` milliseconds.
|
||||
// This is to avoid flickering/flashing when the navigation is fast.
|
||||
progressBarStartTimeout = setTimeout(() => start(), displayThresholdMs);
|
||||
} else start();
|
||||
}
|
||||
});
|
||||
|
||||
afterNavigate(() => {
|
||||
if (progressBarStartTimeout) {
|
||||
clearTimeout(progressBarStartTimeout);
|
||||
progressBarStartTimeout = null;
|
||||
}
|
||||
complete();
|
||||
}
|
||||
});
|
||||
|
||||
$: barStyle = (width && width * 100 && `width: ${width * 100}%;`) || '';
|
||||
</script>
|
||||
|
||||
@@ -3,5 +3,5 @@ import { base } from '$app/paths';
|
||||
import type { PageLoad } from './$types';
|
||||
|
||||
export const load: PageLoad = async ({ params }) => {
|
||||
redirect(302, `${base}/console/project-${params.project}/overview`);
|
||||
redirect(303, `${base}/console/project-${params.project}/overview`);
|
||||
};
|
||||
Reference in new issue
Block a user