ResponseMeta.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 my-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="flex flex-col flex-1 p-4 items-center justify-center"
  64. >
  65. <img
  66. :src="`/images/states/${$colorMode.value}/youre_lost.svg`"
  67. loading="lazy"
  68. class="
  69. flex-col
  70. my-4
  71. object-contain object-center
  72. h-32
  73. w-32
  74. inline-flex
  75. "
  76. :alt="$t('empty.network_fail')"
  77. />
  78. <span class="text-center font-semibold mb-2">
  79. {{ $t("error.network_fail") }}
  80. </span>
  81. <span class="text-center text-secondaryLight mb-4 max-w-sm">
  82. {{ $t("helpers.network_fail") }}
  83. </span>
  84. <AppInterceptor />
  85. </div>
  86. <div
  87. v-if="response.type === 'success' || 'fail'"
  88. :class="statusCategory.className"
  89. class="font-semibold space-x-4"
  90. >
  91. <span v-if="response.statusCode">
  92. <span class="text-secondary"> {{ $t("response.status") }}: </span>
  93. {{ response.statusCode || $t("state.waiting_send_request") }}
  94. </span>
  95. <span v-if="response.meta && response.meta.responseDuration">
  96. <span class="text-secondary"> {{ $t("response.time") }}: </span>
  97. {{ `${response.meta.responseDuration} ms` }}
  98. </span>
  99. <span v-if="response.meta && response.meta.responseSize">
  100. <span class="text-secondary"> {{ $t("response.size") }}: </span>
  101. {{ `${response.meta.responseSize} B` }}
  102. </span>
  103. </div>
  104. </div>
  105. </div>
  106. </template>
  107. <script setup lang="ts">
  108. import { computed } from "@nuxtjs/composition-api"
  109. import findStatusGroup from "~/helpers/findStatusGroup"
  110. import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
  111. import { getPlatformSpecialKey as getSpecialKey } from "~/helpers/platformutils"
  112. const props = defineProps<{
  113. response: HoppRESTResponse
  114. }>()
  115. const statusCategory = computed(() => {
  116. if (
  117. props.response.type === "loading" ||
  118. props.response.type === "network_fail"
  119. )
  120. return ""
  121. return findStatusGroup(props.response.statusCode)
  122. })
  123. </script>
  124. <style lang="scss" scoped>
  125. .shortcut-key {
  126. @apply bg-dividerLight;
  127. @apply rounded;
  128. @apply ml-2;
  129. @apply py-1;
  130. @apply px-2;
  131. @apply inline-flex;
  132. }
  133. </style>