SchemaGraphContext.tsx26 lines · main
| 1 | import { Edge } from '@xyflow/react' |
| 2 | import { createContext, useContext, type ReactNode } from 'react' |
| 3 | |
| 4 | export type SchemaGraphContextType = { |
| 5 | isDownloading: boolean |
| 6 | selectedEdge: Edge | undefined |
| 7 | onEditColumn: (tableId: number, columnId: string) => void |
| 8 | onEditTable: (tableId: number) => void |
| 9 | } |
| 10 | |
| 11 | export const SchemaGraphContext = createContext<SchemaGraphContextType | null>(null) |
| 12 | |
| 13 | export const SchemaGraphContextProvider = ({ |
| 14 | children, |
| 15 | value, |
| 16 | }: { |
| 17 | children: ReactNode |
| 18 | value: SchemaGraphContextType |
| 19 | }) => <SchemaGraphContext.Provider value={value}>{children}</SchemaGraphContext.Provider> |
| 20 | |
| 21 | export const useSchemaGraphContext = () => { |
| 22 | const context = useContext(SchemaGraphContext) |
| 23 | if (!context) |
| 24 | throw new Error('useSchemaGraphContext must be used inside a <SchemaGraphContextProvider>') |
| 25 | return context |
| 26 | } |