Files
parcer/src/context/browserActions.tsx

50 lines
1.7 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;
2024-08-08 00:17:47 +05:30
getList: boolean;
2024-07-24 19:29:52 +05:30
getScreenshot: boolean;
2024-09-05 20:52:20 +05:30
paginationMode: boolean;
2024-09-05 22:42:34 +05:30
startPaginationMode: () => void;
2024-07-24 21:34:28 +05:30
startGetText: () => void;
stopGetText: () => void;
2024-08-08 00:24:07 +05:30
startGetList: () => void;
stopGetList: () => void;
2024-07-24 21:34:28 +05:30
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);
2024-08-08 00:17:47 +05:30
const [getList, setGetList] = useState<boolean>(false);
2024-07-24 19:30:42 +05:30
const [getScreenshot, setGetScreenshot] = useState<boolean>(false);
2024-09-05 20:52:20 +05:30
const [paginationMode, setPaginationMode] = useState<boolean>(false);
2024-07-24 19:30:42 +05:30
2024-09-05 22:42:34 +05:30
const startPaginationMode = () => setPaginationMode(true);
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-08-08 00:24:07 +05:30
const startGetList = () => setGetList(true);
const stopGetList = () => setGetList(false);
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-09-05 22:42:34 +05:30
<ActionContext.Provider value={{ getText, getList, getScreenshot, paginationMode, startGetText, stopGetText, startGetList, stopGetList, startGetScreenshot, stopGetScreenshot, startPaginationMode }}>
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-08-08 00:26:32 +05:30
};