Skip to content

Commit

Permalink
fix: tab system breaks when a new tab is created while waiting for re…
Browse files Browse the repository at this point in the history
…sponse in another tab (hoppscotch#3031)
  • Loading branch information
anwarulislam authored and AndrewBastin committed May 11, 2023
1 parent b7c2d13 commit 3f35fed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ const requestName = ref(
)

watch(
() => [currentActiveTab.value.document.request.name, gqlRequestName.value],
() => [currentActiveTab.value, gqlRequestName.value],
() => {
if (props.mode === "rest")
requestName.value = currentActiveTab.value.document.request.name
else requestName.value = gqlRequestName.value
if (props.mode === "rest") {
requestName.value = currentActiveTab.value?.document.request.name ?? ""
} else requestName.value = gqlRequestName.value
}
)

Expand Down
40 changes: 5 additions & 35 deletions packages/hoppscotch-common/src/components/http/Request.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,10 @@ import { useI18n } from "@composables/i18n"
import { useSetting } from "@composables/settings"
import { useStreamSubscriber } from "@composables/stream"
import { useToast } from "@composables/toast"
import { completePageProgress, startPageProgress } from "@modules/loadingbar"
import { refAutoReset, useVModel } from "@vueuse/core"
import * as E from "fp-ts/Either"
import { isLeft, isRight } from "fp-ts/lib/Either"
import { computed, ref, watch } from "vue"
import { computed, onBeforeUnmount, ref } from "vue"
import { defineActionHandler } from "~/helpers/actions"
import { runMutation } from "~/helpers/backend/GQLClient"
import { UpdateRequestDocument } from "~/helpers/backend/graphql"
Expand Down Expand Up @@ -311,39 +310,6 @@ const clearAll = ref<any | null>(null)
const copyRequestAction = ref<any | null>(null)
const saveRequestAction = ref<any | null>(null)
// Update Nuxt Loading bar
watch(loading, () => {
if (loading.value) {
startPageProgress()
} else {
completePageProgress()
}
})
// TODO: make this oAuthURL() work
// function oAuthURL() {
// const auth = useReadonlyStream(props.request.auth$, {
// authType: "none",
// authActive: true,
// })
// const oauth2Token = pluckRef(auth as Ref<HoppRESTAuthOAuth2>, "token")
// onBeforeMount(async () => {
// try {
// const tokenInfo = await oauthRedirect()
// if (Object.prototype.hasOwnProperty.call(tokenInfo, "access_token")) {
// if (typeof tokenInfo === "object") {
// oauth2Token.value = tokenInfo.access_token
// }
// }
// // eslint-disable-next-line no-empty
// } catch (_) {}
// })
// }
const newSendRequest = async () => {
if (newEndpoint.value === "" || /^\s+$/.test(newEndpoint.value)) {
toast.error(`${t("empty.endpoint")}`)
Expand Down Expand Up @@ -574,6 +540,10 @@ const saveRequest = () => {
}
}
onBeforeUnmount(() => {
if (loading.value) cancelRequest()
})
defineActionHandler("request.send-cancel", () => {
if (!loading.value) newSendRequest()
else cancelRequest()
Expand Down
8 changes: 1 addition & 7 deletions packages/hoppscotch-common/src/components/http/Response.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
</template>

<script setup lang="ts">
import { computed, ref, watch } from "vue"
import { startPageProgress, completePageProgress } from "@modules/loadingbar"
import { computed, ref } from "vue"
import { HoppRESTTab } from "~/helpers/rest/tab"
import { useVModel } from "@vueuse/core"
Expand All @@ -34,9 +33,4 @@ const hasResponse = computed(
)
const loading = computed(() => tab.value.response?.type === "loading")
watch(loading, (isLoading) => {
if (isLoading) startPageProgress()
else completePageProgress()
})
</script>

0 comments on commit 3f35fed

Please sign in to comment.