Files
immich/web/src/lib/stores/slideshow.store.ts
Dag Stuan d544053c67 feat(web): improve slideshow quality of life (#18778)
* Add a new setting to toggle autoplay when showing the slideshow.
* Fix an issue where the slideshow would restart automatically when
navigating after it was paused.
* Add a keyboard shortcut 's' to start the slideshow from the asset
viewer.
* Add a keyboard shortcut ' ' to toggle the slideshow play/paused.
* Change the timeout for hiding the slideshow controls from 10 to 2.5
seconds.
* Add English translation for the 'autoplay_slideshow' setting.

Co-authored-by: Alex <alex.tran1502@gmail.com>
2025-06-02 14:45:39 +00:00

78 lines
2.3 KiB
TypeScript

import { persisted } from 'svelte-persisted-store';
import { writable } from 'svelte/store';
export enum SlideshowState {
PlaySlideshow = 'play-slideshow',
StopSlideshow = 'stop-slideshow',
None = 'none',
}
export enum SlideshowNavigation {
Shuffle = 'shuffle',
AscendingOrder = 'ascending-order',
DescendingOrder = 'descending-order',
}
export enum SlideshowLook {
Contain = 'contain',
Cover = 'cover',
BlurredBackground = 'blurred-background',
}
export const slideshowLookCssMapping: Record<SlideshowLook, string> = {
[SlideshowLook.Contain]: 'object-contain',
[SlideshowLook.Cover]: 'object-cover',
[SlideshowLook.BlurredBackground]: 'object-contain',
};
function createSlideshowStore() {
const restartState = writable<boolean>(false);
const stopState = writable<boolean>(false);
const slideshowNavigation = persisted<SlideshowNavigation>(
'slideshow-navigation',
SlideshowNavigation.DescendingOrder,
);
const slideshowLook = persisted<SlideshowLook>('slideshow-look', SlideshowLook.Contain);
const slideshowState = writable<SlideshowState>(SlideshowState.None);
const showProgressBar = persisted<boolean>('slideshow-show-progressbar', true);
const slideshowDelay = persisted<number>('slideshow-delay', 5, {});
const slideshowTransition = persisted<boolean>('slideshow-transition', true);
const slideshowAutoplay = persisted<boolean>('slideshow-autoplay', true, {});
return {
restartProgress: {
subscribe: restartState.subscribe,
set: (value: boolean) => {
// 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) => {
// 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);
}
},
},
slideshowNavigation,
slideshowLook,
slideshowState,
slideshowDelay,
showProgressBar,
slideshowTransition,
slideshowAutoplay,
};
}
export const slideshowStore = createSlideshowStore();