Refactor loading variable + more showError

pull/62/head
Varun Patil 2022-09-15 17:57:17 -07:00
parent 9ca34b6edf
commit c70d46b45c
1 changed files with 30 additions and 17 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="container" ref="container" :class="{ 'icon-loading': loading }"> <div class="container" ref="container" :class="{ 'icon-loading': loading > 0 }">
<!-- Main recycler view for rows --> <!-- Main recycler view for rows -->
<RecycleScroller <RecycleScroller
ref="recycler" ref="recycler"
@ -110,6 +110,7 @@
import { Component, Watch, Mixins } from 'vue-property-decorator'; import { Component, Watch, Mixins } from 'vue-property-decorator';
import { IDay, IHeadRow, IPhoto, IRow, IRowType, ITick } from "../types"; import { IDay, IHeadRow, IPhoto, IRow, IRowType, ITick } from "../types";
import { generateUrl } from '@nextcloud/router' import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
import GlobalMixin from '../mixins/GlobalMixin'; import GlobalMixin from '../mixins/GlobalMixin';
import NcActions from '@nextcloud/vue/dist/Components/NcActions'; import NcActions from '@nextcloud/vue/dist/Components/NcActions';
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton'; import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton';
@ -148,7 +149,7 @@ for (const [key, value] of Object.entries(API_ROUTES)) {
}) })
export default class Timeline extends Mixins(GlobalMixin) { export default class Timeline extends Mixins(GlobalMixin) {
/** Loading days response */ /** Loading days response */
private loading = true; private loading = 0;
/** Main list of rows */ /** Main list of rows */
private list: IRow[] = []; private list: IRow[] = [];
/** Counter of rows */ /** Counter of rows */
@ -239,7 +240,7 @@ export default class Timeline extends Mixins(GlobalMixin) {
/** Reset all state */ /** Reset all state */
async resetState() { async resetState() {
this.clearSelection(); this.clearSelection();
this.loading = true; this.loading = 0;
this.list = []; this.list = [];
this.numRows = 0; this.numRows = 0;
this.heads = {}; this.heads = {};
@ -443,11 +444,16 @@ export default class Timeline extends Mixins(GlobalMixin) {
params.folderId = this.$route.params.id || 0; params.folderId = this.$route.params.id || 0;
} }
try {
this.loading++;
const startState = this.state; const startState = this.state;
const res = await axios.get<IDay[]>(generateUrl(this.appendQuery(url), params)); const res = await axios.get<IDay[]>(generateUrl(this.appendQuery(url), params));
const data = res.data; const data = res.data;
if (this.state !== startState) return; if (this.state !== startState) return;
await this.processDays(data); await this.processDays(data);
} finally {
this.loading--;
}
} }
/** Process the data for days call including folders */ /** Process the data for days call including folders */
@ -522,10 +528,13 @@ export default class Timeline extends Mixins(GlobalMixin) {
this.processDay(preload.day); this.processDay(preload.day);
} }
this.loading = false;
// Fix view height variable // Fix view height variable
await this.reflowTimeline(); await this.reflowTimeline();
// Check if we didn't find anything
if (this.list.length === 0) {
showError(this.t('memories', 'No photos to show here'));
}
} }
/** Fetch image data for one dayId */ /** Fetch image data for one dayId */
@ -552,6 +561,7 @@ export default class Timeline extends Mixins(GlobalMixin) {
day.count = data.length; day.count = data.length;
this.processDay(day); this.processDay(day);
} catch (e) { } catch (e) {
showError(this.t('memories', 'Failed to load some photos'));
console.error(e); console.error(e);
} }
} }
@ -932,14 +942,17 @@ export default class Timeline extends Mixins(GlobalMixin) {
} }
} }
this.loading = true; try {
const list = [...this.selection]; const list = [...this.selection];
this.loading++;
for await (const delIds of dav.deleteFilesByIds(list.map(p => p.fileid))) { for await (const delIds of dav.deleteFilesByIds(list.map(p => p.fileid))) {
const delIdsSet = new Set(delIds.filter(i => i)); const delIdsSet = new Set(delIds.filter(i => i));
const updatedDays = new Set(list.filter(f => delIdsSet.has(f.fileid)).map(f => f.d)); const updatedDays = new Set(list.filter(f => delIdsSet.has(f.fileid)).map(f => f.d));
await this.deleteFromViewWithAnimation(delIdsSet, updatedDays); await this.deleteFromViewWithAnimation(delIdsSet, updatedDays);
} }
this.loading = false; } finally {
this.loading--;
}
} }
/** /**