viewer: fix OTD

pull/175/head
Varun Patil 2022-11-05 23:32:25 -07:00 committed by Varun Patil
parent 883800c6ac
commit 8a84cd91c2
3 changed files with 35 additions and 6 deletions

View File

@ -45,6 +45,7 @@
<OnThisDay
v-if="$route.name === 'timeline'"
:key="config_timelinePath"
:viewer="$refs.viewer"
@load="scrollerManager.adjust()"
>
</OnThisDay>

View File

@ -418,12 +418,8 @@ export default class Viewer extends Mixins(GlobalMixin) {
// Get full image
return {
src: getPreviewUrl(photo, false, 256),
...this.getItemData(photo),
msrc: thumbSrc,
width: photo.w || undefined,
height: photo.h || undefined,
thumbCropped: true,
photo: photo,
};
});
@ -436,6 +432,34 @@ export default class Viewer extends Mixins(GlobalMixin) {
this.photoswipe.init();
}
/** Open with a static list of photos */
public async openStatic(photo: IPhoto, list: IPhoto[]) {
this.list = list;
await this.createBase({
index: list.findIndex((p) => p.fileid === photo.fileid),
});
this.globalCount = list.length;
this.globalAnchor = 0;
this.photoswipe.addFilter("itemData", (itemData, index) => {
return this.getItemData(this.list[index]);
});
this.photoswipe.init();
}
/** Get base data object */
private getItemData(photo: IPhoto) {
return {
src: getPreviewUrl(photo, false, 256),
width: photo.w || undefined,
height: photo.h || undefined,
thumbCropped: true,
photo: photo,
};
}
/** Get element for thumbnail if it exists */
private thumbElem(photo: IPhoto) {
if (!photo) return;
@ -481,6 +505,7 @@ export default class Viewer extends Mixins(GlobalMixin) {
this.updateLoading(1);
for await (const p of dav.favoritePhotos([photo], val)) {
if (!p[0]) return;
this.$forceUpdate();
}
} finally {
this.updateLoading(-1);

View File

@ -73,6 +73,9 @@ interface IYear {
export default class OnThisDay extends Mixins(GlobalMixin) {
private getPreviewUrl = getPreviewUrl;
@Prop()
private viewer: any;
@Emit("load")
onload() {}
@ -191,7 +194,7 @@ export default class OnThisDay extends Mixins(GlobalMixin) {
click(year: IYear) {
const allPhotos = this.years.flatMap((y) => y.photos);
// this.viewerManager.open(year.preview, allPhotos);
this.viewer.openStatic(year.preview, allPhotos);
}
}
</script>