Files
parcer/src/context/browserActions.tsx

43 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-07-24 19:29:52 +05:30
import React, { createContext, useState, useContext, ReactNode } from 'react';
interface ActionContextType {
getText: boolean;
getScreenshot: boolean;
handleGetText: () => void;
handleGetScreenshot: () => void;
resetActions: () => void;
}
2024-07-24 19:30:22 +05:30
const ActionContext = createContext<ActionContextType | undefined>(undefined);
export const useActionContext = (): ActionContextType => {
const context = useContext(ActionContext);
if (context === undefined) {
throw new Error('useActionContext must be used within an ActionProvider');
}
return context;
};
2024-07-24 19:30:42 +05:30
interface ActionProviderProps {
children: ReactNode;
}
export const ActionProvider: React.FC<ActionProviderProps> = ({ children }) => {
const [getText, setGetText] = useState<boolean>(false);
const [getScreenshot, setGetScreenshot] = useState<boolean>(false);
const handleGetText = () => setGetText(true);
const handleGetScreenshot = () => setGetScreenshot(true);
2024-07-24 19:30:55 +05:30
// Reset actions (optional)
const resetActions = () => {
setGetText(false);
setGetScreenshot(false);
};
2024-07-24 19:30:42 +05:30
return (
<ActionContext.Provider value={{ getText, getScreenshot, handleGetText, handleGetScreenshot, resetActions }}>
{children}
</ActionContext.Provider>
);
2024-07-24 19:31:20 +05:30
};