ResponseMeta.vue 3.9 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">
  13. <div class="flex flex-col space-y-4 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 v-if="response.type === 'loading'">
  55. <i class="animate-spin material-icons"> refresh </i>
  56. </div>
  57. <div
  58. v-if="response.type === 'network_fail'"
  59. class="
  60. flex flex-col flex-1
  61. text-secondaryLight
  62. p-4
  63. items-center
  64. justify-center
  65. "
  66. >
  67. <i class="opacity-75 pb-2 material-icons">cloud_off</i>
  68. <span class="text-center pb-2">
  69. {{ $t("error.network_fail") }}
  70. </span>
  71. <span class="text-center pb-4">
  72. {{ $t("helpers.network_fail") }}
  73. </span>
  74. <ButtonSecondary
  75. outline
  76. :label="$t('action.learn_more')"
  77. to="https://docs.hoppscotch.io"
  78. blank
  79. svg="external-link"
  80. reverse
  81. />
  82. </div>
  83. <div
  84. v-if="response.type === 'success' || 'fail'"
  85. :class="statusCategory.className"
  86. class="font-semibold space-x-4"
  87. >
  88. <span v-if="response.statusCode">
  89. <span class="text-secondary"> {{ $t("response.status") }}: </span>
  90. {{ response.statusCode || $t("state.waiting_send_request") }}
  91. </span>
  92. <span v-if="response.meta && response.meta.responseDuration">
  93. <span class="text-secondary"> {{ $t("response.time") }}: </span>
  94. {{ `${response.meta.responseDuration} ms` }}
  95. </span>
  96. <span v-if="response.meta && response.meta.responseSize">
  97. <span class="text-secondary"> {{ $t("response.size") }}: </span>
  98. {{ `${response.meta.responseSize} B` }}
  99. </span>
  100. </div>
  101. </div>
  102. </div>
  103. </template>
  104. <script>
  105. import { defineComponent } from "@nuxtjs/composition-api"
  106. import findStatusGroup from "~/helpers/findStatusGroup"
  107. import { getPlatformSpecialKey } from "~/helpers/platformutils"
  108. export default defineComponent({
  109. props: {
  110. response: {
  111. type: Object,
  112. default: () => null,
  113. },
  114. },
  115. computed: {
  116. statusCategory() {
  117. return findStatusGroup(this.response.statusCode)
  118. },
  119. },
  120. methods: {
  121. getSpecialKey: getPlatformSpecialKey,
  122. },
  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>