1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
import {useNavigation} from '@react-navigation/native';
import React, {Fragment, useState} from 'react';
import {Alert, Linking, StyleSheet, TouchableOpacity, View} from 'react-native';
import PurpleRingPlus from '../../assets/icons/purple_ring+.svg';
import PurpleRing from '../../assets/icons/purple_ring.svg';
import RingPlus from '../../assets/icons/ring+.svg';
import Ring from '../../assets/icons/ring.svg';
import {
INTEGRATED_SOCIAL_LIST,
TAGG_ICON_DIM,
TAGG_RING_DIM,
} from '../../constants';
import {
getNonIntegratedURL,
handlePressForAuthBrowser,
registerNonIntegratedSocialLink,
} from '../../services';
import {SocialIcon, SocialLinkModal} from '../common';
interface TaggProps {
social: string;
isProfileView: boolean;
isLinked: boolean;
isIntegrated: boolean;
setTaggsNeedUpdate: (_: boolean) => void;
setSocialDataNeedUpdate: (_: string[]) => void;
userId: string;
}
const Tagg: React.FC<TaggProps> = ({
social,
isProfileView,
isLinked,
isIntegrated,
setTaggsNeedUpdate,
setSocialDataNeedUpdate,
userId,
}) => {
const navigation = useNavigation();
const [modalVisible, setModalVisible] = useState(false);
const youMayPass = isLinked || isProfileView;
/*
case isProfileView:
case linked:
show normal ring, navigate to taggs view
case !linked:
don't show tagg
case !isProfileView:
case linked:
show normal ring, navigate to taggs view
case !linked:
show ring+, then...
case integrated_social:
show auth browser
case !integrated_social:
show modal
Tagg's "Tagg" will use the Ring instead of PurpleRing
*/
const modalOrAuthBrowserOrPass = async () => {
if (youMayPass) {
if (INTEGRATED_SOCIAL_LIST.indexOf(social) !== -1) {
navigation.push('SocialMediaTaggs', {
socialMediaType: social,
isProfileView: isProfileView,
});
} else {
getNonIntegratedURL(social, userId).then((socialURL) => {
if (socialURL) {
Linking.openURL(socialURL);
} else {
Alert.alert('We were unable to find this profile 😔');
}
});
}
} else {
if (isIntegrated) {
handlePressForAuthBrowser(social).then((success) => {
setTaggsNeedUpdate(success);
setSocialDataNeedUpdate(success ? [social] : []);
});
} else {
setModalVisible(true);
}
}
};
const pickTheRightRingHere = () => {
if (youMayPass) {
if (social === 'Tagg') {
return <Ring width={TAGG_RING_DIM} height={TAGG_RING_DIM} />;
} else {
return <PurpleRing width={TAGG_RING_DIM} height={TAGG_RING_DIM} />;
}
} else {
if (social === 'Tagg') {
return <RingPlus width={TAGG_RING_DIM} height={TAGG_RING_DIM} />;
} else {
return <PurpleRingPlus width={TAGG_RING_DIM} height={TAGG_RING_DIM} />;
}
}
};
const linkNonIntegratedSocial = async (username: string) => {
if (await registerNonIntegratedSocialLink(social, username)) {
Alert.alert(`Successfully linked ${social} 🎉`);
setTaggsNeedUpdate(true);
} else {
// If we display too fast the alert will get dismissed with the modal
setTimeout(() => {
Alert.alert(`Something went wrong, we can't link with ${social} 😔`);
}, 500);
}
};
return (
<>
{isProfileView && !isLinked ? (
<Fragment />
) : (
<TouchableOpacity onPress={modalOrAuthBrowserOrPass}>
<SocialLinkModal
modalVisible={modalVisible}
setModalVisible={setModalVisible}
completionCallback={linkNonIntegratedSocial}
/>
<View style={styles.container}>
<SocialIcon style={styles.image} social={social} />
{pickTheRightRingHere()}
</View>
</TouchableOpacity>
)}
</>
);
};
const styles = StyleSheet.create({
container: {
justifyContent: 'center',
alignItems: 'center',
marginHorizontal: 15,
},
image: {
width: TAGG_ICON_DIM,
height: TAGG_ICON_DIM,
borderRadius: TAGG_ICON_DIM / 2,
position: 'absolute',
},
});
export default Tagg;
|