ResponseMeta.vue 4.1 KB

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