refactor ChapterOptions (#126)

* Added a useLocalStorageReducer funtion
This is mostly  a refactor of ChapterOptions to simplify it with  a reducer function
Also moved a lot of function used in ChaperList to a utility file

* Added UseCallback where needed

* renamed utility folder to util to follow the convention throughout the app

* Refactor: Moved Resume FAB to seperate file

* Renamed  Types and Function for chapter filtering and sorting with the chapterOption prefix

* more renaming
This commit is contained in:
abhijeetChawla
2022-01-24 15:09:28 +05:30
committed by GitHub
parent f273b11a82
commit aaaadebfb3
7 changed files with 216 additions and 167 deletions

View File

@@ -14,7 +14,7 @@ import React, {
export interface IThreeStateCheckboxProps {
name: string
checked: boolean | undefined | null
onChange: (change: boolean | undefined | null) => void
onChange: (change: boolean | undefined | null, name: string) => void
}
enum CheckState {
@@ -61,10 +61,10 @@ const ThreeStateCheckbox = (props: IThreeStateCheckboxProps) => {
} = props;
const [localChecked, setLocalChecked] = useState(checkedToState(checked));
useEffect(() => setLocalChecked(checkedToState(checked)), [checked]);
const handleChange = () => {
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setLocalChecked(stateTransition(localChecked));
if (onChange) {
onChange(stateToChecked(stateTransition(localChecked)));
onChange(stateToChecked(stateTransition(localChecked)), e.currentTarget.name);
}
};
const CancelBox = createSvgIcon(