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