@@ -22,16 +22,16 @@ export default function GroupTabFilters({
22
22
creatingGroup,
23
23
onCreateNewGroup,
24
24
} ) {
25
- const handleGroupItemClicked = ( group , item , index ) => {
25
+ const handleGroupItemClicked = ( group , item ) => {
26
26
setSelectedGroup ( group ) ;
27
- setSelectedIndex ( index ) ;
27
+ setSelectedItemId ( item . id ) ;
28
28
if ( onGroupSelected ) {
29
29
onGroupSelected ( item ) ;
30
30
}
31
31
} ;
32
32
33
33
const [ selectedGroup , setSelectedGroup ] = useState ( "" ) ;
34
- const [ selectedIndex , setSelectedIndex ] = useState ( - 1 ) ;
34
+ const [ selectedItemId , setSelectedItemId ] = useState ( - 1 ) ;
35
35
const [ myGroupsData , setMyGroupsData ] = useState ( myGroups ) ;
36
36
const [ groupsData , setGroupsData ] = useState ( groups ) ;
37
37
const [ searchText , setSearchText ] = useState ( "" ) ;
@@ -89,16 +89,16 @@ export default function GroupTabFilters({
89
89
group . name . toLowerCase ( ) . includes ( searchText . toLowerCase ( ) )
90
90
) }
91
91
onItemClicked = { handleGroupItemClicked }
92
- selectedIndex = { selectedGroup === "My Groups" ? selectedIndex : - 1 }
92
+ selectedItemId = { selectedGroup === "My Groups" ? selectedItemId : - 1 }
93
93
/>
94
94
< GroupsSection
95
95
title = { loadingGroups ? "Other Groups (Loading...)" : "Other Groups" }
96
96
items = { groupsData . filter ( ( group ) =>
97
97
group . name . toLowerCase ( ) . includes ( searchText . toLowerCase ( ) )
98
98
) }
99
99
onItemClicked = { handleGroupItemClicked }
100
- selectedIndex = {
101
- selectedGroup === "Other Groups" ? selectedIndex : - 1
100
+ selectedItemId = {
101
+ selectedGroup === "Other Groups" ? selectedItemId : - 1
102
102
}
103
103
/>
104
104
</ div >
@@ -116,12 +116,7 @@ GroupTabFilters.propTypes = {
116
116
onCreateNewGroup : PT . func ,
117
117
} ;
118
118
119
- function GroupsSection ( { title, items, onItemClicked, selectedIndex } ) {
120
- const [ selected , setSelected ] = useState ( selectedIndex ) ;
121
- useEffect ( ( ) => {
122
- setSelected ( selectedIndex ) ;
123
- } , [ selectedIndex ] ) ;
124
-
119
+ function GroupsSection ( { title, items, onItemClicked, selectedItemId } ) {
125
120
return (
126
121
< >
127
122
< div className = { styles . sectionTitle } > { title } </ div >
@@ -132,8 +127,8 @@ function GroupsSection({ title, items, onItemClicked, selectedIndex }) {
132
127
key = { `${ title } ${ index } ` }
133
128
title = { item . name }
134
129
badge = { item . count + "" }
135
- action = { ( ) => onItemClicked && onItemClicked ( title , item , index ) }
136
- selected = { index === selected }
130
+ action = { ( ) => onItemClicked && onItemClicked ( title , item ) }
131
+ selected = { item . id === selectedItemId }
137
132
/>
138
133
) ;
139
134
} ) }
0 commit comments