Body.vue 2.9 KB

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