From 0fd892ad288f2e1eaaa4fdf5e1fd6f15dbd45860 Mon Sep 17 00:00:00 2001 From: Ashm Walia <40498934+ashmgarv@users.noreply.github.com> Date: Fri, 4 Dec 2020 08:50:24 -0800 Subject: [TMA - 398 AND TMA-430] Replace Providers with Redux Store (#125) * First * WIP * Thunk * Some more comments * sc * recent searches and follounfollow * Edit profile dummy * Block / unblock and some cleanup * Replace auth provider * Sc * Delete AP after rebase * Discover users * Cleanup * More cleanup * Replace profile provider * Fixed build failure * Fixed a bug reported * Prevent app crash when backend server is down --- src/components/comments/AddComment.tsx | 13 ++++++++----- src/components/comments/CommentTile.tsx | 9 +++++++-- src/components/comments/CommentsCount.tsx | 9 +++++---- 3 files changed, 20 insertions(+), 11 deletions(-) (limited to 'src/components/comments') diff --git a/src/components/comments/AddComment.tsx b/src/components/comments/AddComment.tsx index ac1628da..f8c0b6bc 100644 --- a/src/components/comments/AddComment.tsx +++ b/src/components/comments/AddComment.tsx @@ -7,9 +7,11 @@ import { View, } from 'react-native'; import AsyncStorage from '@react-native-community/async-storage'; -import {AuthContext} from '../../routes'; import {TaggBigInput} from '../onboarding'; import {postMomentComment} from '../../services'; +import {logout} from '../../store/actions'; +import {useSelector, useDispatch} from 'react-redux'; +import {RootState} from '../../store/rootreducer'; /** * This file provides the add comment view for a user. @@ -27,11 +29,12 @@ const AddComment: React.FC = ({ moment_id, }) => { const [comment, setComment] = React.useState(''); + + const dispatch = useDispatch(); const { avatar, - user: {userId, username}, - logout, - } = React.useContext(AuthContext); + user: {userId}, + } = useSelector((state: RootState) => state.user); const handleCommentUpdate = (comment: string) => { setComment(comment); @@ -41,7 +44,7 @@ const AddComment: React.FC = ({ try { const token = await AsyncStorage.getItem('token'); if (!token) { - logout(); + dispatch(logout()); return; } const postedComment = await postMomentComment( diff --git a/src/components/comments/CommentTile.tsx b/src/components/comments/CommentTile.tsx index bee590f5..da78a4dc 100644 --- a/src/components/comments/CommentTile.tsx +++ b/src/components/comments/CommentTile.tsx @@ -1,7 +1,7 @@ import React from 'react'; import {Text, View} from 'react-native-animatable'; import {ProfilePreview} from '../profile'; -import {CommentType} from '../../types'; +import {CommentType, ScreenType} from '../../types'; import {StyleSheet} from 'react-native'; import {getTimePosted} from '../../utils'; import ClockIcon from '../../assets/icons/clock-icon-01.svg'; @@ -12,9 +12,13 @@ import ClockIcon from '../../assets/icons/clock-icon-01.svg'; interface CommentTileProps { comment_object: CommentType; + screenType: ScreenType; } -const CommentTile: React.FC = ({comment_object}) => { +const CommentTile: React.FC = ({ + comment_object, + screenType, +}) => { const timePosted = getTimePosted(comment_object.date_time); return ( @@ -26,6 +30,7 @@ const CommentTile: React.FC = ({comment_object}) => { last_name: '', }} previewType={'Comment'} + screenType={screenType} /> {comment_object.comment} diff --git a/src/components/comments/CommentsCount.tsx b/src/components/comments/CommentsCount.tsx index a9d5b6d6..d210c39a 100644 --- a/src/components/comments/CommentsCount.tsx +++ b/src/components/comments/CommentsCount.tsx @@ -3,6 +3,7 @@ import {Text} from 'react-native-animatable'; import {StyleSheet, TouchableOpacity} from 'react-native'; import CommentIcon from '../../assets/icons/moment-comment-icon.svg'; import {useNavigation} from '@react-navigation/native'; +import {ScreenType} from '../../types'; /** * Provides a view for the comment icon and the comment count. @@ -11,20 +12,20 @@ import {useNavigation} from '@react-navigation/native'; type CommentsCountProps = { comments_count: string; - isProfileView: boolean; moment_id: string; + screenType: ScreenType; }; const CommentsCount: React.FC = ({ comments_count, - isProfileView, moment_id, + screenType, }) => { const navigation = useNavigation(); const navigateToCommentsScreen = async () => { navigation.push('MomentCommentsScreen', { - isProfileView: isProfileView, - moment_id: moment_id, + moment_id, + screenType, }); }; return ( -- cgit v1.2.3-70-g09d2