2024-02-22 12:14:58 +00:00
|
|
|
import type { FileSchema } from "~/server/db/schema/file";
|
2024-02-20 18:03:43 +07:00
|
|
|
import { createContext, useContext } from "react";
|
|
|
|
|
2024-02-21 02:01:35 +07:00
|
|
|
type TEditorContext = {
|
2024-02-20 18:03:43 +07:00
|
|
|
onOpenFile: (fileId: number) => void;
|
|
|
|
onFileChanged: (file: Omit<FileSchema, "content">) => void;
|
|
|
|
onDeleteFile: (fileId: number) => void;
|
|
|
|
};
|
|
|
|
|
2024-02-21 02:01:35 +07:00
|
|
|
const EditorContext = createContext<TEditorContext | null>(null);
|
2024-02-20 18:03:43 +07:00
|
|
|
|
2024-02-21 02:01:35 +07:00
|
|
|
export const useEditorContext = () => {
|
|
|
|
const ctx = useContext(EditorContext);
|
2024-02-20 18:03:43 +07:00
|
|
|
if (!ctx) {
|
2024-02-21 02:01:35 +07:00
|
|
|
throw new Error("Component not in EditorContext!");
|
2024-02-20 18:03:43 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
};
|
|
|
|
|
2024-02-21 02:01:35 +07:00
|
|
|
export default EditorContext;
|