Fix viewer delete (fix #67)
parent
795d0b5896
commit
7a03f622aa
|
@ -38,6 +38,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Prop, Emit, Mixins } from 'vue-property-decorator';
|
import { Component, Prop, Emit, Mixins } from 'vue-property-decorator';
|
||||||
import { IDay, IPhoto } from "../types";
|
import { IDay, IPhoto } from "../types";
|
||||||
|
import { subscribe, unsubscribe } from '@nextcloud/event-bus';
|
||||||
|
|
||||||
import { showError } from '@nextcloud/dialogs'
|
import { showError } from '@nextcloud/dialogs'
|
||||||
import { getPreviewUrl } from "../services/FileUtils";
|
import { getPreviewUrl } from "../services/FileUtils";
|
||||||
|
@ -63,7 +64,7 @@ export default class Photo extends Mixins(GlobalMixin) {
|
||||||
@Prop() rowHeight: number;
|
@Prop() rowHeight: number;
|
||||||
@Prop() day: IDay;
|
@Prop() day: IDay;
|
||||||
|
|
||||||
@Emit('reprocess') emitReprocess(remPhotos: IPhoto[]) {}
|
@Emit('delete') emitDelete(remPhotos: IPhoto[]) {}
|
||||||
@Emit('select') emitSelect(data: IPhoto) {}
|
@Emit('select') emitSelect(data: IPhoto) {}
|
||||||
@Emit('clickImg') emitClickImg(component: any) {}
|
@Emit('clickImg') emitClickImg(component: any) {}
|
||||||
|
|
||||||
|
@ -150,6 +151,13 @@ export default class Photo extends Mixins(GlobalMixin) {
|
||||||
// Key to store sidebar state
|
// Key to store sidebar state
|
||||||
const SIDEBAR_KEY = 'memories:sidebar-open';
|
const SIDEBAR_KEY = 'memories:sidebar-open';
|
||||||
|
|
||||||
|
// Subscribe to delete events
|
||||||
|
const deleteHandler = ({ fileid }) => {
|
||||||
|
const photo = this.day.detail.find(p => p.fileid === fileid);
|
||||||
|
this.emitDelete([photo]);
|
||||||
|
};
|
||||||
|
subscribe('files:file:deleted', deleteHandler);
|
||||||
|
|
||||||
// Open viewer
|
// Open viewer
|
||||||
globalThis.OCA.Viewer.open({
|
globalThis.OCA.Viewer.open({
|
||||||
path: photo.filename, // path
|
path: photo.filename, // path
|
||||||
|
@ -162,9 +170,7 @@ export default class Photo extends Mixins(GlobalMixin) {
|
||||||
localStorage.removeItem(SIDEBAR_KEY);
|
localStorage.removeItem(SIDEBAR_KEY);
|
||||||
}
|
}
|
||||||
globalThis.OCA.Files.Sidebar.close();
|
globalThis.OCA.Files.Sidebar.close();
|
||||||
|
unsubscribe('files:file:deleted', deleteHandler);
|
||||||
// Check for any deleted files and remove them from the main view
|
|
||||||
this.processDeleted();
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -174,27 +180,6 @@ export default class Photo extends Mixins(GlobalMixin) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove deleted files from main view */
|
|
||||||
processDeleted() {
|
|
||||||
// This is really an ugly hack, but the viewer
|
|
||||||
// does not provide a way to get the deleted files
|
|
||||||
|
|
||||||
// Compare new and old list of ids
|
|
||||||
const newIds = new Set(this.day.fileInfos.map(f => f.fileid));
|
|
||||||
const remIds = new Set([...this.day.origFileIds].filter(x => !newIds.has(x)));
|
|
||||||
|
|
||||||
// Exit if nothing to do
|
|
||||||
if (remIds.size === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.day.origFileIds = newIds;
|
|
||||||
|
|
||||||
// Remove deleted files from details
|
|
||||||
// Get IPhotos of the deleted file Ids
|
|
||||||
const remPhotos = this.day.detail.filter(p => remIds.has(p.fileid));
|
|
||||||
this.emitReprocess(remPhotos);
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleSelect() {
|
toggleSelect() {
|
||||||
if (this.data.flag & this.c.FLAG_PLACEHOLDER) {
|
if (this.data.flag & this.c.FLAG_PLACEHOLDER) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
:rowHeight="rowHeight"
|
:rowHeight="rowHeight"
|
||||||
:day="item.day"
|
:day="item.day"
|
||||||
@select="selectPhoto"
|
@select="selectPhoto"
|
||||||
@reprocess="deleteFromViewWithAnimation"
|
@delete="deleteFromViewWithAnimation"
|
||||||
@clickImg="clickPhoto" />
|
@clickImg="clickPhoto" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue