Toasts and name conflict handler

This commit is contained in:
Jiiks 2019-02-28 12:37:57 +02:00
parent 97519b2307
commit 9773f78506
1 changed files with 19 additions and 4 deletions

View File

@ -25,7 +25,8 @@
:readSnippet="readSnippet" :readSnippet="readSnippet"
:injectStyle="injectStyle" :injectStyle="injectStyle"
:toggleLiveUpdate="toggleLiveUpdate" :toggleLiveUpdate="toggleLiveUpdate"
:ctxAction="ctxAction"/> :ctxAction="ctxAction"
:toast="toast"/>
</div> </div>
</template> </template>
@ -60,7 +61,8 @@
loading: true, loading: true,
alwaysOnTop: false, alwaysOnTop: false,
error: undefined, error: undefined,
lastSaved: undefined lastSaved: undefined,
toast: { active: false, msg: '' }
} }
}, },
components: { BDEdit }, components: { BDEdit },
@ -218,15 +220,23 @@
this.loading = true; this.loading = true;
const { oldName, newName } = item; const { oldName, newName } = item;
if (this.files.find(f => f.name === newName)) {
this.loading = false;
this.showToast('err', `File ${newName} already exists`);
return {
err: `File ${newName} already exists`
};
}
try { try {
await ClientIPC.send('rnFile', { oldName: ['userfiles', oldName], newName: ['userfiles', newName] }); await ClientIPC.send('rnFile', { oldName: ['userfiles', oldName], newName: ['userfiles', newName] });
return item;
} catch (err) { } catch (err) {
console.log(err); console.log(err);
return { err };
} finally { } finally {
this.loading = false; this.loading = false;
} }
return;
} }
if (action === 'delete') { if (action === 'delete') {
@ -242,6 +252,11 @@
} }
}, },
showToast(type, msg, timeout = 3000) {
this.toast = { active: true, type, msg };
setTimeout(() => { this.toast.active = false }, timeout);
},
toggleLiveUpdate(item) { toggleLiveUpdate(item) {
item.liveUpdateEnabled = !item.liveUpdateEnabled; item.liveUpdateEnabled = !item.liveUpdateEnabled;
return item; return item;