Request.vue 1.7 KB

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