-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from 3rob3/dev.jw.web-auto-reload
Auto-Reload on Web
- Loading branch information
Showing
8 changed files
with
233 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
immichFrame.Web/src/lib/components/elements/progress-bar.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<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); | ||
// svelte 5, again.... | ||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions | ||
$: 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 bottom-0 h-[3px] framebg-color" | ||
style:width={`${$progress * 100}%`} | ||
/> | ||
{/if} | ||
|
||
<style> | ||
.framebg-color { | ||
background-color: wheat; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { writable } from 'svelte/store'; | ||
|
||
export enum SlideshowState { | ||
PlaySlideshow = 'play-slideshow', | ||
StopSlideshow = 'stop-slideshow', | ||
None = 'none', | ||
} | ||
|
||
|
||
function createSlideshowStore() { | ||
const restartState = writable<boolean>(false); | ||
const stopState = writable<boolean>(false); | ||
|
||
const slideshowState = writable<SlideshowState>(SlideshowState.None); | ||
|
||
return { | ||
restartProgress: { | ||
subscribe: restartState.subscribe, | ||
set: (value: boolean) => { | ||
|
||
console.log('restartProgress value is: ') | ||
console.log(value) | ||
// Trigger an action whenever the restartProgress is set to true. Automatically | ||
// reset the restart state after that | ||
if (value) { | ||
restartState.set(true); | ||
restartState.set(false); | ||
} | ||
}, | ||
}, | ||
stopProgress: { | ||
subscribe: stopState.subscribe, | ||
set: (value: boolean) => { | ||
console.log('stopProgress value is: ') | ||
console.log(value) | ||
// Trigger an action whenever the stopProgress is set to true. Automatically | ||
// reset the stop state after that | ||
if (value) { | ||
stopState.set(true); | ||
stopState.set(false); | ||
} | ||
}, | ||
}, | ||
slideshowState | ||
}; | ||
} | ||
|
||
export const slideshowStore = createSlideshowStore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export const decodeBase64 = (data: string) => Uint8Array.from(atob(data), (c) => c.charCodeAt(0)); | ||
|
||
export const handlePromiseError = <T>(promise: Promise<T>): void => { | ||
promise.catch((error) => console.error(`[utils.ts]:handlePromiseError ${error}`, error)); | ||
}; |