homeflowjs 0.8.7 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,58 +1,75 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import {
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import { useDispatch, useSelector } from 'react-redux';
|
|
3
3
|
import { Checkbox } from 'pretty-checkbox-react';
|
|
4
4
|
|
|
5
5
|
import { setSearchField } from '../../actions/search.actions';
|
|
6
6
|
|
|
7
|
-
const PrettyCheckBox = ({ checked, value,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
7
|
+
const PrettyCheckBox = ({ checked, value, handleChange, children }) => (
|
|
8
|
+
<Checkbox
|
|
9
|
+
name="status"
|
|
10
|
+
checked={checked}
|
|
11
|
+
onChange={handleChange}
|
|
12
|
+
value={value}
|
|
13
|
+
>
|
|
14
|
+
{children}
|
|
15
|
+
</Checkbox>
|
|
16
|
+
);
|
|
18
17
|
|
|
19
|
-
const NormalCheckBox = ({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
const NormalCheckBox = ({
|
|
19
|
+
value,
|
|
20
|
+
uncheckedValue,
|
|
21
|
+
checked,
|
|
22
|
+
status,
|
|
23
|
+
handleChange,
|
|
24
|
+
...otherProps
|
|
25
|
+
}) => {
|
|
26
26
|
|
|
27
27
|
return (
|
|
28
28
|
<input
|
|
29
29
|
type="checkbox"
|
|
30
30
|
name="status"
|
|
31
|
-
value={
|
|
32
|
-
|
|
33
|
-
onChange={
|
|
31
|
+
value={value}
|
|
32
|
+
checked={checked}
|
|
33
|
+
onChange={handleChange}
|
|
34
34
|
{...otherProps}
|
|
35
35
|
/>
|
|
36
36
|
);
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
const StatusCheckbox = (props) => {
|
|
40
|
-
const { pretty } = props;
|
|
40
|
+
const { pretty, value, uncheckedValue } = props;
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
const dispatch = useDispatch();
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const defaultSearchStatus = useSelector((state) => state.app.themePreferences.defaultSearchStatus || 'all');
|
|
45
|
+
const currentSearchStatus = useSelector((state) => state.search.currentSearch.status);
|
|
46
|
+
|
|
47
|
+
const calculateChecked = () => {
|
|
48
|
+
// if no current status then checked if value matches default
|
|
49
|
+
if (currentSearchStatus && currentSearchStatus === value) return true;
|
|
50
|
+
|
|
51
|
+
if (currentSearchStatus) return false;
|
|
52
|
+
|
|
53
|
+
// when there is no status set
|
|
54
|
+
return value === defaultSearchStatus;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const [checked, setChecked] = useState(calculateChecked());
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
setChecked(calculateChecked());
|
|
61
|
+
}, [defaultSearchStatus, currentSearchStatus]);
|
|
62
|
+
|
|
63
|
+
const handleChange = (e) => {
|
|
64
|
+
const newValue = checked ? (uncheckedValue || '') : value;
|
|
65
|
+
|
|
66
|
+
dispatch(setSearchField({ status: newValue === defaultSearchStatus ? '' : newValue }));
|
|
67
|
+
setChecked(calculateChecked());
|
|
68
|
+
};
|
|
46
69
|
|
|
47
|
-
|
|
48
|
-
checked: state.search.currentSearch.status === ownProps.value,
|
|
49
|
-
});
|
|
70
|
+
if (pretty) return <PrettyCheckBox {...props} handleChange={handleChange} checked={checked} />;
|
|
50
71
|
|
|
51
|
-
|
|
52
|
-
setSearchField,
|
|
72
|
+
return <NormalCheckBox {...props} handleChange={handleChange} checked={checked} />;
|
|
53
73
|
};
|
|
54
74
|
|
|
55
|
-
export default
|
|
56
|
-
mapStateToProps,
|
|
57
|
-
mapDispatchToProps,
|
|
58
|
-
)(StatusCheckbox);
|
|
75
|
+
export default StatusCheckbox;
|