# Description of Changes <!-- Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(issue_number) --> --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import { PageEditorFunctions } from '../../types/pageEditor';
|
|
import { type ToolPanelMode, DEFAULT_TOOL_PANEL_MODE } from '../../constants/toolPanel';
|
|
|
|
export interface ToolWorkflowState {
|
|
// UI State
|
|
sidebarsVisible: boolean;
|
|
leftPanelView: 'toolPicker' | 'toolContent' | 'hidden';
|
|
readerMode: boolean;
|
|
toolPanelMode: ToolPanelMode;
|
|
|
|
previewFile: File | null;
|
|
pageEditorFunctions: PageEditorFunctions | null;
|
|
|
|
// Search State
|
|
searchQuery: string;
|
|
}
|
|
|
|
// Actions
|
|
export type ToolWorkflowAction =
|
|
| { type: 'SET_SIDEBARS_VISIBLE'; payload: boolean }
|
|
| { type: 'SET_LEFT_PANEL_VIEW'; payload: 'toolPicker' | 'toolContent' | 'hidden' }
|
|
| { type: 'SET_READER_MODE'; payload: boolean }
|
|
| { type: 'SET_TOOL_PANEL_MODE'; payload: ToolPanelMode }
|
|
| { type: 'SET_PREVIEW_FILE'; payload: File | null }
|
|
| { type: 'SET_PAGE_EDITOR_FUNCTIONS'; payload: PageEditorFunctions | null }
|
|
| { type: 'SET_SEARCH_QUERY'; payload: string }
|
|
| { type: 'RESET_UI_STATE' };
|
|
|
|
|
|
export const baseState: Omit<ToolWorkflowState, 'toolPanelMode'> = {
|
|
sidebarsVisible: true,
|
|
leftPanelView: 'toolPicker',
|
|
readerMode: false,
|
|
previewFile: null,
|
|
pageEditorFunctions: null,
|
|
searchQuery: '',
|
|
};
|
|
|
|
export const createInitialState = (): ToolWorkflowState => ({
|
|
...baseState,
|
|
toolPanelMode: DEFAULT_TOOL_PANEL_MODE,
|
|
});
|
|
|
|
export function toolWorkflowReducer(state: ToolWorkflowState, action: ToolWorkflowAction): ToolWorkflowState {
|
|
switch (action.type) {
|
|
case 'SET_SIDEBARS_VISIBLE':
|
|
return { ...state, sidebarsVisible: action.payload };
|
|
case 'SET_LEFT_PANEL_VIEW':
|
|
return { ...state, leftPanelView: action.payload };
|
|
case 'SET_READER_MODE':
|
|
return { ...state, readerMode: action.payload };
|
|
case 'SET_TOOL_PANEL_MODE':
|
|
return { ...state, toolPanelMode: action.payload };
|
|
case 'SET_PREVIEW_FILE':
|
|
return { ...state, previewFile: action.payload };
|
|
case 'SET_PAGE_EDITOR_FUNCTIONS':
|
|
return { ...state, pageEditorFunctions: action.payload };
|
|
case 'SET_SEARCH_QUERY':
|
|
return { ...state, searchQuery: action.payload };
|
|
case 'RESET_UI_STATE':
|
|
return {
|
|
...baseState,
|
|
toolPanelMode: state.toolPanelMode,
|
|
searchQuery: state.searchQuery,
|
|
};
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
|