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