editdate: soft refresh only

old-stable24
Varun Patil 2022-10-16 18:56:50 -07:00
parent 007b026d63
commit d90a85a459
1 changed files with 38 additions and 13 deletions

View File

@ -87,7 +87,7 @@
<SelectionManager ref="selectionManager" <SelectionManager ref="selectionManager"
:selection="selection" :heads="heads" :selection="selection" :heads="heads"
@refresh="refresh" @refresh="softRefresh"
@delete="deleteFromViewWithAnimation" @delete="deleteFromViewWithAnimation"
@updateLoading="updateLoading" /> @updateLoading="updateLoading" />
</div> </div>
@ -235,18 +235,15 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
} }
/** Recreate everything */ /** Recreate everything */
async refresh(preservePosition = false) { async refresh() {
// Get current scroll position
const origScroll = (<any>this.$refs.recycler).$el.scrollTop;
// Reset state
await this.resetState(); await this.resetState();
await this.createState(); await this.createState();
}
// Restore scroll position /** Re-process days */
if (preservePosition) { async softRefresh() {
(<any>this.$refs.recycler).scrollToPosition(origScroll); this.selectionManager.clearSelection();
} await this.fetchDays(true);
} }
/** Do resize after some time */ /** Do resize after some time */
@ -342,9 +339,19 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
} }
} }
// Check if this was requested by a refresh
const force = this.currentEnd === -1;
// Make sure we don't do this too often // Make sure we don't do this too often
this.currentStart = startIndex; this.currentStart = startIndex;
this.currentEnd = endIndex; this.currentEnd = endIndex;
// Check if this was requested specifically
if (force) {
this.loadScrollChanges(startIndex, endIndex);
return;
}
setTimeout(() => { setTimeout(() => {
// Get the overlapping range between startIndex and // Get the overlapping range between startIndex and
// currentStart and endIndex and currentEnd. // currentStart and endIndex and currentEnd.
@ -472,7 +479,7 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
} }
/** Fetch timeline main call */ /** Fetch timeline main call */
async fetchDays() { async fetchDays(noCache=false) {
let url = '/apps/memories/api/days'; let url = '/apps/memories/api/days';
let params: any = {}; let params: any = {};
@ -480,6 +487,9 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
let cache: IDay[]; let cache: IDay[];
const cacheUrl = window.location.pathname + 'api/days'; const cacheUrl = window.location.pathname + 'api/days';
// Make sure to refresh scroll later
this.currentEnd = -1;
try { try {
this.loading++; this.loading++;
const startState = this.state; const startState = this.state;
@ -493,7 +503,7 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
data = await dav.getPeopleData(); data = await dav.getPeopleData();
} else { } else {
// Try the cache // Try the cache
cache = await utils.getCachedData(cacheUrl); cache = noCache ? null : (await utils.getCachedData(cacheUrl));
if (cache) { if (cache) {
await this.processDays(cache); await this.processDays(cache);
this.loading--; this.loading--;
@ -578,8 +588,17 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
heads[day.dayid] = head; heads[day.dayid] = head;
list.push(head); list.push(head);
// Dummy rows for placeholders
let nrows = Math.ceil(day.count / this.numCols);
// Check if already loaded - we can learn
let prevRows: IRow[] | null = null;
if (this.loadedDays.has(day.dayid)) {
prevRows = this.heads[day.dayid]?.day.rows;
nrows = prevRows?.length || nrows;
}
// Add rows // Add rows
const nrows = Math.ceil(day.count / this.numCols);
for (let i = 0; i < nrows; i++) { for (let i = 0; i < nrows; i++) {
const row = this.addRow(day); const row = this.addRow(day);
list.push(row); list.push(row);
@ -588,6 +607,12 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
const leftNum = (day.count - i * this.numCols); const leftNum = (day.count - i * this.numCols);
row.pct = leftNum > this.numCols ? this.numCols : leftNum; row.pct = leftNum > this.numCols ? this.numCols : leftNum;
row.photos = []; row.photos = [];
// Learn from existing row
if (prevRows && i < prevRows.length) {
row.size = prevRows[i].size;
row.photos = prevRows[i].photos;
}
} }
// Continue processing // Continue processing