fix: catch an edge case while saving request

This commit is contained in:
liyasthomas
2021-12-05 18:21:41 +05:30
parent fb6015ce26
commit e7535d505e
3 changed files with 23 additions and 5 deletions

View File

@@ -198,6 +198,7 @@ import {
getRESTSaveContext, getRESTSaveContext,
getRESTRequest, getRESTRequest,
restRequest$, restRequest$,
setRESTSaveContext,
} from "~/newstore/RESTSession" } from "~/newstore/RESTSession"
import { editRESTRequest } from "~/newstore/collections" import { editRESTRequest } from "~/newstore/collections"
import { runRESTRequest$ } from "~/helpers/RequestRunner" import { runRESTRequest$ } from "~/helpers/RequestRunner"
@@ -418,8 +419,17 @@ const saveRequest = () => {
} }
if (saveCtx.originLocation === "user-collection") { if (saveCtx.originLocation === "user-collection") {
editRESTRequest(saveCtx.folderPath, saveCtx.requestIndex, getRESTRequest()) try {
toast.success(`${t("request.saved")}`) editRESTRequest(
saveCtx.folderPath,
saveCtx.requestIndex,
getRESTRequest()
)
toast.success(`${t("request.saved")}`)
} catch (e) {
setRESTSaveContext(null)
saveRequest()
}
} else if (saveCtx.originLocation === "team-collection") { } else if (saveCtx.originLocation === "team-collection") {
const req = getRESTRequest() const req = getRESTRequest()

View File

@@ -73,7 +73,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from "@nuxtjs/composition-api" import { defineComponent, onBeforeUnmount } from "@nuxtjs/composition-api"
import { useKeybindingDisabler } from "~/helpers/keybindings" import { useKeybindingDisabler } from "~/helpers/keybindings"
const PORTAL_DOM_ID = "hoppscotch-modal-portal" const PORTAL_DOM_ID = "hoppscotch-modal-portal"
@@ -118,9 +118,12 @@ export default defineComponent({
setup() { setup() {
const { disableKeybindings, enableKeybindings } = useKeybindingDisabler() const { disableKeybindings, enableKeybindings } = useKeybindingDisabler()
onBeforeUnmount(() => {
enableKeybindings()
})
return { return {
disableKeybindings, disableKeybindings,
enableKeybindings,
} }
}, },
data() { data() {
@@ -154,7 +157,6 @@ export default defineComponent({
methods: { methods: {
close() { close() {
this.$emit("close") this.$emit("close")
this.enableKeybindings()
}, },
onKeyDown(e: KeyboardEvent) { onKeyDown(e: KeyboardEvent) {
if (e.key === "Escape" && this.stackId === stack.peek()) { if (e.key === "Escape" && this.stackId === stack.peek()) {

View File

@@ -744,6 +744,12 @@ export function editRESTRequest(
requestIndex: number, requestIndex: number,
requestNew: HoppRESTRequest requestNew: HoppRESTRequest
) { ) {
const indexPaths = path.split("/").map((x) => parseInt(x))
if (
!navigateToFolderWithIndexPath(restCollectionStore.value.state, indexPaths)
)
throw new Error("Path not found")
restCollectionStore.dispatch({ restCollectionStore.dispatch({
dispatcher: "editRequest", dispatcher: "editRequest",
payload: { payload: {