Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 09df13c

Browse files
Merge pull request #547 from topcoder-platform/issues/timor/81
fixes issue#81
2 parents efb7829 + c8fcdbb commit 09df13c

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

client/src/components/GroupsSideMenu/filters.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ export default function GroupTabFilters({
2222
creatingGroup,
2323
onCreateNewGroup,
2424
}) {
25-
const handleGroupItemClicked = (group, item, index) => {
25+
const handleGroupItemClicked = (group, item) => {
2626
setSelectedGroup(group);
27-
setSelectedIndex(index);
27+
setSelectedItemId(item.id);
2828
if (onGroupSelected) {
2929
onGroupSelected(item);
3030
}
3131
};
3232

3333
const [selectedGroup, setSelectedGroup] = useState("");
34-
const [selectedIndex, setSelectedIndex] = useState(-1);
34+
const [selectedItemId, setSelectedItemId] = useState(-1);
3535
const [myGroupsData, setMyGroupsData] = useState(myGroups);
3636
const [groupsData, setGroupsData] = useState(groups);
3737
const [searchText, setSearchText] = useState("");
@@ -89,16 +89,16 @@ export default function GroupTabFilters({
8989
group.name.toLowerCase().includes(searchText.toLowerCase())
9090
)}
9191
onItemClicked={handleGroupItemClicked}
92-
selectedIndex={selectedGroup === "My Groups" ? selectedIndex : -1}
92+
selectedItemId={selectedGroup === "My Groups" ? selectedItemId : -1}
9393
/>
9494
<GroupsSection
9595
title={loadingGroups ? "Other Groups (Loading...)" : "Other Groups"}
9696
items={groupsData.filter((group) =>
9797
group.name.toLowerCase().includes(searchText.toLowerCase())
9898
)}
9999
onItemClicked={handleGroupItemClicked}
100-
selectedIndex={
101-
selectedGroup === "Other Groups" ? selectedIndex : -1
100+
selectedItemId={
101+
selectedGroup === "Other Groups" ? selectedItemId : -1
102102
}
103103
/>
104104
</div>
@@ -116,12 +116,7 @@ GroupTabFilters.propTypes = {
116116
onCreateNewGroup: PT.func,
117117
};
118118

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 }) {
125120
return (
126121
<>
127122
<div className={styles.sectionTitle}>{title}</div>
@@ -132,8 +127,8 @@ function GroupsSection({ title, items, onItemClicked, selectedIndex }) {
132127
key={`${title}${index}`}
133128
title={item.name}
134129
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}
137132
/>
138133
);
139134
})}

0 commit comments

Comments
 (0)