feat: prompt to confirm discard editor changes (#2948)

* chore: update he.json

* feat: prompt to confirm discard editor changes

---------

Co-authored-by: Oleg Lobanov <oleg@lobanov.me>
This commit is contained in:
Shlomo 2024-01-30 11:48:03 +02:00 committed by GitHub
parent b19710efca
commit fb1a09c7c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 63 additions and 9 deletions

View File

@ -0,0 +1,45 @@
<template>
<div class="card floating">
<div class="card-content">
<p>
{{ $t("prompts.discardEditorChanges") }}
</p>
</div>
<div class="card-action">
<button
@click="$store.commit('closeHovers')"
class="button button--flat button--grey"
:aria-label="$t('buttons.cancel')"
:title="$t('buttons.cancel')"
>
{{ $t("buttons.cancel") }}
</button>
<button
@click="submit"
class="button button--flat button--red"
:aria-label="$t('buttons.discardChanges')"
:title="$t('buttons.discardChanges')"
>
{{ $t("buttons.discardChanges") }}
</button>
</div>
</div>
</template>
<script>
import { mapMutations } from "vuex";
import url from "@/utils/url";
export default {
name: "discardEditorChanges",
methods: {
...mapMutations(["closeHovers"]),
submit: async function () {
this.$store.commit("updateRequest", {});
let uri = url.removeLastDir(this.$route.path) + "/";
this.$router.push({ path: uri });
},
},
};
</script>

View File

@ -27,6 +27,7 @@ import Share from "./Share.vue";
import Upload from "./Upload.vue"; import Upload from "./Upload.vue";
import ShareDelete from "./ShareDelete.vue"; import ShareDelete from "./ShareDelete.vue";
import Sidebar from "../Sidebar.vue"; import Sidebar from "../Sidebar.vue";
import DiscardEditorChanges from "./DiscardEditorChanges.vue";
import { mapGetters, mapState } from "vuex"; import { mapGetters, mapState } from "vuex";
import buttons from "@/utils/buttons"; import buttons from "@/utils/buttons";
@ -47,7 +48,8 @@ export default {
ReplaceRename, ReplaceRename,
Upload, Upload,
ShareDelete, ShareDelete,
Sidebar Sidebar,
DiscardEditorChanges,
}, },
data: function () { data: function () {
return { return {

View File

@ -38,7 +38,8 @@
"update": "Update", "update": "Update",
"upload": "Upload", "upload": "Upload",
"openFile": "Open file", "openFile": "Open file",
"continue": "Continue" "continue": "Continue",
"discardChanges": "Discard"
}, },
"download": { "download": {
"downloadFile": "Download File", "downloadFile": "Download File",
@ -162,7 +163,8 @@
"uploadFiles": "Uploading {files} files...", "uploadFiles": "Uploading {files} files...",
"uploadMessage": "Select an option to upload.", "uploadMessage": "Select an option to upload.",
"optionalPassword": "Optional password", "optionalPassword": "Optional password",
"resolution": "Resolution" "resolution": "Resolution",
"discardEditorChanges": "Are you sure you wish to discard the changes you've made?"
}, },
"search": { "search": {
"images": "Images", "images": "Images",

View File

@ -38,7 +38,8 @@
"update": "עדכון", "update": "עדכון",
"upload": "העלאה", "upload": "העלאה",
"openFile": "פתח קובץ", "openFile": "פתח קובץ",
"continue": "המשך" "continue": "המשך",
"discardChanges": "זריקת השינויים"
}, },
"download": { "download": {
"downloadFile": "הורד קובץ", "downloadFile": "הורד קובץ",
@ -160,7 +161,8 @@
"upload": "העלאה", "upload": "העלאה",
"uploadFiles": "מעלה {files} קבצים...", "uploadFiles": "מעלה {files} קבצים...",
"uploadMessage": "בחר אפשרות העלאה.", "uploadMessage": "בחר אפשרות העלאה.",
"optionalPassword": "סיסמא אופציונלית" "optionalPassword": "סיסמא אופציונלית",
"discardEditorChanges": "האם אתה בטוח שברצונך לבטל את השינויים שביצעת?"
}, },
"search": { "search": {
"images": "תמונות", "images": "תמונות",

View File

@ -107,10 +107,6 @@ export default {
this.editor.focus(); this.editor.focus();
}, },
methods: { methods: {
back() {
let uri = url.removeLastDir(this.$route.path) + "/";
this.$router.push({ path: uri });
},
keyEvent(event) { keyEvent(event) {
if (event.code === "Escape") { if (event.code === "Escape") {
this.close(); this.close();
@ -140,6 +136,13 @@ export default {
} }
}, },
close() { close() {
const originalContent = this.req.content;
const currentContent = this.editor.getValue();
if (originalContent !== currentContent) {
this.$store.commit("showHover", "discardEditorChanges");
return;
}
this.$store.commit("updateRequest", {}); this.$store.commit("updateRequest", {});
let uri = url.removeLastDir(this.$route.path) + "/"; let uri = url.removeLastDir(this.$route.path) + "/";