Request.vue 1.7 KB

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