forked from Cutlery/immich
* no-misused-promises * no-floating-promises * format * revert for now * remove load function * require-await * revert a few no-floating-promises changes that would cause no-misused-promises failures * format * fix a few more * fix most remaining errors * executor-queue * executor-queue.spec * remove duplicate comments by grouping rules * upgrade sveltekit and enforce rules * oops. move await * try this * just ignore for now since it's only a test * run in parallel * Update web/src/routes/admin/jobs-status/+page.svelte Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> * remove Promise.resolve call * rename function * remove unnecessary warning silencing * make handleError sync * fix new errors from recently merged PR to main * extract method * use handlePromiseError --------- Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
91 lines
1.8 KiB
Svelte
91 lines
1.8 KiB
Svelte
<script context="module" lang="ts">
|
|
export enum ProgressBarStatus {
|
|
Playing = 'playing',
|
|
Paused = 'paused',
|
|
}
|
|
</script>
|
|
|
|
<script lang="ts">
|
|
import { handlePromiseError } from '$lib/utils';
|
|
|
|
import { createEventDispatcher, onMount } from 'svelte';
|
|
import { tweened } from 'svelte/motion';
|
|
|
|
/**
|
|
* Autoplay on mount
|
|
* @default false
|
|
*/
|
|
export let autoplay = false;
|
|
|
|
/**
|
|
* Progress bar status
|
|
*/
|
|
export let status: ProgressBarStatus = ProgressBarStatus.Paused;
|
|
|
|
export let hidden = false;
|
|
|
|
export let duration = 5;
|
|
|
|
const onChange = async () => {
|
|
progress = setDuration(duration);
|
|
await play();
|
|
};
|
|
|
|
let progress = setDuration(duration);
|
|
|
|
$: duration, handlePromiseError(onChange());
|
|
|
|
$: {
|
|
if ($progress === 1) {
|
|
dispatch('done');
|
|
}
|
|
}
|
|
|
|
const dispatch = createEventDispatcher<{
|
|
done: void;
|
|
playing: void;
|
|
paused: void;
|
|
}>();
|
|
|
|
onMount(async () => {
|
|
if (autoplay) {
|
|
await play();
|
|
}
|
|
});
|
|
|
|
export const play = async () => {
|
|
status = ProgressBarStatus.Playing;
|
|
dispatch('playing');
|
|
await progress.set(1);
|
|
};
|
|
|
|
export const pause = async () => {
|
|
status = ProgressBarStatus.Paused;
|
|
dispatch('paused');
|
|
await progress.set($progress);
|
|
};
|
|
|
|
export const restart = async (autoplay: boolean) => {
|
|
await progress.set(0);
|
|
|
|
if (autoplay) {
|
|
await play();
|
|
}
|
|
};
|
|
|
|
export const reset = async () => {
|
|
status = ProgressBarStatus.Paused;
|
|
await progress.set(0);
|
|
};
|
|
|
|
function setDuration(newDuration: number) {
|
|
return tweened<number>(0, {
|
|
duration: (from: number, to: number) => (to ? newDuration * 1000 * (to - from) : 0),
|
|
});
|
|
}
|
|
</script>
|
|
|
|
{#if !hidden}
|
|
<span class="absolute left-0 h-[3px] bg-immich-primary shadow-2xl" style:width={`${$progress * 100}%`} />
|
|
{/if}
|