From 73dfa2b7baaa89921e21304d9e2138ff549fe895 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 8 Sep 2024 12:17:50 +0530 Subject: [PATCH] feat: context for list captue limit --- src/context/browserActions.tsx | 54 +++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/src/context/browserActions.tsx b/src/context/browserActions.tsx index f65e7399..08754071 100644 --- a/src/context/browserActions.tsx +++ b/src/context/browserActions.tsx @@ -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(undefined); @@ -26,24 +34,62 @@ export const ActionProvider = ({ children }: { children: ReactNode }) => { const [getList, setGetList] = useState(false); const [getScreenshot, setGetScreenshot] = useState(false); const [paginationMode, setPaginationMode] = useState(false); + const [limitMode, setLimitMode] = useState(false); const [paginationType, setPaginationType] = useState(''); + const [limitType, setLimitType] = useState(''); + const [customLimit, setCustomLimit] = useState(''); 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 ( - + {children} ); @@ -55,4 +101,4 @@ export const useActionContext = () => { throw new Error('useActionContext must be used within an ActionProvider'); } return context; -}; +}; \ No newline at end of file