2024-04-04 03:20:54 +02:00
|
|
|
import type { AssetResponseDto } from '@immich/sdk';
|
|
|
|
|
2023-11-02 02:34:30 +01:00
|
|
|
export class SlideshowHistory {
|
2024-04-04 03:20:54 +02:00
|
|
|
private history: AssetResponseDto[] = [];
|
2023-11-02 02:34:30 +01:00
|
|
|
private index = 0;
|
|
|
|
|
2024-04-04 03:20:54 +02:00
|
|
|
constructor(private onChange: (asset: AssetResponseDto) => void) {}
|
2023-11-02 02:34:30 +01:00
|
|
|
|
|
|
|
reset() {
|
|
|
|
this.history = [];
|
|
|
|
this.index = 0;
|
|
|
|
}
|
|
|
|
|
2024-04-04 03:20:54 +02:00
|
|
|
queue(asset: AssetResponseDto) {
|
|
|
|
this.history.push(asset);
|
2023-11-02 02:34:30 +01:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|