1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-10 13:56:47 +01:00
immich/web/src/lib/utils/slideshow-history.ts
2024-04-03 21:20:54 -04:00

42 lines
862 B
TypeScript

import type { AssetResponseDto } from '@immich/sdk';
export class SlideshowHistory {
private history: AssetResponseDto[] = [];
private index = 0;
constructor(private onChange: (asset: AssetResponseDto) => void) {}
reset() {
this.history = [];
this.index = 0;
}
queue(asset: AssetResponseDto) {
this.history.push(asset);
// If we were at the end of the slideshow history, move the index to the new end
if (this.index === this.history.length - 2) {
this.index++;
}
}
next(): boolean {
if (this.index === this.history.length - 1) {
return false;
}
this.index++;
this.onChange(this.history[this.index]);
return true;
}
previous(): boolean {
if (this.index === 0) {
return false;
}
this.index--;
this.onChange(this.history[this.index]);
return true;
}
}