feat: context for list captue limit

This commit is contained in:
karishmas6
2024-09-08 12:17:50 +05:30
parent 0d057c43ff
commit 73dfa2b7ba

View File

@@ -1,13 +1,17 @@
import React, { createContext, useContext, useState, ReactNode } from 'react';
export type PaginationType = 'scrollDown' | 'scrollUp' | 'clickNext' | 'clickLoadMore' | 'none' | '';
export type LimitType = '10' | '100' | 'custom' | '';
interface ActionContextProps {
getText: boolean;
getList: boolean;
getScreenshot: boolean;
paginationMode: boolean;
limitMode: boolean;
paginationType: PaginationType;
limitType: LimitType;
customLimit: string;
startPaginationMode: () => void;
startGetText: () => void;
stopGetText: () => void;
@@ -17,6 +21,10 @@ interface ActionContextProps {
stopGetScreenshot: () => void;
stopPaginationMode: () => void;
updatePaginationType: (type: PaginationType) => void;
startLimitMode: () => void;
stopLimitMode: () => void;
updateLimitType: (type: LimitType) => void;
updateCustomLimit: (limit: string) => void;
}
const ActionContext = createContext<ActionContextProps | undefined>(undefined);
@@ -26,24 +34,62 @@ export const ActionProvider = ({ children }: { children: ReactNode }) => {
const [getList, setGetList] = useState<boolean>(false);
const [getScreenshot, setGetScreenshot] = useState<boolean>(false);
const [paginationMode, setPaginationMode] = useState<boolean>(false);
const [limitMode, setLimitMode] = useState<boolean>(false);
const [paginationType, setPaginationType] = useState<PaginationType>('');
const [limitType, setLimitType] = useState<LimitType>('');
const [customLimit, setCustomLimit] = useState<string>('');
const updatePaginationType = (type: PaginationType) => setPaginationType(type);
const updateLimitType = (type: LimitType) => setLimitType(type);
const updateCustomLimit = (limit: string) => setCustomLimit(limit);
const startPaginationMode = () => setPaginationMode(true);
const stopPaginationMode = () => setPaginationMode(false);
const stopPaginationMode = () => {
setPaginationMode(false);
setLimitMode(true);
};
const startLimitMode = () => setLimitMode(true);
const stopLimitMode = () => setLimitMode(false);
const startGetText = () => setGetText(true);
const stopGetText = () => setGetText(false);
const startGetList = () => setGetList(true);
const stopGetList = () => setGetList(false);
const stopGetList = () => {
setGetList(false);
setPaginationType('');
setLimitType('');
setCustomLimit('');
};
const startGetScreenshot = () => setGetScreenshot(true);
const stopGetScreenshot = () => setGetScreenshot(false);
return (
<ActionContext.Provider value={{ getText, getList, getScreenshot, paginationMode, startGetText, stopGetText, startGetList, stopGetList, startGetScreenshot, stopGetScreenshot, startPaginationMode, stopPaginationMode, paginationType, updatePaginationType }}>
<ActionContext.Provider value={{
getText,
getList,
getScreenshot,
paginationMode,
limitMode,
paginationType,
limitType,
customLimit,
startGetText,
stopGetText,
startGetList,
stopGetList,
startGetScreenshot,
stopGetScreenshot,
startPaginationMode,
stopPaginationMode,
startLimitMode,
stopLimitMode,
updatePaginationType,
updateLimitType,
updateCustomLimit
}}>
{children}
</ActionContext.Provider>
);
@@ -55,4 +101,4 @@ export const useActionContext = () => {
throw new Error('useActionContext must be used within an ActionProvider');
}
return context;
};
};