Request.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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="bg-primaryLight border border-divider rounded text-secondaryDark w-full py-2 px-4 hover:border-dividerDark focus-visible:bg-transparent focus-visible:border-dividerDark"
  11. :placeholder="`${t('request.url')}`"
  12. :disabled="connected"
  13. @keyup.enter="onConnectClick"
  14. />
  15. <ButtonPrimary
  16. id="get"
  17. name="get"
  18. :label="!connected ? t('action.connect') : t('action.disconnect')"
  19. class="w-32"
  20. @click.native="onConnectClick"
  21. />
  22. </div>
  23. </div>
  24. </template>
  25. <script setup lang="ts">
  26. import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
  27. import { GQLConnection } from "~/helpers/GQLConnection"
  28. import { getCurrentStrategyID } from "~/helpers/network"
  29. import {
  30. useReadonlyStream,
  31. useStream,
  32. useI18n,
  33. } from "~/helpers/utils/composables"
  34. import { gqlHeaders$, gqlURL$, setGQLURL } from "~/newstore/GQLSession"
  35. const t = useI18n()
  36. const props = defineProps<{
  37. conn: GQLConnection
  38. }>()
  39. const connected = useReadonlyStream(props.conn.connected$, false)
  40. const headers = useReadonlyStream(gqlHeaders$, [])
  41. const url = useStream(gqlURL$, "", setGQLURL)
  42. const onConnectClick = () => {
  43. if (!connected.value) {
  44. props.conn.connect(url.value, headers.value as any)
  45. logHoppRequestRunToAnalytics({
  46. platform: "graphql-schema",
  47. strategy: getCurrentStrategyID(),
  48. })
  49. } else {
  50. props.conn.disconnect()
  51. }
  52. }
  53. </script>