ResponseMeta.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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="my-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. :alt="$t('empty.network_fail')"
  83. />
  84. <span class="text-center mb-2">
  85. {{ $t("error.network_fail") }}
  86. </span>
  87. <span class="text-center mb-4 max-w-sm">
  88. {{ $t("helpers.network_fail") }}
  89. </span>
  90. <ButtonSecondary
  91. outline
  92. :label="$t('action.learn_more')"
  93. to="https://docs.hoppscotch.io"
  94. blank
  95. svg="external-link"
  96. reverse
  97. />
  98. </div>
  99. <div
  100. v-if="response.type === 'success' || 'fail'"
  101. :class="statusCategory.className"
  102. class="font-semibold space-x-4"
  103. >
  104. <span v-if="response.statusCode">
  105. <span class="text-secondary"> {{ $t("response.status") }}: </span>
  106. {{ response.statusCode || $t("state.waiting_send_request") }}
  107. </span>
  108. <span v-if="response.meta && response.meta.responseDuration">
  109. <span class="text-secondary"> {{ $t("response.time") }}: </span>
  110. {{ `${response.meta.responseDuration} ms` }}
  111. </span>
  112. <span v-if="response.meta && response.meta.responseSize">
  113. <span class="text-secondary"> {{ $t("response.size") }}: </span>
  114. {{ `${response.meta.responseSize} B` }}
  115. </span>
  116. </div>
  117. </div>
  118. </div>
  119. </template>
  120. <script setup lang="ts">
  121. import { computed } from "@nuxtjs/composition-api"
  122. import findStatusGroup from "~/helpers/findStatusGroup"
  123. import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
  124. import { getPlatformSpecialKey as getSpecialKey } from "~/helpers/platformutils"
  125. const props = defineProps<{
  126. response: HoppRESTResponse
  127. }>()
  128. const statusCategory = computed(() => {
  129. if (
  130. props.response.type === "loading" ||
  131. props.response.type === "network_fail"
  132. )
  133. return ""
  134. return findStatusGroup(props.response.statusCode)
  135. })
  136. </script>
  137. <style lang="scss" scoped>
  138. .shortcut-key {
  139. @apply bg-dividerLight;
  140. @apply rounded;
  141. @apply ml-2;
  142. @apply py-1;
  143. @apply px-2;
  144. @apply inline-flex;
  145. }
  146. </style>