Body.vue 3.0 KB

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