feat: track browser actions state
This commit is contained in:
@@ -6,6 +6,7 @@ import { emptyWorkflow } from '../shared/constants';
|
|||||||
export type PaginationType = 'scrollDown' | 'scrollUp' | 'clickNext' | 'clickLoadMore' | 'none' | '';
|
export type PaginationType = 'scrollDown' | 'scrollUp' | 'clickNext' | 'clickLoadMore' | 'none' | '';
|
||||||
export type LimitType = '10' | '100' | 'custom' | '';
|
export type LimitType = '10' | '100' | 'custom' | '';
|
||||||
export type CaptureStage = 'initial' | 'pagination' | 'limit' | 'complete' | '';
|
export type CaptureStage = 'initial' | 'pagination' | 'limit' | 'complete' | '';
|
||||||
|
export type ActionType = 'text' | 'list' | 'screenshot';
|
||||||
|
|
||||||
interface ActionContextProps {
|
interface ActionContextProps {
|
||||||
getText: boolean;
|
getText: boolean;
|
||||||
@@ -20,17 +21,26 @@ interface ActionContextProps {
|
|||||||
captureStage: CaptureStage;
|
captureStage: CaptureStage;
|
||||||
showPaginationOptions: boolean;
|
showPaginationOptions: boolean;
|
||||||
showLimitOptions: boolean;
|
showLimitOptions: boolean;
|
||||||
|
actionsInWorkflow: {
|
||||||
|
text: boolean;
|
||||||
|
list: boolean;
|
||||||
|
screenshot: boolean;
|
||||||
|
};
|
||||||
|
activeAction: 'none' | 'text' | 'list' | 'screenshot';
|
||||||
|
setActiveAction: (action: 'none' | 'text' | 'list' | 'screenshot') => void;
|
||||||
setWorkflow: (workflow: WorkflowFile) => void;
|
setWorkflow: (workflow: WorkflowFile) => void;
|
||||||
setShowPaginationOptions: (show: boolean) => void;
|
setShowPaginationOptions: (show: boolean) => void;
|
||||||
setShowLimitOptions: (show: boolean) => void;
|
setShowLimitOptions: (show: boolean) => void;
|
||||||
setCaptureStage: (stage: CaptureStage) => void;
|
setCaptureStage: (stage: CaptureStage) => void;
|
||||||
startPaginationMode: () => void;
|
startAction: (action: 'text' | 'list' | 'screenshot') => void;
|
||||||
|
finishAction: (action: 'text' | 'list' | 'screenshot') => void;
|
||||||
startGetText: () => void;
|
startGetText: () => void;
|
||||||
stopGetText: () => void;
|
stopGetText: () => void;
|
||||||
startGetList: () => void;
|
startGetList: () => void;
|
||||||
stopGetList: () => void;
|
stopGetList: () => void;
|
||||||
startGetScreenshot: () => void;
|
startGetScreenshot: () => void;
|
||||||
stopGetScreenshot: () => void;
|
stopGetScreenshot: () => void;
|
||||||
|
startPaginationMode: () => void;
|
||||||
stopPaginationMode: () => void;
|
stopPaginationMode: () => void;
|
||||||
updatePaginationType: (type: PaginationType) => void;
|
updatePaginationType: (type: PaginationType) => void;
|
||||||
startLimitMode: () => void;
|
startLimitMode: () => void;
|
||||||
@@ -54,9 +64,54 @@ export const ActionProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
const [captureStage, setCaptureStage] = useState<CaptureStage>('initial');
|
const [captureStage, setCaptureStage] = useState<CaptureStage>('initial');
|
||||||
const [showPaginationOptions, setShowPaginationOptions] = useState(false);
|
const [showPaginationOptions, setShowPaginationOptions] = useState(false);
|
||||||
const [showLimitOptions, setShowLimitOptions] = useState(false);
|
const [showLimitOptions, setShowLimitOptions] = useState(false);
|
||||||
|
const [actionsInWorkflow, setActionsInWorkflow] = useState({
|
||||||
|
text: false,
|
||||||
|
list: false,
|
||||||
|
screenshot: false
|
||||||
|
});
|
||||||
|
const [activeAction, setActiveAction] = useState<'none' | 'text' | 'list' | 'screenshot'>('none');
|
||||||
|
|
||||||
const { socket } = useSocketStore();
|
const { socket } = useSocketStore();
|
||||||
|
|
||||||
|
const startAction = (action: 'text' | 'list' | 'screenshot') => {
|
||||||
|
if (activeAction !== 'none') return;
|
||||||
|
|
||||||
|
setActiveAction(action);
|
||||||
|
|
||||||
|
if (action === 'text') {
|
||||||
|
setGetText(true);
|
||||||
|
} else if (action === 'list') {
|
||||||
|
setGetList(true);
|
||||||
|
socket?.emit('setGetList', { getList: true });
|
||||||
|
setCaptureStage('initial');
|
||||||
|
} else if (action === 'screenshot') {
|
||||||
|
setGetScreenshot(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const finishAction = (action: 'text' | 'list' | 'screenshot') => {
|
||||||
|
if (activeAction !== action) return;
|
||||||
|
|
||||||
|
setActionsInWorkflow(prev => ({
|
||||||
|
...prev,
|
||||||
|
[action]: true
|
||||||
|
}));
|
||||||
|
|
||||||
|
setActiveAction('none');
|
||||||
|
|
||||||
|
if (action === 'text') {
|
||||||
|
setGetText(false);
|
||||||
|
} else if (action === 'list') {
|
||||||
|
setGetList(false);
|
||||||
|
setPaginationType('');
|
||||||
|
setLimitType('');
|
||||||
|
setCustomLimit('');
|
||||||
|
setCaptureStage('complete');
|
||||||
|
} else if (action === 'screenshot') {
|
||||||
|
setGetScreenshot(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const updatePaginationType = (type: PaginationType) => setPaginationType(type);
|
const updatePaginationType = (type: PaginationType) => setPaginationType(type);
|
||||||
const updateLimitType = (type: LimitType) => setLimitType(type);
|
const updateLimitType = (type: LimitType) => setLimitType(type);
|
||||||
const updateCustomLimit = (limit: string) => setCustomLimit(limit);
|
const updateCustomLimit = (limit: string) => setCustomLimit(limit);
|
||||||
@@ -77,14 +132,14 @@ export const ActionProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
|
|
||||||
const stopLimitMode = () => setLimitMode(false);
|
const stopLimitMode = () => setLimitMode(false);
|
||||||
|
|
||||||
const startGetText = () => setGetText(true);
|
const startGetText = () => startAction('text');
|
||||||
const stopGetText = () => setGetText(false);
|
|
||||||
|
|
||||||
const startGetList = () => {
|
const stopGetText = () => {
|
||||||
setGetList(true);
|
setGetText(false);
|
||||||
socket?.emit('setGetList', { getList: true });
|
setActiveAction('none');
|
||||||
setCaptureStage('initial');
|
};
|
||||||
}
|
|
||||||
|
const startGetList = () => startAction('list');
|
||||||
|
|
||||||
const stopGetList = () => {
|
const stopGetList = () => {
|
||||||
setGetList(false);
|
setGetList(false);
|
||||||
@@ -92,10 +147,15 @@ export const ActionProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
setLimitType('');
|
setLimitType('');
|
||||||
setCustomLimit('');
|
setCustomLimit('');
|
||||||
setCaptureStage('complete');
|
setCaptureStage('complete');
|
||||||
|
setActiveAction('none');
|
||||||
};
|
};
|
||||||
|
|
||||||
const startGetScreenshot = () => setGetScreenshot(true);
|
const startGetScreenshot = () => startAction('screenshot');
|
||||||
const stopGetScreenshot = () => setGetScreenshot(false);
|
|
||||||
|
const stopGetScreenshot = () => {
|
||||||
|
setGetScreenshot(false);
|
||||||
|
setActiveAction('none');
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ActionContext.Provider value={{
|
<ActionContext.Provider value={{
|
||||||
@@ -111,10 +171,15 @@ export const ActionProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
captureStage,
|
captureStage,
|
||||||
showPaginationOptions,
|
showPaginationOptions,
|
||||||
showLimitOptions,
|
showLimitOptions,
|
||||||
|
actionsInWorkflow,
|
||||||
|
activeAction,
|
||||||
|
setActiveAction,
|
||||||
setWorkflow,
|
setWorkflow,
|
||||||
setShowPaginationOptions,
|
setShowPaginationOptions,
|
||||||
setShowLimitOptions,
|
setShowLimitOptions,
|
||||||
setCaptureStage,
|
setCaptureStage,
|
||||||
|
startAction,
|
||||||
|
finishAction,
|
||||||
startGetText,
|
startGetText,
|
||||||
stopGetText,
|
stopGetText,
|
||||||
startGetList,
|
startGetList,
|
||||||
@@ -123,9 +188,9 @@ export const ActionProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
stopGetScreenshot,
|
stopGetScreenshot,
|
||||||
startPaginationMode,
|
startPaginationMode,
|
||||||
stopPaginationMode,
|
stopPaginationMode,
|
||||||
|
updatePaginationType,
|
||||||
startLimitMode,
|
startLimitMode,
|
||||||
stopLimitMode,
|
stopLimitMode,
|
||||||
updatePaginationType,
|
|
||||||
updateLimitType,
|
updateLimitType,
|
||||||
updateCustomLimit
|
updateCustomLimit
|
||||||
}}>
|
}}>
|
||||||
|
|||||||
Reference in New Issue
Block a user