mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-07 08:24:27 +00:00
Remove more contexts
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
import React, { createContext, useContext, useEffect } from 'react';
|
||||
import { useFileManagementContext } from './FileManagementContext';
|
||||
|
||||
const EditorContentContext = createContext();
|
||||
|
||||
export const EditorContentProvider = ({ children }) => {
|
||||
const { content, handleContentChange, handleSave, selectedFile } =
|
||||
useFileManagementContext();
|
||||
|
||||
return (
|
||||
<EditorContentContext.Provider
|
||||
value={{ content, handleContentChange, handleSave }}
|
||||
>
|
||||
{children}
|
||||
</EditorContentContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useEditorContent = () => {
|
||||
const context = useContext(EditorContentContext);
|
||||
if (context === undefined) {
|
||||
throw new Error(
|
||||
'useEditorContent must be used within an EditorContentProvider'
|
||||
);
|
||||
}
|
||||
return context;
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
import React, { createContext, useContext, useMemo } from 'react';
|
||||
import { useFileManagement } from '../hooks/useFileManagement';
|
||||
|
||||
const FileManagementContext = createContext();
|
||||
|
||||
export const FileManagementProvider = ({ children }) => {
|
||||
const fileManagement = useFileManagement();
|
||||
|
||||
const value = useMemo(
|
||||
() => fileManagement,
|
||||
[
|
||||
fileManagement.selectedFile,
|
||||
fileManagement.isNewFile,
|
||||
fileManagement.content,
|
||||
fileManagement.isLoading,
|
||||
fileManagement.error,
|
||||
fileManagement.hasUnsavedChanges,
|
||||
]
|
||||
);
|
||||
|
||||
return (
|
||||
<FileManagementContext.Provider value={value}>
|
||||
{children}
|
||||
</FileManagementContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useFileManagementContext = () => {
|
||||
const context = useContext(FileManagementContext);
|
||||
if (context === undefined) {
|
||||
throw new Error(
|
||||
'useFileManagementContext must be used within a FileManagementProvider'
|
||||
);
|
||||
}
|
||||
return context;
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
import React, { createContext, useContext } from 'react';
|
||||
import { useFileManagementContext } from './FileManagementContext';
|
||||
|
||||
const FileSelectionContext = createContext();
|
||||
|
||||
export const FileSelectionProvider = ({ children }) => {
|
||||
const { selectedFile, handleFileSelect } = useFileManagementContext();
|
||||
|
||||
return (
|
||||
<FileSelectionContext.Provider value={{ selectedFile, handleFileSelect }}>
|
||||
{children}
|
||||
</FileSelectionContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useFileSelection = () => {
|
||||
const context = useContext(FileSelectionContext);
|
||||
if (context === undefined) {
|
||||
throw new Error(
|
||||
'useFileSelection must be used within a FileSelectionProvider'
|
||||
);
|
||||
}
|
||||
return context;
|
||||
};
|
||||
Reference in New Issue
Block a user