Files
parcer/src/context/browserActions.tsx

59 lines
2.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-09-06 23:56:53 +05:30
type PaginationType = 'scrollDown' | 'scrollUp' | 'clickNext' | 'clickLoadMore' | 'none' | '';
2024-09-06 23:08:01 +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;
paginationType: PaginationType;
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-09-05 22:42:57 +05:30
stopPaginationMode: () => void;
updatePaginationType: (type: PaginationType) => 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-09-06 23:10:06 +05:30
const [paginationType, setPaginationType] = useState<PaginationType>('');
2024-09-06 23:13:42 +05:30
2024-09-06 23:14:12 +05:30
const updatePaginationType = (type: PaginationType) => setPaginationType(type);
2024-09-06 23:13:42 +05:30
const startPaginationMode = () => setPaginationMode(true);
const stopPaginationMode = () => setPaginationMode(false);
2024-09-05 22:42:34 +05:30
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 (
<ActionContext.Provider value={{ getText, getList, getScreenshot, paginationMode, startGetText, stopGetText, startGetList, stopGetList, startGetScreenshot, stopGetScreenshot, startPaginationMode, stopPaginationMode, paginationType, updatePaginationType }}>
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
};