Body.vue 2.8 KB

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