useSchemasForAi.ts 549 B

1234567891011121314151617181920
  1. import { LOCAL_STORAGE_KEYS } from 'common'
  2. import { Dispatch, SetStateAction } from 'react'
  3. import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage'
  4. /**
  5. * Returns which schemas are ok to be sent to AI.
  6. */
  7. export function useSchemasForAi(
  8. ref: string
  9. ): readonly [string[], Dispatch<SetStateAction<string[]>>] {
  10. const [enabledSchemas, setEnabledSchemas] = useLocalStorageQuery(
  11. LOCAL_STORAGE_KEYS.SQL_EDITOR_AI_SCHEMA(ref),
  12. ['public']
  13. )
  14. if (!ref) return [[], () => {}]
  15. return [enabledSchemas, setEnabledSchemas]
  16. }