mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-07-29 00:25:28 +00:00

# Description of Changes <!-- File context for managing files between tools and views Optimisation for large files Updated Split to work with new file system and match Matts stepped design closer --> --- ## 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>
71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import { useState } from 'react';
|
|
import { SPLIT_MODES, SPLIT_TYPES, ENDPOINTS, type SplitMode, type SplitType } from '../../../constants/splitConstants';
|
|
import { SplitParameters } from '../../../components/tools/split/SplitSettings';
|
|
|
|
export interface SplitParametersHook {
|
|
mode: SplitMode | '';
|
|
parameters: SplitParameters;
|
|
setMode: (mode: SplitMode | '') => void;
|
|
updateParameter: (parameter: keyof SplitParameters, value: string | boolean) => void;
|
|
resetParameters: () => void;
|
|
validateParameters: () => boolean;
|
|
getEndpointName: () => string;
|
|
}
|
|
|
|
const initialParameters: SplitParameters = {
|
|
pages: '',
|
|
hDiv: '2',
|
|
vDiv: '2',
|
|
merge: false,
|
|
splitType: SPLIT_TYPES.SIZE,
|
|
splitValue: '',
|
|
bookmarkLevel: '1',
|
|
includeMetadata: false,
|
|
allowDuplicates: false,
|
|
};
|
|
|
|
export const useSplitParameters = (): SplitParametersHook => {
|
|
const [mode, setMode] = useState<SplitMode | ''>('');
|
|
const [parameters, setParameters] = useState<SplitParameters>(initialParameters);
|
|
|
|
const updateParameter = (parameter: keyof SplitParameters, value: string | boolean) => {
|
|
setParameters(prev => ({ ...prev, [parameter]: value }));
|
|
};
|
|
|
|
const resetParameters = () => {
|
|
setParameters(initialParameters);
|
|
setMode('');
|
|
};
|
|
|
|
const validateParameters = () => {
|
|
if (!mode) return false;
|
|
|
|
switch (mode) {
|
|
case SPLIT_MODES.BY_PAGES:
|
|
return parameters.pages.trim() !== "";
|
|
case SPLIT_MODES.BY_SECTIONS:
|
|
return parameters.hDiv !== "" && parameters.vDiv !== "";
|
|
case SPLIT_MODES.BY_SIZE_OR_COUNT:
|
|
return parameters.splitValue.trim() !== "";
|
|
case SPLIT_MODES.BY_CHAPTERS:
|
|
return parameters.bookmarkLevel !== "";
|
|
default:
|
|
return false;
|
|
}
|
|
};
|
|
|
|
const getEndpointName = () => {
|
|
if (!mode) return ENDPOINTS[SPLIT_MODES.BY_PAGES];
|
|
return ENDPOINTS[mode as SplitMode];
|
|
};
|
|
|
|
return {
|
|
mode,
|
|
parameters,
|
|
setMode,
|
|
updateParameter,
|
|
resetParameters,
|
|
validateParameters,
|
|
getEndpointName,
|
|
};
|
|
}; |