diff options
-rw-r--r-- | src/components/moments/MomentPost.tsx | 18 | ||||
-rw-r--r-- | src/components/profile/MomentMoreInfoDrawer.tsx | 34 |
2 files changed, 31 insertions, 21 deletions
diff --git a/src/components/moments/MomentPost.tsx b/src/components/moments/MomentPost.tsx index 1ab7c1fa..e2875b9a 100644 --- a/src/components/moments/MomentPost.tsx +++ b/src/components/moments/MomentPost.tsx @@ -46,11 +46,17 @@ const MomentPost: React.FC<MomentPostProps> = ({item, userXId, screenType}) => { * Check if loggedInUser has been tagged in the picture and set the id */ useEffect(() => { - tags.forEach((tag) => { - if (tag.user.id === loggedInUserId) { - setMomentTagId(tag.id); + const getMomentTagId = () => { + const ownTag: MomentTagType[] = tags.filter( + (tag) => tag.user.id === loggedInUserId, + ); + if (ownTag?.length > 0) { + setMomentTagId(ownTag[0].id); + } else { + setMomentTagId(''); } - }); + }; + getMomentTagId(); }, [tags]); /* @@ -64,6 +70,10 @@ const MomentPost: React.FC<MomentPostProps> = ({item, userXId, screenType}) => { } }; + useEffect(() => { + console.log('Tags have been altered'); + }, [tags]); + return ( <View style={styles.postContainer}> <MomentPostHeader diff --git a/src/components/profile/MomentMoreInfoDrawer.tsx b/src/components/profile/MomentMoreInfoDrawer.tsx index 3f8707e8..1265497e 100644 --- a/src/components/profile/MomentMoreInfoDrawer.tsx +++ b/src/components/profile/MomentMoreInfoDrawer.tsx @@ -116,26 +116,26 @@ const MomentMoreInfoDrawer: React.FC<MomentMoreInfoDrawerProps> = (props) => { * Update bottom drawer options to contain/not contain 'remove tag' option */ useEffect(() => { - const setupBottomDrawer = async () => { + const setupBottomDrawer = () => { const present = drawerButtons.findIndex( (button) => button[0] === MomentDrawerOptions.RemoveTag, ); - if (momentTagId !== '') { - if (present === -1) { - const localDrawerButtons = drawerButtons; - localDrawerButtons.push([ - MomentDrawerOptions.RemoveTag, - handleRemoveTag, - ]); - setDrawerButtons(localDrawerButtons); - } - } else { - if (present !== -1) { - const filteredButtons = drawerButtons.filter( - (button) => button[0] !== MomentDrawerOptions.RemoveTag, - ); - setDrawerButtons(filteredButtons); - } + /* + * If user is not tagged but button is present, remove button from bottom drawer + * If user is tagged but button is not present, add button to bottom drawer + */ + if (momentTagId !== '' && present === -1) { + const localDrawerButtons = drawerButtons; + localDrawerButtons.push([ + MomentDrawerOptions.RemoveTag, + handleRemoveTag, + ]); + setDrawerButtons(localDrawerButtons); + } else if (momentTagId === '' && present !== -1) { + const filteredButtons = drawerButtons.filter( + (button) => button[0] !== MomentDrawerOptions.RemoveTag, + ); + setDrawerButtons(filteredButtons); } }; setupBottomDrawer(); |