Request.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <div
  3. class="sticky top-0 z-10 flex flex-shrink-0 p-4 overflow-x-auto space-x-2 bg-primary hide-scrollbar"
  4. >
  5. <div class="inline-flex flex-1 space-x-2">
  6. <input
  7. id="url"
  8. v-model="url"
  9. type="url"
  10. autocomplete="off"
  11. spellcheck="false"
  12. class="w-full px-4 py-2 border rounded bg-primaryLight border-divider text-secondaryDark"
  13. :placeholder="`${t('request.url')}`"
  14. :disabled="connected"
  15. @keyup.enter="onConnectClick"
  16. />
  17. <ButtonPrimary
  18. id="get"
  19. name="get"
  20. :label="!connected ? t('action.connect') : t('action.disconnect')"
  21. class="w-32"
  22. @click.native="onConnectClick"
  23. />
  24. </div>
  25. </div>
  26. </template>
  27. <script setup lang="ts">
  28. import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
  29. import { GQLConnection } from "~/helpers/GQLConnection"
  30. import { getCurrentStrategyID } from "~/helpers/network"
  31. import {
  32. useReadonlyStream,
  33. useStream,
  34. useI18n,
  35. } from "~/helpers/utils/composables"
  36. import { gqlHeaders$, gqlURL$, setGQLURL } from "~/newstore/GQLSession"
  37. const t = useI18n()
  38. const props = defineProps<{
  39. conn: GQLConnection
  40. }>()
  41. const connected = useReadonlyStream(props.conn.connected$, false)
  42. const headers = useReadonlyStream(gqlHeaders$, [])
  43. const url = useStream(gqlURL$, "", setGQLURL)
  44. const onConnectClick = () => {
  45. if (!connected.value) {
  46. props.conn.connect(url.value, headers.value as any)
  47. logHoppRequestRunToAnalytics({
  48. platform: "graphql-schema",
  49. strategy: getCurrentStrategyID(),
  50. })
  51. } else {
  52. props.conn.disconnect()
  53. }
  54. }
  55. </script>