ResponseMeta.vue 4.1 KB

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