Body.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div>
  3. <div
  4. class="
  5. bg-primary
  6. border-b border-dividerLight
  7. flex flex-1
  8. top-upperSecondaryStickyFold
  9. pl-4
  10. z-10
  11. sticky
  12. items-center
  13. justify-between
  14. "
  15. >
  16. <span class="flex items-center">
  17. <label class="font-semibold text-secondaryLight">
  18. {{ $t("request.content_type") }}
  19. </label>
  20. <tippy
  21. ref="contentTypeOptions"
  22. interactive
  23. trigger="click"
  24. theme="popover"
  25. arrow
  26. >
  27. <template #trigger>
  28. <span class="select-wrapper">
  29. <ButtonSecondary
  30. :label="contentType || $t('state.none').toLowerCase()"
  31. class="rounded-none ml-2 pr-8"
  32. />
  33. </span>
  34. </template>
  35. <SmartItem
  36. :label="$t('state.none').toLowerCase()"
  37. :info-icon="contentType === null ? 'done' : ''"
  38. :active-info-icon="contentType === null"
  39. @click.native="
  40. () => {
  41. contentType = null
  42. $refs.contentTypeOptions.tippy().hide()
  43. }
  44. "
  45. />
  46. <SmartItem
  47. v-for="(contentTypeItem, index) in validContentTypes"
  48. :key="`contentTypeItem-${index}`"
  49. :label="contentTypeItem"
  50. :info-icon="contentTypeItem === contentType ? 'done' : ''"
  51. :active-info-icon="contentTypeItem === contentType"
  52. @click.native="
  53. () => {
  54. contentType = contentTypeItem
  55. $refs.contentTypeOptions.tippy().hide()
  56. }
  57. "
  58. />
  59. </tippy>
  60. </span>
  61. </div>
  62. <HttpBodyParameters v-if="contentType === 'multipart/form-data'" />
  63. <HttpRawBody v-else-if="contentType !== null" :content-type="contentType" />
  64. <div
  65. v-if="contentType == null"
  66. class="flex flex-col text-secondaryLight p-4 items-center justify-center"
  67. >
  68. <img
  69. :src="`/images/states/${$colorMode.value}/upload_single_file.svg`"
  70. loading="lazy"
  71. class="flex-col my-4 object-contain object-center h-16 w-16 inline-flex"
  72. />
  73. <span class="text-center pb-4">
  74. {{ $t("empty.body") }}
  75. </span>
  76. <ButtonSecondary
  77. outline
  78. :label="`${$t('app.documentation')}`"
  79. to="https://docs.hoppscotch.io"
  80. blank
  81. svg="external-link"
  82. reverse
  83. />
  84. </div>
  85. </div>
  86. </template>
  87. <script lang="ts">
  88. import { defineComponent } from "@nuxtjs/composition-api"
  89. import { useStream } from "~/helpers/utils/composables"
  90. import { restContentType$, setRESTContentType } from "~/newstore/RESTSession"
  91. import { knownContentTypes } from "~/helpers/utils/contenttypes"
  92. export default defineComponent({
  93. setup() {
  94. return {
  95. validContentTypes: Object.keys(knownContentTypes),
  96. contentType: useStream(restContentType$, null, setRESTContentType),
  97. }
  98. },
  99. })
  100. </script>