From 9895bd4c52854767657f4d70dba4018cba2b8751 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 21 May 2021 20:04:12 -0400 Subject: Refactor code --- src/components/common/MomentTags.tsx | 79 ++++++++++++++++++++++++++++++++++++ src/components/common/index.ts | 1 + 2 files changed, 80 insertions(+) create mode 100644 src/components/common/MomentTags.tsx (limited to 'src/components/common') diff --git a/src/components/common/MomentTags.tsx b/src/components/common/MomentTags.tsx new file mode 100644 index 00000000..f6f475bc --- /dev/null +++ b/src/components/common/MomentTags.tsx @@ -0,0 +1,79 @@ +import React, {MutableRefObject, useEffect, useState} from 'react'; +import {MomentTagType, ProfilePreviewType} from '../../types'; +import TaggDraggable from '../taggs/TaggDraggable'; +import Draggable from './Draggable'; + +interface MomentTagsProps { + editing: boolean; + tags: MomentTagType[]; + imageRef: MutableRefObject; + deleteFromList?: (user: ProfilePreviewType) => void; +} + +const MomentTags: React.FC = ({ + editing, + tags, + imageRef, + deleteFromList, +}) => { + const [offset, setOffset] = useState([0, 0]); + const [curStart, setCurStart] = useState([0, 0]); + const [imageDimensions, setImageDimensions] = useState([0, 0]); + + useEffect(() => { + imageRef.current.measure((fx, fy, width, height, px, py) => { + console.log(px, py); + console.log(width, height); + setOffset([px, py]); + setImageDimensions([width, height]); + }); + }, []); + + if (!tags) { + return null; + } + + return editing && deleteFromList ? ( + <> + {tags.map((tag) => ( + null}> + deleteFromList(tag.user)} + setStart={setCurStart} + /> + + ))} + + ) : ( + <> + {tags.map((tag) => ( + null}> + null} + setStart={setCurStart} + /> + + ))} + + ); +}; + +export default MomentTags; diff --git a/src/components/common/index.ts b/src/components/common/index.ts index 48abb8b8..692c9f8a 100644 --- a/src/components/common/index.ts +++ b/src/components/common/index.ts @@ -27,3 +27,4 @@ export {default as Avatar} from './Avatar'; export {default as TaggTypeahead} from './TaggTypeahead'; export {default as TaggUserRowCell} from './TaggUserRowCell'; export {default as LikeButton} from './LikeButton'; +export {default as MomentTags} from './MomentTags'; -- cgit v1.2.3-70-g09d2