From 224bd3c2c981ed8ef6bfbb0844530d776da6b0b1 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 25 Aug 2023 20:01:16 -0700 Subject: [PATCH] viewer: reduce round trip for sidebar load Signed-off-by: Varun Patil --- src/components/Sidebar.vue | 4 ++-- src/components/viewer/Viewer.vue | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index 39cba0fc..997dc561 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -90,8 +90,8 @@ export default defineComponent({ }, methods: { - async open(photo: IPhoto | number, filename?: string, forceNative = false) { - if (!this.reducedOpen && this.native && (!photo || forceNative)) { + async open(photo: IPhoto | number, filename?: string, useNative = false) { + if (!this.reducedOpen && this.native && (!photo || useNative)) { // Open native sidebar this.native?.setFullScreenMode?.(true); this.native?.open(filename); diff --git a/src/components/viewer/Viewer.vue b/src/components/viewer/Viewer.vue index ac2e3aba..ef3fe4a6 100644 --- a/src/components/viewer/Viewer.vue +++ b/src/components/viewer/Viewer.vue @@ -1046,11 +1046,22 @@ export default defineComponent({ if (this.routeIsPublic || this.isLocal) { globalThis.mSidebar.open(photo); } else { - const fileInfo = (await dav.getFiles([photo]))[0]; - if (abort()) return; + // check if file path is already loaded with image info + let filename = photo.imageInfo?.filename; + let useNative = !!filename; - const forceNative = fileInfo?.originalFilename?.startsWith('/files/'); - globalThis.mSidebar.open(photo, fileInfo?.filename, forceNative); + // get filename from DAV if not already loaded + if (!filename) { + const fileInfo = (await dav.getFiles([photo]))[0]; + if (abort()) return; + + // get filename + filename = fileInfo?.filename; + useNative = fileInfo?.originalFilename?.startsWith('/files/'); + } + + // open sidebar + globalThis.mSidebar.open(photo, filename, useNative); } };