aboutsummaryrefslogtreecommitdiff
path: root/src/components/comments/AddComment.tsx
diff options
context:
space:
mode:
authorBrian Kim <brian@tagg.id>2021-06-15 12:28:32 +0900
committerBrian Kim <brian@tagg.id>2021-06-15 12:28:32 +0900
commitdb0678d647f774dcb1cd60513985d9b6fbd0e28b (patch)
tree00e62c1821d4973d214fdd47f8293749972c1925 /src/components/comments/AddComment.tsx
parenta249f2d027c9cd5d7f20602cf79ec2265f60a54c (diff)
parent78f32c1400eff46d4c768b78fbaf672826c74285 (diff)
Merge branch 'master' of https://github.com/TaggiD-Inc/Frontend
Diffstat (limited to 'src/components/comments/AddComment.tsx')
-rw-r--r--src/components/comments/AddComment.tsx96
1 files changed, 66 insertions, 30 deletions
diff --git a/src/components/comments/AddComment.tsx b/src/components/comments/AddComment.tsx
index b229d010..9667046c 100644
--- a/src/components/comments/AddComment.tsx
+++ b/src/components/comments/AddComment.tsx
@@ -24,10 +24,21 @@ import {MentionInputControlled} from './MentionInputControlled';
export interface AddCommentProps {
momentId: string;
placeholderText: string;
+ callback?: (message: string) => void;
+ onFocus?: () => void;
+ isKeyboardAvoiding?: boolean;
+ theme?: 'dark' | 'white';
}
-const AddComment: React.FC<AddCommentProps> = ({momentId, placeholderText}) => {
- const {setShouldUpdateAllComments, commentTapped} =
+const AddComment: React.FC<AddCommentProps> = ({
+ momentId,
+ placeholderText,
+ callback = (_) => null,
+ onFocus = () => null,
+ isKeyboardAvoiding = true,
+ theme = 'white',
+}) => {
+ const {setShouldUpdateAllComments = () => null, commentTapped} =
useContext(CommentContext);
const [inReplyToMention, setInReplyToMention] = useState('');
const [comment, setComment] = useState('');
@@ -50,13 +61,15 @@ const AddComment: React.FC<AddCommentProps> = ({momentId, placeholderText}) => {
if (trimmed === '') {
return;
}
+ const message = inReplyToMention + trimmed;
const postedComment = await postComment(
- inReplyToMention + trimmed,
+ message,
objectId,
isReplyingToComment || isReplyingToReply,
);
if (postedComment) {
+ callback(message);
setComment('');
setInReplyToMention('');
@@ -100,43 +113,63 @@ const AddComment: React.FC<AddCommentProps> = ({momentId, placeholderText}) => {
}
}, [isReplyingToComment, isReplyingToReply, commentTapped]);
- return (
- <KeyboardAvoidingView
- behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
- keyboardVerticalOffset={SCREEN_HEIGHT * 0.1}>
- <View
- style={[
- styles.container,
- keyboardVisible ? styles.whiteBackround : {},
- ]}>
- <View style={styles.textContainer}>
- <Avatar style={styles.avatar} uri={avatar} />
- <MentionInputControlled
- containerStyle={styles.text}
- placeholder={placeholderText}
- value={inReplyToMention + comment}
- onChange={(newText: string) => {
- // skipping the `inReplyToMention` text
- setComment(
- newText.substring(inReplyToMention.length, newText.length),
- );
- }}
- inputRef={ref}
- partTypes={mentionPartTypes('blue')}
- />
+ const mainContent = () => (
+ <View
+ style={[
+ theme === 'white' ? styles.containerWhite : styles.containerDark,
+ keyboardVisible && theme !== 'dark' ? styles.whiteBackround : {},
+ ]}>
+ <View style={styles.textContainer}>
+ <Avatar style={styles.avatar} uri={avatar} />
+ <MentionInputControlled
+ containerStyle={styles.text}
+ placeholderTextColor={theme === 'dark' ? '#828282' : undefined}
+ placeholder={placeholderText}
+ value={inReplyToMention + comment}
+ onFocus={onFocus}
+ onChange={(newText: string) => {
+ // skipping the `inReplyToMention` text
+ setComment(
+ newText.substring(inReplyToMention.length, newText.length),
+ );
+ }}
+ inputRef={ref}
+ partTypes={mentionPartTypes('blue')}
+ />
+ {(theme === 'white' || (theme === 'dark' && keyboardVisible)) && (
<View style={styles.submitButton}>
- <TouchableOpacity style={styles.submitButton} onPress={addComment}>
+ <TouchableOpacity
+ style={
+ comment === ''
+ ? [styles.submitButton, styles.greyButton]
+ : styles.submitButton
+ }
+ disabled={comment === ''}
+ onPress={addComment}>
<UpArrowIcon width={35} height={35} color={'white'} />
</TouchableOpacity>
</View>
- </View>
+ )}
</View>
+ </View>
+ );
+ return isKeyboardAvoiding ? (
+ <KeyboardAvoidingView
+ behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
+ keyboardVerticalOffset={SCREEN_HEIGHT * 0.1}>
+ {mainContent()}
</KeyboardAvoidingView>
+ ) : (
+ mainContent()
);
};
const styles = StyleSheet.create({
- container: {
+ containerDark: {
+ alignItems: 'center',
+ width: SCREEN_WIDTH,
+ },
+ containerWhite: {
backgroundColor: '#f7f7f7',
alignItems: 'center',
width: SCREEN_WIDTH,
@@ -176,6 +209,9 @@ const styles = StyleSheet.create({
marginVertical: '2%',
alignSelf: 'flex-end',
},
+ greyButton: {
+ backgroundColor: 'grey',
+ },
whiteBackround: {
backgroundColor: '#fff',
},