2023-08-02 12:29:44 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
|
|
|
import type { OpChanges, Progress } from "@tslib/anki/collection_pb";
|
|
|
|
import { runWithBackendProgress } from "@tslib/progress";
|
|
|
|
|
|
|
|
import { pageTheme } from "../sveltelib/theme";
|
|
|
|
|
|
|
|
type ResultWithChanges = OpChanges | { changes?: OpChanges };
|
|
|
|
|
|
|
|
export let task: () => Promise<ResultWithChanges | undefined>;
|
2023-09-14 01:06:15 +02:00
|
|
|
export let result: ResultWithChanges | undefined;
|
|
|
|
export let error: Error | undefined;
|
2023-08-02 12:29:44 +02:00
|
|
|
let label: string = "";
|
|
|
|
|
|
|
|
function onUpdate(progress: Progress) {
|
2023-09-04 03:17:42 +02:00
|
|
|
if (
|
|
|
|
progress.value.value &&
|
|
|
|
progress.value.case !== "none" &&
|
|
|
|
label !== progress.value.value.toString()
|
|
|
|
) {
|
2023-08-02 12:29:44 +02:00
|
|
|
label = progress.value.value.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$: (async () => {
|
2023-09-14 01:06:15 +02:00
|
|
|
if (!result && !error) {
|
|
|
|
try {
|
|
|
|
result = await runWithBackendProgress(task, onUpdate);
|
|
|
|
} catch (err) {
|
|
|
|
if (err instanceof Error) {
|
|
|
|
error = err;
|
|
|
|
} else {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
2023-08-02 12:29:44 +02:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- spinner taken from https://loading.io/css/; CC0 -->
|
|
|
|
{#if !result}
|
|
|
|
<div class="progress">
|
|
|
|
<div class="spinner" class:nightMode={$pageTheme.isDark}>
|
|
|
|
<div />
|
|
|
|
<div />
|
|
|
|
<div />
|
|
|
|
<div />
|
|
|
|
</div>
|
|
|
|
<div id="label">{label}</div>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.progress {
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
left: 50%;
|
|
|
|
transform: translate(-50%, -50%);
|
|
|
|
}
|
|
|
|
|
|
|
|
.spinner {
|
|
|
|
display: block;
|
|
|
|
position: relative;
|
|
|
|
width: 80px;
|
|
|
|
height: 80px;
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
|
|
div {
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
|
|
|
margin: 8px;
|
|
|
|
border: 8px solid #000;
|
|
|
|
border-radius: 50%;
|
|
|
|
animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
|
|
|
|
border-color: #000 transparent transparent transparent;
|
|
|
|
}
|
|
|
|
&.nightMode div {
|
|
|
|
border-top-color: #fff;
|
|
|
|
}
|
|
|
|
div:nth-child(1) {
|
|
|
|
animation-delay: -0.45s;
|
|
|
|
}
|
|
|
|
div:nth-child(2) {
|
|
|
|
animation-delay: -0.3s;
|
|
|
|
}
|
|
|
|
div:nth-child(3) {
|
|
|
|
animation-delay: -0.15s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@keyframes spin {
|
|
|
|
0% {
|
|
|
|
transform: rotate(0deg);
|
|
|
|
}
|
|
|
|
100% {
|
|
|
|
transform: rotate(360deg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#label {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
</style>
|