From e3571b2fcb4a78ea11466ff4bfb0405ae4028aea Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Wed, 26 May 2021 19:08:28 -0400 Subject: Finish logic for draggables, Caption screen logic is done --- src/components/common/MomentTags.tsx | 24 ++++++--- src/components/moments/TagFriendsFoooter.tsx | 74 +++++++++++++++------------- src/components/taggs/TaggDraggable.tsx | 2 +- 3 files changed, 60 insertions(+), 40 deletions(-) (limited to 'src/components') diff --git a/src/components/common/MomentTags.tsx b/src/components/common/MomentTags.tsx index 12a7d70a..d1bb03ff 100644 --- a/src/components/common/MomentTags.tsx +++ b/src/components/common/MomentTags.tsx @@ -6,7 +6,7 @@ import Draggable from './Draggable'; interface MomentTagsProps { editing: boolean; tags: MomentTagType[]; - // setTags: (tag: MomentTagType[]) => void; + setTags: (tag: MomentTagType[]) => void; imageRef: MutableRefObject; deleteFromList?: (user: ProfilePreviewType) => void; } @@ -14,7 +14,7 @@ interface MomentTagsProps { const MomentTags: React.FC = ({ editing, tags, - // setTags, + setTags, imageRef, deleteFromList, }) => { @@ -39,9 +39,21 @@ const MomentTags: React.FC = ({ px: number, // location of ref relative to entire screen py: number, ) => { - const x = Math.floor(((px - offset[0]) / imageDimensions[0]) * 100); - const y = Math.floor(((py - offset[1]) / imageDimensions[1]) * 100); - console.log(x, y); + const x = ((px - offset[0]) / imageDimensions[0]) * 100; + const y = ((py - offset[1]) / imageDimensions[1]) * 100; + setTags( + tags.map((tag) => + tag.user.id === userId + ? { + id: '', + x, + y, + z: maxZIndex - 1, // TODO: change this + user: tag.user, + } + : tag, + ), + ); }, ); } @@ -80,7 +92,7 @@ const MomentTags: React.FC = ({ <> {tags.map((tag, index) => ( = ({ setTaggedUsers(filteredSelection); }; - const TaggMoreButton = () => ( - - navigation.navigate('TagSelectionScreen', { - selectedUsers: taggedUsers, - }) - } - style={styles.tagMoreContainer}> - - {'Tagg More'} - + const goToSelectionScreen = () => { + navigation.navigate('TagSelectionScreen', { + selectedUsers: taggedUsers, + }); + }; + + const taggMoreButton = useMemo( + () => ( + + + {'Tagg More'} + + ), + [], ); const TaggedUser = (user: ProfilePreviewType) => ( @@ -66,32 +71,35 @@ const TagFriendsFooter: React.FC = ({ * If taggUsers is empty, title acts as a button * Else, gets disabled and TaggMore button appears */ - const TagFriendsTitle = () => ( - - navigation.navigate('TagSelectionScreen', { - selectedUsers: taggedUsers, - }) - }> - - Tag Friends - + const tagFriendsTitle = useMemo( + () => ( + + navigation.navigate('TagSelectionScreen', { + selectedUsers: taggedUsers, + }) + }> + + Tag Friends + + ), + [taggedUsers.length], ); return ( <> - + {tagFriendsTitle} {taggedUsers.map((user) => ( - + ))} - {taggedUsers.length !== 0 && } + {taggedUsers.length !== 0 && taggMoreButton} diff --git a/src/components/taggs/TaggDraggable.tsx b/src/components/taggs/TaggDraggable.tsx index 06825641..86915bb4 100644 --- a/src/components/taggs/TaggDraggable.tsx +++ b/src/components/taggs/TaggDraggable.tsx @@ -26,10 +26,10 @@ interface TaggDraggableProps extends ViewProps { const TaggDraggable: React.FC = ( props: TaggDraggableProps, ) => { + const {draggableRef, taggedUser, editingView, deleteFromList} = props; const navigation = useNavigation(); const dispatch = useDispatch(); const state = useSelector((rs: RootState) => rs); - const {draggableRef, taggedUser, editingView, deleteFromList} = props; let uriX = require('../../assets/images/draggableX.png'); let uriTip = require('../../assets/images/Tagg-Triangle.png'); -- cgit v1.2.3-70-g09d2