Animate after viewer file delete

pull/37/head
Varun Patil 2022-09-08 11:09:11 -07:00
parent e2d5dcbc1c
commit e1448d05ff
2 changed files with 42 additions and 13 deletions

View File

@ -154,9 +154,7 @@ export default {
this.day.fiOrigIds = newIds; this.day.fiOrigIds = newIds;
// Remove deleted files from details // Remove deleted files from details
this.day.detail = this.day.detail.filter(f => !remIds.has(f.fileid)); this.$emit('reprocess', remIds, new Set([this.day]));
this.day.count = this.day.detail.length;
this.$emit('reprocess', this.day);
}, },
toggleSelect() { toggleSelect() {

View File

@ -26,7 +26,7 @@
<Photo v-else <Photo v-else
:data="photo" :rowHeight="rowHeight" :day="item.day" :data="photo" :rowHeight="rowHeight" :day="item.day"
@select="selectPhoto" @select="selectPhoto"
@reprocess="processDay" @reprocess="deleteFromViewWithAnimation"
@clickImg="clickPhoto" /> @clickImg="clickPhoto" />
</div> </div>
</div> </div>
@ -444,7 +444,7 @@ export default {
const day = this.days.find(d => d.dayid === dayId); const day = this.days.find(d => d.dayid === dayId);
day.detail = data; day.detail = data;
day.count = data.length; day.count = data.length;
this.processDay(day); this.processDay(day, true);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
head.loadedImages = false; head.loadedImages = false;
@ -501,8 +501,14 @@ export default {
} }
}, },
/** Process items from day response */ /**
processDay(day) { * Process items from day response.
* Do not auto reflow if you plan to cal the reflow function later.
*
* @param {any} day Day object
* @param {boolean} autoReflowTimeline Whether to reflow timeline if row changed
*/
processDay(day, autoReflowTimeline = false) {
const dayId = day.dayid; const dayId = day.dayid;
const data = day.detail; const data = day.detail;
@ -571,7 +577,7 @@ export default {
// This will be true even if the head is being spliced // This will be true even if the head is being spliced
// because one row is always removed in that case // because one row is always removed in that case
// So just reflow the timeline here // So just reflow the timeline here
if (addedRow || spliceCount > 0) { if (autoReflowTimeline && (addedRow || spliceCount > 0)) {
this.reflowTimeline(); this.reflowTimeline();
this.handleViewSizeChange(); this.handleViewSizeChange();
} }
@ -724,14 +730,39 @@ export default {
await Promise.allSettled(promises); await Promise.allSettled(promises);
this.loading = false; this.loading = false;
await this.deleteFromViewWithAnimation(delIds, updatedDays);
this.clearSelection();
},
/**
* Delete elements from main view with some animation
* This function looks horribly slow, probably isn't that bad
* in all practical scenarios.
*
* This is also going to update day.detail for you and make
* a call to processDay so just pass it the list of ids to
* delete and the days that were updated.
*
* @param {Set} delIds Set of file ids to delete
* @param {Set} updatedDays of days that MAY be affected
*/
async deleteFromViewWithAnimation(delIds, updatedDays) {
if (delIds.size === 0 || updatedDays.size === 0) {
return;
}
// Animate the deletion // Animate the deletion
for (const photo of this.selection) { for (const day of updatedDays) {
if (delIds.has(photo.fileid)) { for (const row of day.rows) {
photo.flag |= constants.FLAG_LEAVING; for (const photo of row.photos) {
if (delIds.has(photo.fileid)) {
photo.flag |= constants.FLAG_LEAVING;
}
}
} }
} }
// wait for 250ms // wait for 200ms
await new Promise(resolve => setTimeout(resolve, 200)); await new Promise(resolve => setTimeout(resolve, 200));
// Speculate day reflow for animation // Speculate day reflow for animation
@ -783,7 +814,7 @@ export default {
} }
} }
this.clearSelection(); // Reflow timeline
this.reflowTimeline(); this.reflowTimeline();
this.handleViewSizeChange(); this.handleViewSizeChange();
}, },