anki/ts/components/BackendProgressIndicator.svelte
RumovZ 850043b49b
Tooltips for CSV import and import page refactoring (#2655)
* Make enum selector generic

* Refactor ImportCsvPage to support tooltips

* Improve csv import defaults

* Unify import pages

* Improve import page styling

* Fix life cycle issue with import properties

* Remove size constraints to fix scrollbar styling

* Add help strings and urls to csv import page

* Show ErrorPage on ImportPage error

* Fix escaping of import path

* Unify ImportPage and ImportLogPage

* Apply suggestions from code review (dae)

* Fix import progress

* Fix preview overflowing container

* Don't include <br> in FileIoErrors (dae)

e.g. 500: Failed to read '/home/dae/foo2.csv':<br>stream did not contain valid UTF-8

I thought about using {@html ...} here, but that's a potential security issue,
as the filename is not something we control.
2023-09-14 09:06:15 +10:00

107 lines
2.7 KiB
Svelte

<!--
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>;
export let result: ResultWithChanges | undefined;
export let error: Error | undefined;
let label: string = "";
function onUpdate(progress: Progress) {
if (
progress.value.value &&
progress.value.case !== "none" &&
label !== progress.value.value.toString()
) {
label = progress.value.value.toString();
}
}
$: (async () => {
if (!result && !error) {
try {
result = await runWithBackendProgress(task, onUpdate);
} catch (err) {
if (err instanceof Error) {
error = err;
} else {
throw err;
}
}
}
})();
</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>