diff --git a/src/Components/ProfileList.js b/src/Components/ProfileList.js index 873c41f7..ab99fa36 100644 --- a/src/Components/ProfileList.js +++ b/src/Components/ProfileList.js @@ -20,9 +20,6 @@ export default function Memberlist() { const [membersPerPage, setMembersPerPage] = useState(25); const [members, setMembers ] = useState([]); - const [memberData, setMemberData ] = useState([]); - const [filteredMembers, setFilteredMembers ] = useState([]); - const [sortedMembers, setSortedMembers ] = useState([]); const [searchBy, setSearchBy] = useState('name') const [sortBy, setSortBy] = useState('name') @@ -52,7 +49,9 @@ export default function Memberlist() { fetchMembers(); }, [fetchMembers]) - useEffect(() => { + const indexOfLastMember = currentPage * membersPerPage; + const indexOfFirstMember = indexOfLastMember - membersPerPage; + let Members = members.map(member => { if (member.display_name) { return {...member, displayName: member.display_name} @@ -63,18 +62,8 @@ export default function Memberlist() { return {...member, desc: member.description} } return {...member, desc: "(no description)"} }) - setMemberData(Members1); - }, [members]) - - const indexOfLastMember = currentPage * membersPerPage; - const indexOfFirstMember = indexOfLastMember - membersPerPage; - - useEffect(() => { - searchMembers(); - }, [value, memberData, searchBy]) - - function searchMembers() { - const currentMembers = memberData.filter(member => { + + const currentMembers = Members1.filter(member => { if (!value) return true; if (searchBy === 'name') { @@ -100,30 +89,23 @@ export default function Memberlist() { } return false; }) - setFilteredMembers(currentMembers); - } - - useEffect (() => { - if (sortBy === 'name') { - const sortMembers = filteredMembers.sort((a, b) => a.name.localeCompare(b.name)).slice(indexOfFirstMember, indexOfLastMember); - setSortedMembers(sortMembers); - } else if (sortBy === 'display name') { - const sortMembers = filteredMembers.sort((a, b) => a.displayName.localeCompare(b.displayName)).slice(indexOfFirstMember, indexOfLastMember); - setSortedMembers(sortMembers); - } else if (sortBy === 'ID') { - const sortMembers = filteredMembers.sort((a, b) => a.id.localeCompare(b.id)).slice(indexOfFirstMember, indexOfLastMember); - setSortedMembers(sortMembers); - } - }, [sortBy, filteredMembers, indexOfFirstMember, indexOfLastMember]) - const active = currentPage; - const pageAmount = Math.ceil(filteredMembers.length / membersPerPage); - - const memberList = sortedMembers.map((member) => - + const pageAmount = Math.ceil(currentMembers.length / membersPerPage); + + var sortMembers = currentMembers; + if (sortBy === 'name') { + sortMembers = currentMembers.sort((a, b) => a.name.localeCompare(b.name)).slice(indexOfFirstMember, indexOfLastMember); + } else if (sortBy === 'display name') { + sortMembers = currentMembers.sort((a, b) => a.displayName.localeCompare(b.displayName)).slice(indexOfFirstMember, indexOfLastMember); + } else if (sortBy === 'ID') { + sortMembers = currentMembers.sort((a, b) => a.id.localeCompare(b.id)).slice(indexOfFirstMember, indexOfLastMember); + } + + const memberList = sortMembers.map((member) => + ); @@ -131,7 +113,7 @@ export default function Memberlist() { <> - + @@ -178,13 +160,13 @@ export default function Memberlist() { - - + + {setValue(e.target.value); setCurrentPage(1);}} placeholder={`Search by ${searchBy}`}/> - + fetchMembers()}>Refresh