ResponseMeta.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div
  3. class="bg-primary flex p-4 top-0 z-10 sticky items-center overflow-auto hide-scrollbar whitespace-nowrap"
  4. >
  5. <div
  6. v-if="response == null"
  7. class="flex flex-col flex-1 text-secondaryLight items-center justify-center"
  8. >
  9. <div class="flex space-x-2 my-4 pb-4">
  10. <div class="flex flex-col space-y-4 text-right items-end">
  11. <span class="flex flex-1 items-center">
  12. {{ t("shortcut.request.send_request") }}
  13. </span>
  14. <span class="flex flex-1 items-center">
  15. {{ t("shortcut.general.show_all") }}
  16. </span>
  17. <span class="flex flex-1 items-center">
  18. {{ t("shortcut.general.command_menu") }}
  19. </span>
  20. <span class="flex flex-1 items-center">
  21. {{ t("shortcut.general.help_menu") }}
  22. </span>
  23. </div>
  24. <div class="flex flex-col space-y-4">
  25. <div class="flex">
  26. <span class="shortcut-key">{{ getSpecialKey() }}</span>
  27. <span class="shortcut-key">G</span>
  28. </div>
  29. <div class="flex">
  30. <span class="shortcut-key">{{ getSpecialKey() }}</span>
  31. <span class="shortcut-key">K</span>
  32. </div>
  33. <div class="flex">
  34. <span class="shortcut-key">/</span>
  35. </div>
  36. <div class="flex">
  37. <span class="shortcut-key">?</span>
  38. </div>
  39. </div>
  40. </div>
  41. <ButtonSecondary
  42. :label="t('app.documentation')"
  43. to="https://docs.hoppscotch.io/features/response"
  44. svg="external-link"
  45. blank
  46. outline
  47. reverse
  48. />
  49. </div>
  50. <div v-else class="flex flex-col flex-1">
  51. <div
  52. v-if="response.type === 'loading'"
  53. class="flex flex-col items-center justify-center"
  54. >
  55. <SmartSpinner class="my-4" />
  56. <span class="text-secondaryLight">{{ t("state.loading") }}</span>
  57. </div>
  58. <div
  59. v-if="response.type === 'network_fail'"
  60. class="flex flex-col flex-1 p-4 items-center justify-center"
  61. >
  62. <img
  63. :src="`/images/states/${$colorMode.value}/youre_lost.svg`"
  64. loading="lazy"
  65. class="flex-col object-contain object-center h-32 my-4 w-32 inline-flex"
  66. :alt="`${t('error.network_fail')}`"
  67. />
  68. <span class="font-semibold text-center mb-2">
  69. {{ t("error.network_fail") }}
  70. </span>
  71. <span
  72. class="max-w-sm text-secondaryLight text-center mb-4 whitespace-normal"
  73. >
  74. {{ t("helpers.network_fail") }}
  75. </span>
  76. <AppInterceptor />
  77. </div>
  78. <div
  79. v-if="response.type === 'script_fail'"
  80. class="flex flex-col flex-1 p-4 items-center justify-center"
  81. >
  82. <img
  83. :src="`/images/states/${$colorMode.value}/youre_lost.svg`"
  84. loading="lazy"
  85. class="flex-col object-contain object-center h-32 my-4 w-32 inline-flex"
  86. :alt="`${t('error.script_fail')}`"
  87. />
  88. <span class="font-semibold text-center mb-2">
  89. {{ t("error.script_fail") }}
  90. </span>
  91. <span
  92. class="max-w-sm text-secondaryLight text-center mb-4 whitespace-normal"
  93. >
  94. {{ t("helpers.script_fail") }}
  95. </span>
  96. <div
  97. class="bg-primaryLight rounded font-mono w-full py-2 px-4 text-red-400 overflow-auto whitespace-normal"
  98. >
  99. {{ response.error.name }}: {{ response.error.message }}<br />
  100. {{ response.error.stack }}
  101. </div>
  102. </div>
  103. <div
  104. v-if="response.type === 'success' || 'fail'"
  105. :class="statusCategory.className"
  106. class="font-semibold space-x-4"
  107. >
  108. <span v-if="response.statusCode">
  109. <span class="text-secondary"> {{ t("response.status") }}: </span>
  110. {{ response.statusCode || t("state.waiting_send_request") }}
  111. </span>
  112. <span v-if="response.meta && response.meta.responseDuration">
  113. <span class="text-secondary"> {{ t("response.time") }}: </span>
  114. {{ `${response.meta.responseDuration} ms` }}
  115. </span>
  116. <span v-if="response.meta && response.meta.responseSize">
  117. <span class="text-secondary"> {{ t("response.size") }}: </span>
  118. {{ `${response.meta.responseSize} B` }}
  119. </span>
  120. </div>
  121. </div>
  122. </div>
  123. </template>
  124. <script setup lang="ts">
  125. import { computed } from "@nuxtjs/composition-api"
  126. import findStatusGroup from "~/helpers/findStatusGroup"
  127. import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
  128. import { getPlatformSpecialKey as getSpecialKey } from "~/helpers/platformutils"
  129. import { useI18n } from "~/helpers/utils/composables"
  130. const t = useI18n()
  131. const props = defineProps<{
  132. response: HoppRESTResponse
  133. }>()
  134. const statusCategory = computed(() => {
  135. if (
  136. props.response.type === "loading" ||
  137. props.response.type === "network_fail" ||
  138. props.response.type === "script_fail"
  139. )
  140. return ""
  141. return findStatusGroup(props.response.statusCode)
  142. })
  143. </script>
  144. <style lang="scss" scoped>
  145. .shortcut-key {
  146. @apply bg-dividerLight;
  147. @apply rounded;
  148. @apply ml-2;
  149. @apply py-1;
  150. @apply px-2;
  151. @apply inline-flex;
  152. }
  153. </style>