From 54059b42165f59237a727063fd91e95d154a0b49 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sun, 29 Oct 2023 12:14:42 -0700 Subject: [PATCH] viewer: invalidate metadata during fast changes Signed-off-by: Varun Patil --- src/components/Metadata.vue | 13 ++++++++++--- src/components/Sidebar.vue | 19 +++++++++++++++---- src/components/viewer/Viewer.vue | 5 ++++- src/globals.d.ts | 1 + 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/components/Metadata.vue b/src/components/Metadata.vue index e297639c..981bc9eb 100644 --- a/src/components/Metadata.vue +++ b/src/components/Metadata.vue @@ -54,14 +54,14 @@
-
-
- {{ t('memries', 'Failed to load metadata') }} +
+ {{ t('memories', 'Failed to load metadata') }}
@@ -119,6 +119,7 @@ export default defineComponent({ filename: '', exif: {} as IExif, baseInfo: {} as IImageInfo, + error: false, loading: 0, state: 0, @@ -386,6 +387,7 @@ export default defineComponent({ async update(photo: number | IPhoto): Promise { this.state = Math.random(); this.loading = 0; + this.error = false; this.fileid = null; this.exif = {}; @@ -427,6 +429,10 @@ export default defineComponent({ if (this.fileid) await this.update(this.fileid); }, + invalidate() { + this.fileid = null; + }, + editDate() { _m.modals.editMetadata([_m.viewer.currentPhoto!], [1]); }, @@ -464,6 +470,7 @@ export default defineComponent({ if (state === this.state) return res; return null; } catch (err) { + this.error = true; throw err; } finally { if (state === this.state) this.loading--; diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index 3aabb9b6..d0ff7d5e 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -41,8 +41,9 @@ export default defineComponent({ data: () => ({ nativeOpen: false, reducedOpen: false, - basename: '', + basename: String(), lastKnownWidth: 0, + nativeMetadata: null as null | InstanceType, }), computed: { @@ -87,6 +88,7 @@ export default defineComponent({ open: this.open.bind(this), close: this.close.bind(this), setTab: this.setTab.bind(this), + invalidate: this.invalidate.bind(this), getWidth: this.getWidth.bind(this), }; @@ -139,6 +141,11 @@ export default defineComponent({ this.native?.setActiveTab(tab); }, + invalidate() { + this.refs.metadata?.invalidate(); + this.nativeMetadata?.invalidate(); + }, + getWidth() { const sidebar = document.getElementById('app-sidebar-vue'); this.lastKnownWidth = sidebar?.offsetWidth || this.lastKnownWidth; @@ -186,7 +193,8 @@ export default defineComponent({ const router = this.$router; // Component instance - let component: (Vue & { $children: readonly [InstanceType] }) | null; + let component: any; + const self = this; // Register sidebar tab globalThis.OCA?.Files?.Sidebar?.registerTab( @@ -200,16 +208,19 @@ export default defineComponent({ component?.$destroy?.(); component = new Vue({ render: (h) => h(Metadata), router }); component.$mount(el); - component.$children[0].update(Number(fileInfo.id)); + + self.nativeMetadata = component.$children[0]; + self.nativeMetadata?.update(Number(fileInfo.id)); }, update(fileInfo: { id: string | number }) { - component?.$children[0].update(Number(fileInfo.id)); + self.nativeMetadata?.update(Number(fileInfo.id)); }, destroy() { component?.$destroy?.(); component = null; + self.nativeMetadata = null; }, }), ); diff --git a/src/components/viewer/Viewer.vue b/src/components/viewer/Viewer.vue index 3c7db457..26bd35be 100644 --- a/src/components/viewer/Viewer.vue +++ b/src/components/viewer/Viewer.vue @@ -173,7 +173,7 @@