aboutsummaryrefslogtreecommitdiff
path: root/src/components/taggs/TaggsBar.tsx
diff options
context:
space:
mode:
authorGeorge Rusu <56009869+grusu6928@users.noreply.github.com>2020-10-25 15:21:38 -0700
committerGitHub <noreply@github.com>2020-10-25 18:21:38 -0400
commit9da19cdcb6c7596d60afde6d0d559f06a24a0627 (patch)
tree8f11b6e0a5fcdc2eb983d498fa7b016d4daf44ba /src/components/taggs/TaggsBar.tsx
parent44a25bfabd356f5eee5ec4f580452407a7e40246 (diff)
[TMA-237] Added modal for user registration and redirect (#61)
* move async-storage * removed lock files * added lock files to gitignore * added the wrong file to gitignore * added modal for user registration and redirect * api call to get list of linked socials for each user to display appropriate icon * fixed indentation and linting * refactored modal and browser sign-in * now dynamically adding linked and unlinked taggs, added a bunch of TODOs for tomorrow * added svg icons * done? finished taggs bar UI and all the navigations including modal * fixed some bugs and added more TODOs * fixed some bugs and refactored posts fetching logic * fixed taggs bar bug * done, it will update everything correctly * added comments * added tiktok Co-authored-by: hsalhab <husam_salhab@brown.edu> Co-authored-by: george <grus6928@gmail.com> Co-authored-by: Ivan Chen <ivan@thetaggid.com>
Diffstat (limited to 'src/components/taggs/TaggsBar.tsx')
-rw-r--r--src/components/taggs/TaggsBar.tsx101
1 files changed, 60 insertions, 41 deletions
diff --git a/src/components/taggs/TaggsBar.tsx b/src/components/taggs/TaggsBar.tsx
index 88f670b5..520cc266 100644
--- a/src/components/taggs/TaggsBar.tsx
+++ b/src/components/taggs/TaggsBar.tsx
@@ -1,10 +1,16 @@
// @refresh react
-import React from 'react';
+import React, {useEffect, useState} from 'react';
import {StyleSheet} from 'react-native';
import Animated from 'react-native-reanimated';
-import Tagg from './Tagg';
-import {PROFILE_CUTOUT_BOTTOM_Y} from '../../constants';
+import {
+ INTEGRATED_SOCIAL_LIST,
+ PROFILE_CUTOUT_BOTTOM_Y,
+ SOCIAL_LIST,
+} from '../../constants';
+import {AuthContext, ProfileContext} from '../../routes';
+import {getLinkedSocials} from '../../services';
import {StatusBarHeight} from '../../utils';
+import Tagg from './Tagg';
const {View, ScrollView, interpolate, Extrapolate} = Animated;
interface TaggsBarProps {
@@ -17,43 +23,59 @@ const TaggsBar: React.FC<TaggsBarProps> = ({
profileBodyHeight,
isProfileView,
}) => {
- const taggs: Array<JSX.Element> = [];
+ let [taggs, setTaggs] = useState<Object[]>([]);
+ let [taggsNeedUpdate, setTaggsNeedUpdate] = useState(true);
+ const context = isProfileView
+ ? React.useContext(ProfileContext)
+ : React.useContext(AuthContext);
+ const {user, socialsNeedUpdate} = context;
- taggs.push(
- <Tagg
- key={0}
- style={styles.tagg}
- social={'Instagram'}
- isProfileView={isProfileView}
- />,
- );
- taggs.push(
- <Tagg
- key={1}
- style={styles.tagg}
- social={'Facebook'}
- isProfileView={isProfileView}
- />,
- );
- taggs.push(
- <Tagg
- key={2}
- style={styles.tagg}
- social={'Twitter'}
- isProfileView={isProfileView}
- />,
- );
+ useEffect(() => {
+ const loadData = async () => {
+ getLinkedSocials(user.userId).then((linkedSocials) => {
+ const unlinkedSocials = SOCIAL_LIST.filter(
+ (s) => linkedSocials.indexOf(s) === -1,
+ );
+ let new_taggs = [];
+ let i = 0;
+ for (let social of linkedSocials) {
+ new_taggs.push(
+ <Tagg
+ key={i}
+ social={social}
+ isProfileView={isProfileView}
+ isLinked={true}
+ isIntegrated={INTEGRATED_SOCIAL_LIST.indexOf(social) !== -1}
+ setTaggsNeedUpdate={setTaggsNeedUpdate}
+ setSocialDataNeedUpdate={socialsNeedUpdate}
+ />,
+ );
+ i++;
+ }
+ for (let social of unlinkedSocials) {
+ new_taggs.push(
+ <Tagg
+ key={i}
+ social={social}
+ isProfileView={isProfileView}
+ isLinked={false}
+ isIntegrated={INTEGRATED_SOCIAL_LIST.indexOf(social) !== -1}
+ setTaggsNeedUpdate={setTaggsNeedUpdate}
+ setSocialDataNeedUpdate={socialsNeedUpdate}
+ />,
+ );
+ i++;
+ }
+ setTaggs(new_taggs);
+ setTaggsNeedUpdate(false);
+ });
+ };
+
+ if (taggsNeedUpdate) {
+ loadData();
+ }
+ }, [isProfileView, taggsNeedUpdate, user.userId]);
- for (let i = 3; i < 10; i++) {
- taggs.push(
- <Tagg
- key={i}
- style={styles.tagg}
- social={'Instagram'}
- isProfileView={isProfileView}
- />,
- );
- }
const shadowOpacity: Animated.Node<number> = interpolate(y, {
inputRange: [
PROFILE_CUTOUT_BOTTOM_Y + profileBodyHeight,
@@ -105,9 +127,6 @@ const styles = StyleSheet.create({
alignItems: 'center',
paddingHorizontal: 15,
},
- tagg: {
- marginHorizontal: 14,
- },
});
export default TaggsBar;