ResponseMeta.vue 4.3 KB

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