Files
parcer/src/context/browserActions.tsx

37 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-07-24 21:34:28 +05:30
import React, { createContext, useContext, useState, ReactNode } from 'react';
2024-07-24 19:29:52 +05:30
2024-07-24 21:34:28 +05:30
interface ActionContextProps {
2024-07-24 19:29:52 +05:30
getText: boolean;
getScreenshot: boolean;
2024-07-24 21:34:28 +05:30
startGetText: () => void;
stopGetText: () => void;
startGetScreenshot: () => void;
stopGetScreenshot: () => void;
2024-07-24 19:29:52 +05:30
}
2024-07-24 21:34:28 +05:30
const ActionContext = createContext<ActionContextProps | undefined>(undefined);
2024-07-24 19:30:22 +05:30
2024-07-24 21:34:28 +05:30
export const ActionProvider = ({ children }: { children: ReactNode }) => {
2024-07-24 19:30:42 +05:30
const [getText, setGetText] = useState<boolean>(false);
const [getScreenshot, setGetScreenshot] = useState<boolean>(false);
2024-07-24 21:34:28 +05:30
const startGetText = () => setGetText(true);
const stopGetText = () => setGetText(false);
2024-07-24 19:30:42 +05:30
2024-07-24 21:34:28 +05:30
const startGetScreenshot = () => setGetScreenshot(true);
const stopGetScreenshot = () => setGetScreenshot(false);
2024-07-24 19:30:42 +05:30
return (
2024-07-24 21:34:28 +05:30
<ActionContext.Provider value={{ getText, getScreenshot, startGetText, stopGetText, startGetScreenshot, stopGetScreenshot }}>
2024-07-24 19:30:42 +05:30
{children}
</ActionContext.Provider>
);
2024-07-24 21:34:28 +05:30
};
export const useActionContext = () => {
const context = useContext(ActionContext);
if (context === undefined) {
throw new Error('useActionContext must be used within an ActionProvider');
}
return context;
2024-07-24 21:34:58 +05:30
};