aboutsummaryrefslogtreecommitdiff
path: root/src/screens
diff options
context:
space:
mode:
Diffstat (limited to 'src/screens')
-rw-r--r--src/screens/profile/MomentCommentsScreen.tsx91
1 files changed, 55 insertions, 36 deletions
diff --git a/src/screens/profile/MomentCommentsScreen.tsx b/src/screens/profile/MomentCommentsScreen.tsx
index 73266a39..1a913e58 100644
--- a/src/screens/profile/MomentCommentsScreen.tsx
+++ b/src/screens/profile/MomentCommentsScreen.tsx
@@ -7,7 +7,7 @@ import {AddComment} from '../../components/';
import CommentsContainer from '../../components/comments/CommentsContainer';
import {ADD_COMMENT_TEXT} from '../../constants/strings';
import {headerBarOptions, MainStackParams} from '../../routes/main';
-import {CommentType} from '../../types';
+import {CommentThreadType, CommentType} from '../../types';
import {HeaderHeight, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils';
/**
@@ -25,18 +25,35 @@ interface MomentCommentsScreenProps {
route: MomentCommentsScreenRouteProps;
}
+type MomentCommentContextType = {
+ commentTapped: CommentType | CommentThreadType | undefined;
+ setCommentTapped: (
+ comment: CommentType | CommentThreadType | undefined,
+ ) => void;
+ shouldUpdateAllComments: boolean;
+ setShouldUpdateAllComments: (available: boolean) => void;
+ commentsLength: number;
+ setCommentsLength: (length: number) => void;
+};
+
+export const CommentContext = React.createContext(
+ {} as MomentCommentContextType,
+);
+
const MomentCommentsScreen: React.FC<MomentCommentsScreenProps> = ({route}) => {
const navigation = useNavigation();
const {moment_id, screenType, comment_id} = route.params;
//Receives comment length from child CommentsContainer
const [commentsLength, setCommentsLength] = useState<number>(0);
- const [newCommentsAvailable, setNewCommentsAvailable] = React.useState(true);
+ const [shouldUpdateAllComments, setShouldUpdateAllComments] = React.useState(
+ true,
+ );
//Keeps track of the current comments object in focus so that the application knows which comment to post a reply to
- const [commentObjectInFocus, setCommentObjectInFocus] = useState<
- CommentType | undefined
- >(undefined);
+ const [commentTapped, setCommentTapped] = useState<
+ CommentType | CommentThreadType | undefined
+ >();
useEffect(() => {
navigation.setOptions({
@@ -45,37 +62,39 @@ const MomentCommentsScreen: React.FC<MomentCommentsScreenProps> = ({route}) => {
}, [commentsLength, navigation]);
return (
- <View style={styles.background}>
- <SafeAreaView>
- <View style={styles.body}>
- <CommentsContainer
- objectId={moment_id}
- commentId={comment_id}
- screenType={screenType}
- setCommentsLength={setCommentsLength}
- newCommentsAvailable={newCommentsAvailable}
- setNewCommentsAvailable={setNewCommentsAvailable}
- setCommentObjectInFocus={setCommentObjectInFocus}
- commentObjectInFocus={commentObjectInFocus}
- typeOfComment={'Comment'}
- />
- <AddComment
- placeholderText={
- commentObjectInFocus
- ? ADD_COMMENT_TEXT(commentObjectInFocus.commenter.username)
- : ADD_COMMENT_TEXT()
- }
- setNewCommentsAvailable={setNewCommentsAvailable}
- commentInReplyTo={
- commentObjectInFocus ? commentObjectInFocus : undefined
- }
- momentId={commentObjectInFocus ? undefined : moment_id}
- isReplying={commentObjectInFocus ? true : false}
- />
- </View>
- </SafeAreaView>
- <TabsGradient />
- </View>
+ <CommentContext.Provider
+ value={{
+ commentTapped,
+ setCommentTapped,
+ shouldUpdateAllComments,
+ setShouldUpdateAllComments,
+ commentsLength,
+ setCommentsLength,
+ }}>
+ <View style={styles.background}>
+ <SafeAreaView>
+ <View style={styles.body}>
+ <CommentsContainer
+ objectId={moment_id}
+ commentId={comment_id}
+ screenType={screenType}
+ shouldUpdate={shouldUpdateAllComments}
+ setShouldUpdate={setShouldUpdateAllComments}
+ isThread={false}
+ />
+ <AddComment
+ placeholderText={
+ !commentTapped
+ ? ADD_COMMENT_TEXT()
+ : ADD_COMMENT_TEXT(commentTapped.commenter.username)
+ }
+ momentId={moment_id}
+ />
+ </View>
+ </SafeAreaView>
+ <TabsGradient />
+ </View>
+ </CommentContext.Provider>
);
};