@@ -3,23 +3,20 @@ import CheckboxList from "../../../ui/checkboxList";
3
3
import log from 'loglevel' ;
4
4
import { useDispatch , useSelector } from "react-redux" ;
5
5
import { ADD_SELECTED_CATEGORY } from "../../../../actions/types" ;
6
- import { NavBarHeader } from "../../../ui/headers" ;
7
- import { Box , Grid } from "@material-ui/core" ;
8
- import CollapsableSearch from "../../../ui/collapsableSearch" ;
9
- import Button from '@material-ui/core/Button' ;
10
- import Paper from '@material-ui/core/Paper' ;
11
- import CloseIcon from "@material-ui/icons/Close" ;
12
- import IconButton from "@material-ui/core/IconButton" ;
13
- import SortedCheckboxList from "../../../ui/sortedCheckboxList" ;
6
+ import CheckboxMoreButton from "./checkboxMoreButton" ;
7
+ import CheckboxSearchBar from "./checkboxSearchBar" ;
8
+ import { useSortList } from "./sortListHook" ;
14
9
15
10
export default function ApparelCheckBox ( ) {
16
11
const TITLE = "Apparel"
12
+ const propName = "apparels"
17
13
const dispatch = useDispatch ( )
18
14
const apparelList = useSelector ( state => state . filterAttributesReducer ?
19
15
state . filterAttributesReducer . apparels : null )
20
16
const selectedApparels = useSelector ( state => state . selectedFilterAttributesReducer . apparels )
21
17
const [ searchApparelList , setSearchApparelList ] = useState ( null )
22
- const [ moreButtonState , setMoreButtonState ] = useState ( { active : false , topPosition : 0 } )
18
+
19
+ useSortList ( apparelList , propName )
23
20
24
21
if ( ! apparelList ) {
25
22
log . debug ( `[ApparelCheckBox] apparelList is null` )
@@ -30,14 +27,8 @@ export default function ApparelCheckBox() {
30
27
return searchApparelList ? searchApparelList : apparelList
31
28
}
32
29
33
- const handleSearchBarChange = value => {
34
- log . info ( `[ApparelCheckBox] handleSearchClick value = ${ value } ` )
35
- let filterApparelList = apparelList . filter ( info => info . value . toUpperCase ( ) . search ( value . toUpperCase ( ) ) !== - 1 )
36
- setSearchApparelList ( filterApparelList )
37
- }
38
-
39
- const handleSearchBarCancel = ( ) => {
40
- setSearchApparelList ( null )
30
+ const handleSearchListChange = ( searchList ) => {
31
+ setSearchApparelList ( searchList )
41
32
}
42
33
43
34
const handleCheckBoxChange = ( id , value ) => {
@@ -52,93 +43,29 @@ export default function ApparelCheckBox() {
52
43
} )
53
44
}
54
45
55
- const handleMoreButton = ( event ) => {
56
- log . info ( `[Apparel Checkbox] clientX = ${ event . clientX } , clientY = ${ event . clientY } , moreButtonState = ${ JSON . stringify ( moreButtonState ) } ` )
57
- setMoreButtonState ( { active : true , topPosition : parseInt ( event . clientY ) } )
58
- log . info ( `[Apparel Checkbox] moreButtonState = ${ JSON . stringify ( moreButtonState ) } ` )
59
- }
60
-
61
- const handleMoreListCloseButton = ( ) => {
62
- setMoreButtonState ( { active : false , topPosition : 0 } )
63
- }
64
-
65
- const renderMoreButtonList = ( ) => {
66
- return (
67
- < Paper elevation = { 3 } variant = "outlined" square
68
- style = { { backgroundColor : "inherit" , width : "100%" , height : "70vh" } } >
69
- < Grid item container direction = "row" sm = { 8 } style = { {
70
- height : '70vh' , zIndex : 1300 , overflow : "auto" ,
71
- position : "fixed" , top : 180 , backgroundColor : "rgb(230, 230, 230)" ,
72
- } } >
73
- < SortedCheckboxList attrList = { getActiveApparelList ( ) }
74
- fontSize = "0.9rem"
75
- title = { TITLE }
76
- selectedAttrList = { selectedApparels }
77
- onChangeHandler = { handleCheckBoxChange } />
78
- < Grid item sm = { 1 } container justify = "flex-end" style = { { height : "5%" , paddingRight : "0.5rem" } } >
79
- < IconButton size = "medium"
80
- color = "primary"
81
- onClick = { handleMoreListCloseButton }
82
- >
83
- < CloseIcon />
84
- </ IconButton >
85
- </ Grid >
86
- </ Grid >
87
- </ Paper >
88
- )
89
- }
90
-
91
- const renderCheckboxList = ( ) => {
92
- return (
93
- < >
94
- < Box display = "flex" alignItems = "center" pt = { 2 } >
95
- < Box width = "50%" >
96
- < NavBarHeader title = { TITLE } />
97
- </ Box >
98
- < Box width = "50%" >
99
- < CollapsableSearch
100
- handleOnSearchChange = { handleSearchBarChange }
101
- handleCancelButton = { handleSearchBarCancel }
102
- placeholder = "Search for Apparels"
103
- />
104
- </ Box >
105
- </ Box >
106
- < CheckboxList attrList = { getActiveApparelList ( ) }
107
- fontSize = "0.9rem"
108
- title = { TITLE }
109
- maxItems = { 6 }
110
- selectedAttrList = { selectedApparels }
111
- onChangeHandler = { handleCheckBoxChange } />
112
- { renderMoreButton ( ) }
113
- { moreButtonState . active ? renderMoreButtonList ( ) : null }
114
- </ >
115
- )
116
- }
117
-
118
- const renderMoreButton = ( ) => {
119
- if ( getActiveApparelList ( ) . length > 6 ) {
120
- return (
121
- < Box pl = { 1.5 } pb = { 1 } >
122
- < Button color = "secondary" onClick = { handleMoreButton } >
123
- { `+ ${ getActiveApparelList ( ) . length - 6 } more` }
124
- </ Button >
125
- </ Box >
126
- )
127
- }
128
- return null
129
- }
130
-
131
-
132
46
log . debug ( `[ApparelCheckBox] selectedApparels = ${ JSON . stringify ( selectedApparels ) } ` )
133
47
134
48
log . info ( `[ApparelCheckBox] Rendering ApparelCheckBox Component` )
135
49
136
50
return (
137
51
< >
138
- { /*{moreButtonState ? <ModalSection*/ }
139
- { /* handleCloseButton={handleMoreListCloseButton}*/ }
140
- { /* content={renderMoreButtonList}/> : renderCheckboxList()}*/ }
141
- { renderCheckboxList ( ) }
52
+ < CheckboxSearchBar title = { TITLE }
53
+ placeholderText = "Search for Apparels"
54
+ checkboxList = { apparelList }
55
+ searchListHandler = { handleSearchListChange }
56
+ />
57
+ < CheckboxList attrList = { getActiveApparelList ( ) }
58
+ fontSize = "0.9rem"
59
+ title = { TITLE }
60
+ maxItems = { 6 }
61
+ selectedAttrList = { selectedApparels }
62
+ onChangeHandler = { handleCheckBoxChange } />
63
+ < CheckboxMoreButton title = { TITLE }
64
+ checkboxList = { apparelList }
65
+ propName = { propName }
66
+ selectedCheckboxList = { selectedApparels }
67
+ checkboxChangeHandler = { handleCheckBoxChange } />
68
+
142
69
</ >
143
70
) ;
144
71
}
0 commit comments