From 278f3f96f8df8a5121115fd040f4bf72e332a2c8 Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Sat, 6 Feb 2021 19:45:25 +0100 Subject: [PATCH] fix render loop --- src/Components/MemberCard.js | 17 +++++++---------- src/Components/Memberlist.js | 27 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/Components/MemberCard.js b/src/Components/MemberCard.js index 279f3cda..071ce083 100644 --- a/src/Components/MemberCard.js +++ b/src/Components/MemberCard.js @@ -113,6 +113,8 @@ export default function MemberCard(props) { }, [member.description, member.color, member.birthday, member.display_name, member.pronouns, member.avatar_url, member.proxy_tags]); const submitEdit = data => { + props.edit(Object.assign(member, data)); + fetch(`${API_URL}m/${member.id}`,{ method: 'PATCH', body: JSON.stringify(data), @@ -132,6 +134,8 @@ export default function MemberCard(props) { } const submitPrivacy = data => { + props.edit(Object.assign(member, data)); + fetch(`${API_URL}m/${member.id}`,{ method: 'PATCH', body: JSON.stringify(data), @@ -181,6 +185,7 @@ export default function MemberCard(props) { const submitProxy = data => { const newdata = {proxy_tags: data.proxy_tags.filter(tag => !(tag.prefix === "" && tag.suffix === ""))} + props.edit(Object.assign(member, newdata)); fetch(`${API_URL}m/${member.id}`,{ method: 'PATCH', @@ -191,8 +196,8 @@ export default function MemberCard(props) { }}).then (res => res.json() ).then (data => { setMember(prevState => {return {...prevState, ...data}}); - setProxyTags(data.proxy_tags); - setErrorAlert(false) + setProxyTags(data.proxy_tags); + setErrorAlert(false); setProxyMode(false); } ).catch (error => { @@ -202,14 +207,6 @@ export default function MemberCard(props) { } const didMount = useRef(false); - - useEffect(() => { - if (didMount.current) { - props.edit(member); - } else { - didMount.current = true; - } - }, [props, member]); function copyLink() { var link = `https://spectralitree.github.io/pk-webs/profile/${sysID}/${member.id}` diff --git a/src/Components/Memberlist.js b/src/Components/Memberlist.js index 166b52f0..6968bca8 100644 --- a/src/Components/Memberlist.js +++ b/src/Components/Memberlist.js @@ -82,9 +82,9 @@ export default function Memberlist() { return {...member, desc: member.description} } return {...member, desc: "(no description)"} }) - - const currentMembers = Members1.filter(member => { - if (!value & privacyFilter === 'all') return true; + + const currentMembers = Members1.filter(member => { + if (!value) return true; if (privacyFilter === 'private') { if (member.visibility !== 'private') { @@ -138,7 +138,7 @@ export default function Memberlist() { const memberList = sortMembers.map((member) => {setMembers(members.map(member => member.id === memberEdit.id ? Object.assign(member, memberEdit) : member)); console.log(members)}} + edit={memberEdit => setMembers(members.map(member => member.id === memberEdit.id ? Object.assign(member, memberEdit) : member))} /> ); @@ -250,11 +250,11 @@ export default function Memberlist() { { currentPage === 1 ? : setCurrentPage(currentPage - 1)} />} { currentPage < 3 ? "" : setCurrentPage(1)} active={1 === active}>{1}} - { currentPage < 4 ? "" :} + { currentPage < 4 ? "" : currentPage < 5 ? setCurrentPage(2)} active={2 === active}>{2} : } { currentPage > 1 ? setCurrentPage(currentPage - 1)}>{currentPage - 1} : "" } setCurrentPage(currentPage)} active={currentPage === active}>{currentPage} { currentPage < pageAmount ? setCurrentPage(currentPage + 1)}>{currentPage + 1} : "" } - { currentPage > pageAmount - 3 ? "" : } + { currentPage > pageAmount - 3 ? "" : currentPage === pageAmount - 3 ? setCurrentPage(pageAmount - 1)} active={pageAmount - 1 === active}>{pageAmount - 1} : } { currentPage > pageAmount - 2 ? "" : setCurrentPage(pageAmount)} active={pageAmount === active}>{pageAmount}} { currentPage === pageAmount ? : setCurrentPage(currentPage + 1)} />} @@ -391,6 +391,19 @@ export default function Memberlist() { {memberList} + + + { currentPage === 1 ? : setCurrentPage(currentPage - 1)} />} + { currentPage < 3 ? "" : setCurrentPage(1)} active={1 === active}>{1}} + { currentPage < 4 ? "" : currentPage < 5 ? setCurrentPage(2)} active={2 === active}>{2} : } + { currentPage > 1 ? setCurrentPage(currentPage - 1)}>{currentPage - 1} : "" } + setCurrentPage(currentPage)} active={currentPage === active}>{currentPage} + { currentPage < pageAmount ? setCurrentPage(currentPage + 1)}>{currentPage + 1} : "" } + { currentPage > pageAmount - 3 ? "" : currentPage === pageAmount - 3 ? setCurrentPage(pageAmount - 1)} active={pageAmount - 1 === active}>{pageAmount - 1} : } + { currentPage > pageAmount - 2 ? "" : setCurrentPage(pageAmount)} active={pageAmount === active}>{pageAmount}} + { currentPage === pageAmount ? : setCurrentPage(currentPage + 1)} />} + + } @@ -398,7 +411,7 @@ export default function Memberlist() { { isLoading ? : {setMembers(members.map(member => member.id === memberEdit.id ? Object.assign(member, memberEdit) : member)); console.log(members)}}/>} + edit={memberEdit => setMembers(members.map(member => member.id === memberEdit.id ? Object.assign(member, memberEdit) : member))}/>} )