import React, {useEffect, useState, useContext} from 'react'; import {StyleSheet} from 'react-native'; import Animated from 'react-native-reanimated'; import {useDispatch, useSelector} from 'react-redux'; import { INTEGRATED_SOCIAL_LIST, PROFILE_CUTOUT_BOTTOM_Y, SOCIAL_LIST, } from '../../constants'; import {getLinkedSocials} from '../../services'; import {StatusBarHeight} from '../../utils'; import Tagg from './Tagg'; import {RootState} from '../../store/rootReducer'; import {ScreenType} from '../../types'; import {loadIndividualSocial} from '../../store/actions'; const {View, ScrollView, interpolate, Extrapolate} = Animated; interface TaggsBarProps { y: Animated.Value; profileBodyHeight: number; userXId: string; screenType: ScreenType; } const TaggsBar: React.FC = ({ y, profileBodyHeight, userXId, screenType, }) => { let [taggs, setTaggs] = useState([]); let [taggsNeedUpdate, setTaggsNeedUpdate] = useState(true); const {user} = userXId ? useSelector((state: RootState) => state.userX[screenType][userXId]) : useSelector((state: RootState) => state.user); const dispatch = useDispatch(); /** * Updates the individual social that needs update * @param socialType Type of the social that needs update */ const handleSocialUpdate = (socialType: string) => { dispatch(loadIndividualSocial(user.userId, socialType)); }; /** * This useEffect should be called evey time the user being viewed is changed OR * And update is triggered manually */ 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( , ); i++; } for (let social of unlinkedSocials) { new_taggs.push( , ); i++; } setTaggs(new_taggs); setTaggsNeedUpdate(false); }); }; loadData(); }, [taggsNeedUpdate, user]); const shadowOpacity: Animated.Node = interpolate(y, { inputRange: [ PROFILE_CUTOUT_BOTTOM_Y + profileBodyHeight, PROFILE_CUTOUT_BOTTOM_Y + profileBodyHeight + 20, ], outputRange: [0, 0.2], extrapolate: Extrapolate.CLAMP, }); const paddingTop: Animated.Node = interpolate(y, { inputRange: [ 0, PROFILE_CUTOUT_BOTTOM_Y + profileBodyHeight - 30, PROFILE_CUTOUT_BOTTOM_Y + profileBodyHeight, ], outputRange: [20, 20, StatusBarHeight], extrapolate: Extrapolate.CLAMP, }); const paddingBottom: Animated.Node = interpolate(y, { inputRange: [ 0, PROFILE_CUTOUT_BOTTOM_Y + profileBodyHeight - 30, PROFILE_CUTOUT_BOTTOM_Y + profileBodyHeight, ], outputRange: [30, 30, 15], extrapolate: Extrapolate.CLAMP, }); return ( {taggs} ); }; const styles = StyleSheet.create({ container: { backgroundColor: 'white', shadowColor: '#000', shadowRadius: 10, shadowOffset: {width: 0, height: 2}, zIndex: 1, }, contentContainer: { alignItems: 'center', paddingHorizontal: 10, }, }); export default TaggsBar;