feat: stop browser actions context
This commit is contained in:
@@ -1,43 +1,37 @@
|
|||||||
import React, { createContext, useState, useContext, ReactNode } from 'react';
|
import React, { createContext, useContext, useState, ReactNode } from 'react';
|
||||||
|
|
||||||
interface ActionContextType {
|
interface ActionContextProps {
|
||||||
getText: boolean;
|
getText: boolean;
|
||||||
getScreenshot: boolean;
|
getScreenshot: boolean;
|
||||||
handleGetText: () => void;
|
startGetText: () => void;
|
||||||
handleGetScreenshot: () => void;
|
stopGetText: () => void;
|
||||||
resetActions: () => void;
|
startGetScreenshot: () => void;
|
||||||
|
stopGetScreenshot: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ActionContext = createContext<ActionContextType | undefined>(undefined);
|
const ActionContext = createContext<ActionContextProps | undefined>(undefined);
|
||||||
|
|
||||||
export const useActionContext = (): ActionContextType => {
|
export const ActionProvider = ({ children }: { children: ReactNode }) => {
|
||||||
|
const [getText, setGetText] = useState<boolean>(false);
|
||||||
|
const [getScreenshot, setGetScreenshot] = useState<boolean>(false);
|
||||||
|
|
||||||
|
const startGetText = () => setGetText(true);
|
||||||
|
const stopGetText = () => setGetText(false);
|
||||||
|
|
||||||
|
const startGetScreenshot = () => setGetScreenshot(true);
|
||||||
|
const stopGetScreenshot = () => setGetScreenshot(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ActionContext.Provider value={{ getText, getScreenshot, startGetText, stopGetText, startGetScreenshot, stopGetScreenshot }}>
|
||||||
|
{children}
|
||||||
|
</ActionContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useActionContext = () => {
|
||||||
const context = useContext(ActionContext);
|
const context = useContext(ActionContext);
|
||||||
if (context === undefined) {
|
if (context === undefined) {
|
||||||
throw new Error('useActionContext must be used within an ActionProvider');
|
throw new Error('useActionContext must be used within an ActionProvider');
|
||||||
}
|
}
|
||||||
return context;
|
return context;
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Reset actions (optional)
|
|
||||||
const resetActions = () => {
|
|
||||||
setGetText(false);
|
|
||||||
setGetScreenshot(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ActionContext.Provider value={{ getText, getScreenshot, handleGetText, handleGetScreenshot, resetActions }}>
|
|
||||||
{children}
|
|
||||||
</ActionContext.Provider>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user