move restoring og photo scroll position into own function

This commit is contained in:
heikomat 2022-08-27 22:43:19 +02:00 committed by Michael Mayer
parent 3e33af7d1d
commit 00ed6468c3

View file

@ -494,17 +494,8 @@ export default {
if (this.$root.$el.clientHeight <= window.document.documentElement.clientHeight + 300) {
this.$emit("scrollRefresh");
}
const lastOpenedPhotoId = window.localStorage.getItem("last_opened_photo");
if (!this.viewer.open && lastOpenedPhotoId) {
window.localStorage.removeItem("last_opened_photo");
this.$nextTick(() => {
document.querySelector(`[data-uid="${lastOpenedPhotoId}"]`)?.scrollIntoView({
behavior: 'auto',
block: 'center',
inline: 'center'
});
});
}
this.restoreScrollPosition();
});
}
}).finally(() => {
@ -513,6 +504,21 @@ export default {
this.listen = true;
});
},
restoreScrollPosition() {
const lastOpenedPhotoId = window.localStorage.getItem("last_opened_photo");
if (lastOpenedPhotoId === undefined || lastOpenedPhotoId === null || this.viewer.open) {
return;
}
window.localStorage.removeItem("last_opened_photo");
this.$nextTick(() => {
document.querySelector(`[data-uid="${lastOpenedPhotoId}"]`)?.scrollIntoView({
behavior: 'auto',
block: 'center',
inline: 'center'
});
});
},
onImportCompleted() {
if (!this.listen) return;