diff --git a/editor/src/Editor.vue b/editor/src/Editor.vue index 68336b18..aea6acf1 100644 --- a/editor/src/Editor.vue +++ b/editor/src/Editor.vue @@ -25,7 +25,8 @@ :readSnippet="readSnippet" :injectStyle="injectStyle" :toggleLiveUpdate="toggleLiveUpdate" - :ctxAction="ctxAction"/> + :ctxAction="ctxAction" + :toast="toast"/> @@ -60,7 +61,8 @@ loading: true, alwaysOnTop: false, error: undefined, - lastSaved: undefined + lastSaved: undefined, + toast: { active: false, msg: '' } } }, components: { BDEdit }, @@ -218,15 +220,23 @@ this.loading = true; 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 { await ClientIPC.send('rnFile', { oldName: ['userfiles', oldName], newName: ['userfiles', newName] }); + return item; } catch (err) { console.log(err); + return { err }; } finally { this.loading = false; } - - return; } 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) { item.liveUpdateEnabled = !item.liveUpdateEnabled; return item;