[blockly] Show toast instead of error when saving / running from code preview (#1899)

Since the very beginning of Blockly a not very meaningful error message was alerted when the user attempted to run/save a Blockly from the code preview. 
This detects that situation and shows a nice toast instead of the cryptic error alert.

Also-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Stefan Höhn <mail@stefanhoehn.com>
pull/1904/head
stefan-hoehn 2023-05-16 19:22:59 +02:00 committed by GitHub
parent ae4b729b29
commit 55c72349e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 6 deletions

View File

@ -2,8 +2,8 @@
<f7-page @page:afterin="onPageAfterIn" @page:beforeout="onPageBeforeOut">
<f7-navbar :title="pageTitle" :subtitle="(!newScript) ? mode : undefined" back-link="Back">
<f7-nav-right v-if="isEditable && !newScript">
<f7-link @click="save()" v-if="$theme.md" icon-md="material:save" icon-only />
<f7-link @click="save()" v-if="!$theme.md">
<f7-link @click="onSave()" v-if="$theme.md" icon-md="material:save" icon-only />
<f7-link @click="onSave()" v-if="!$theme.md">
Save<span v-if="$device.desktop">&nbsp;(Ctrl-S)</span>
</f7-link>
</f7-nav-right>
@ -306,12 +306,23 @@ export default {
destroyOnClose: true,
closeTimeout: 2000
}).open()
return Promise.reject()
return Promise.reject('saveWhileRunningRejected')
}
if (this.isBlockly) {
try {
this.currentModule.configuration.blockSource = this.$refs.blocklyEditor.getBlocks()
this.script = this.$refs.blocklyEditor.getCode()
if (!this.blocklyCodePreview) {
this.currentModule.configuration.blockSource = this.$refs.blocklyEditor.getBlocks()
this.script = this.$refs.blocklyEditor.getCode()
} else {
this.$f7.toast.create({
text: 'Running / saving is only supported in block mode!<br>Please switch back from code preview to block editor.',
position: 'center',
icon: '<i class="f7-icons">exclamationmark_bubble</i>',
destroyOnClose: true,
closeTimeout: 3000
}).open()
return Promise.reject('saveOnCodePreviewRejected')
}
} catch (e) {
this.$f7.dialog.alert(e)
return Promise.reject(e)
@ -336,6 +347,9 @@ export default {
}).open()
})
},
onSave () {
this.save().catch((e) => { if (!['saveWhileRunningRejected', 'saveOnCodePreviewRejected'].includes(e)) { throw (e) } })
},
changeLanguage (contentType) {
if (this.createMode) return
this.mode = contentType
@ -383,6 +397,7 @@ export default {
}).open()
})
})
.catch((e) => { if (e !== 'saveOnCodePreviewRejected') { throw (e) } })
},
deleteRule () {
this.$f7.dialog.confirm(
@ -458,7 +473,7 @@ export default {
ev.preventDefault()
break
case 83:
this.save()
this.onSave()
ev.stopPropagation()
ev.preventDefault()
break