Body.vue 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. contentType = null
  41. $refs.contentTypeOptions.tippy().hide()
  42. "
  43. />
  44. <SmartItem
  45. v-for="(contentTypeItem, index) in validContentTypes"
  46. :key="`contentTypeItem-${index}`"
  47. :label="contentTypeItem"
  48. :info-icon="contentTypeItem === contentType ? 'done' : ''"
  49. :active-info-icon="contentTypeItem === contentType"
  50. @click.native="
  51. contentType = contentTypeItem
  52. $refs.contentTypeOptions.tippy().hide()
  53. "
  54. />
  55. </tippy>
  56. </span>
  57. </div>
  58. <HttpBodyParameters v-if="contentType === 'multipart/form-data'" />
  59. <HttpRawBody v-else-if="contentType !== null" :content-type="contentType" />
  60. <div
  61. v-if="contentType == null"
  62. class="flex flex-col text-secondaryLight p-4 items-center justify-center"
  63. >
  64. <span class="text-center pb-4">
  65. {{ $t("empty.body") }}
  66. </span>
  67. <ButtonSecondary
  68. outline
  69. :label="$t('app.documentation')"
  70. to="https://docs.hoppscotch.io"
  71. blank
  72. svg="external-link"
  73. reverse
  74. />
  75. </div>
  76. </div>
  77. </template>
  78. <script lang="ts">
  79. import { defineComponent } from "@nuxtjs/composition-api"
  80. import { useStream } from "~/helpers/utils/composables"
  81. import { restContentType$, setRESTContentType } from "~/newstore/RESTSession"
  82. import { knownContentTypes } from "~/helpers/utils/contenttypes"
  83. export default defineComponent({
  84. setup() {
  85. return {
  86. validContentTypes: Object.keys(knownContentTypes),
  87. contentType: useStream(restContentType$, null, setRESTContentType),
  88. }
  89. },
  90. })
  91. </script>