viewer: invalidate metadata during fast changes

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/900/head
Varun Patil 2023-10-29 12:14:42 -07:00
parent 198fe97b4b
commit 54059b4216
4 changed files with 30 additions and 8 deletions

View File

@ -54,14 +54,14 @@
</div> </div>
<div v-if="lat && lon" class="map"> <div v-if="lat && lon" class="map">
<iframe class="fill-block" :src="mapUrl" /> <iframe class="fill-block" :src="mapUrl"></iframe>
</div> </div>
</div> </div>
<div class="loading-icon fill-block" v-else-if="loading"> <div class="loading-icon fill-block" v-else-if="loading">
<XLoadingIcon /> <XLoadingIcon />
</div> </div>
<div v-else> <div v-else-if="error">
{{ t('memries', 'Failed to load metadata') }} {{ t('memories', 'Failed to load metadata') }}
</div> </div>
</template> </template>
@ -119,6 +119,7 @@ export default defineComponent({
filename: '', filename: '',
exif: {} as IExif, exif: {} as IExif,
baseInfo: {} as IImageInfo, baseInfo: {} as IImageInfo,
error: false,
loading: 0, loading: 0,
state: 0, state: 0,
@ -386,6 +387,7 @@ export default defineComponent({
async update(photo: number | IPhoto): Promise<IImageInfo | null> { async update(photo: number | IPhoto): Promise<IImageInfo | null> {
this.state = Math.random(); this.state = Math.random();
this.loading = 0; this.loading = 0;
this.error = false;
this.fileid = null; this.fileid = null;
this.exif = {}; this.exif = {};
@ -427,6 +429,10 @@ export default defineComponent({
if (this.fileid) await this.update(this.fileid); if (this.fileid) await this.update(this.fileid);
}, },
invalidate() {
this.fileid = null;
},
editDate() { editDate() {
_m.modals.editMetadata([_m.viewer.currentPhoto!], [1]); _m.modals.editMetadata([_m.viewer.currentPhoto!], [1]);
}, },
@ -464,6 +470,7 @@ export default defineComponent({
if (state === this.state) return res; if (state === this.state) return res;
return null; return null;
} catch (err) { } catch (err) {
this.error = true;
throw err; throw err;
} finally { } finally {
if (state === this.state) this.loading--; if (state === this.state) this.loading--;

View File

@ -41,8 +41,9 @@ export default defineComponent({
data: () => ({ data: () => ({
nativeOpen: false, nativeOpen: false,
reducedOpen: false, reducedOpen: false,
basename: '', basename: String(),
lastKnownWidth: 0, lastKnownWidth: 0,
nativeMetadata: null as null | InstanceType<typeof Metadata>,
}), }),
computed: { computed: {
@ -87,6 +88,7 @@ export default defineComponent({
open: this.open.bind(this), open: this.open.bind(this),
close: this.close.bind(this), close: this.close.bind(this),
setTab: this.setTab.bind(this), setTab: this.setTab.bind(this),
invalidate: this.invalidate.bind(this),
getWidth: this.getWidth.bind(this), getWidth: this.getWidth.bind(this),
}; };
@ -139,6 +141,11 @@ export default defineComponent({
this.native?.setActiveTab(tab); this.native?.setActiveTab(tab);
}, },
invalidate() {
this.refs.metadata?.invalidate();
this.nativeMetadata?.invalidate();
},
getWidth() { getWidth() {
const sidebar = document.getElementById('app-sidebar-vue'); const sidebar = document.getElementById('app-sidebar-vue');
this.lastKnownWidth = sidebar?.offsetWidth || this.lastKnownWidth; this.lastKnownWidth = sidebar?.offsetWidth || this.lastKnownWidth;
@ -186,7 +193,8 @@ export default defineComponent({
const router = this.$router; const router = this.$router;
// Component instance // Component instance
let component: (Vue & { $children: readonly [InstanceType<typeof Metadata>] }) | null; let component: any;
const self = this;
// Register sidebar tab // Register sidebar tab
globalThis.OCA?.Files?.Sidebar?.registerTab( globalThis.OCA?.Files?.Sidebar?.registerTab(
@ -200,16 +208,19 @@ export default defineComponent({
component?.$destroy?.(); component?.$destroy?.();
component = new Vue({ render: (h) => h(Metadata), router }); component = new Vue({ render: (h) => h(Metadata), router });
component.$mount(el); 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 }) { update(fileInfo: { id: string | number }) {
component?.$children[0].update(Number(fileInfo.id)); self.nativeMetadata?.update(Number(fileInfo.id));
}, },
destroy() { destroy() {
component?.$destroy?.(); component?.$destroy?.();
component = null; component = null;
self.nativeMetadata = null;
}, },
}), }),
); );

View File

@ -173,7 +173,7 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { IImageInfo, IPhoto, IRowType, TimelineState } from '../../types'; import { IImageInfo, IPhoto, TimelineState } from '../../types';
import type { PsContent } from './types'; import type { PsContent } from './types';
import UserConfig from '../../mixins/UserConfig'; import UserConfig from '../../mixins/UserConfig';
@ -1063,6 +1063,9 @@ export default defineComponent({
if (!photo) return; if (!photo) return;
const abort = () => !this.isOpen || photo !== this.currentPhoto; const abort = () => !this.isOpen || photo !== this.currentPhoto;
// Invalidate currently open metadata
_m.sidebar.invalidate();
// Update the sidebar, first call immediate // Update the sidebar, first call immediate
utils.setRenewingTimeout( utils.setRenewingTimeout(
this, this,

1
src/globals.d.ts vendored
View File

@ -49,6 +49,7 @@ declare global {
open: (photo: IPhoto | number, filename?: string, forceNative?: boolean) => void; open: (photo: IPhoto | number, filename?: string, forceNative?: boolean) => void;
close: () => void; close: () => void;
setTab: (tab: string) => void; setTab: (tab: string) => void;
invalidate: () => void;
getWidth: () => number; getWidth: () => number;
}; };