diff options
author | Ashm Walia <40498934+ashmgarv@users.noreply.github.com> | 2020-12-30 11:36:44 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-30 14:36:44 -0500 |
commit | 38661e00281363b0f4ad32f0b29d739e1ca09164 (patch) | |
tree | 316cd837b6cc6ae24783f1d93d6c9ee7fb898f68 /src/components/profile/FriendsCount.tsx | |
parent | bd2f89805d0bb1c2f1d08fe8d91099aa4f109d35 (diff) |
[TMA - 457]Change followers to friends (#149)
* One commit to replace followers with friends
* Move block unblock to drawer and some cosmetic changes
* Options to edit own profile when viewing
* Changes for University Class
* Small fix
* Made ProfileOnboarding a scroll view and other small changes
* Small fix
* Small fix thanks to ivan and tanmay
* Add ?
Diffstat (limited to 'src/components/profile/FriendsCount.tsx')
-rw-r--r-- | src/components/profile/FriendsCount.tsx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/components/profile/FriendsCount.tsx b/src/components/profile/FriendsCount.tsx new file mode 100644 index 00000000..91d54cab --- /dev/null +++ b/src/components/profile/FriendsCount.tsx @@ -0,0 +1,66 @@ +import React from 'react'; +import {View, Text, StyleSheet, ViewProps} from 'react-native'; +import {TouchableOpacity} from 'react-native-gesture-handler'; +import {useNavigation} from '@react-navigation/native'; +import {RootState} from '../../store/rootReducer'; +import {useSelector} from 'react-redux'; +import {ScreenType} from '../../types'; + +interface FriendsCountProps extends ViewProps { + userXId: string | undefined; + screenType: ScreenType; +} + +const FriendsCount: React.FC<FriendsCountProps> = ({ + style, + userXId, + screenType, +}) => { + const count = (userXId + ? useSelector((state: RootState) => state.userX[screenType][userXId]) + : useSelector((state: RootState) => state.friends) + )?.friends.length; + + const displayedCount: string = + count < 5e3 + ? `${count}` + : count < 1e5 + ? `${(count / 1e3).toFixed(1)}k` + : count < 1e6 + ? `${(count / 1e3).toFixed(0)}k` + : `${count / 1e6}m`; + + const navigation = useNavigation(); + + return ( + <TouchableOpacity + style={{right: '20%'}} + onPress={() => + navigation.push('FriendsListScreen', { + userXId, + screenType, + }) + }> + <View style={[styles.container, style]}> + <Text style={styles.count}>{displayedCount}</Text> + <Text style={styles.label}>Friends</Text> + </View> + </TouchableOpacity> + ); +}; + +const styles = StyleSheet.create({ + container: { + alignItems: 'center', + }, + count: { + fontWeight: '700', + fontSize: 18, + }, + label: { + fontWeight: '500', + fontSize: 16, + }, +}); + +export default FriendsCount; |