Body.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. :alt="$t('empty.body')"
  73. />
  74. <span class="text-center pb-4">
  75. {{ $t("empty.body") }}
  76. </span>
  77. <ButtonSecondary
  78. outline
  79. :label="`${$t('app.documentation')}`"
  80. to="https://docs.hoppscotch.io"
  81. blank
  82. svg="external-link"
  83. reverse
  84. class="mb-4"
  85. />
  86. </div>
  87. </div>
  88. </template>
  89. <script lang="ts">
  90. import { defineComponent } from "@nuxtjs/composition-api"
  91. import { useStream } from "~/helpers/utils/composables"
  92. import { restContentType$, setRESTContentType } from "~/newstore/RESTSession"
  93. import { knownContentTypes } from "~/helpers/utils/contenttypes"
  94. export default defineComponent({
  95. setup() {
  96. return {
  97. validContentTypes: Object.keys(knownContentTypes),
  98. contentType: useStream(restContentType$, null, setRESTContentType),
  99. }
  100. },
  101. })
  102. </script>