ResponseMeta.vue 4.4 KB

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