aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Chen <ivan@thetaggid.com>2020-10-27 19:31:39 -0400
committerGitHub <noreply@github.com>2020-10-27 19:31:39 -0400
commit795ba089207571ec13226f2d07c149c8697763ce (patch)
tree81d08094396cda3195287fa0c72c5cb4c91a1287
parente004fd362583a020b07f87536aac077269eaad27 (diff)
done (#81)
-rw-r--r--src/components/taggs/Tagg.tsx14
-rw-r--r--src/components/taggs/TaggsBar.tsx2
-rw-r--r--src/constants/constants.ts2
-rw-r--r--src/services/SocialLinkingService.ts35
4 files changed, 45 insertions, 8 deletions
diff --git a/src/components/taggs/Tagg.tsx b/src/components/taggs/Tagg.tsx
index 39cbee06..a9bc05a9 100644
--- a/src/components/taggs/Tagg.tsx
+++ b/src/components/taggs/Tagg.tsx
@@ -7,6 +7,7 @@ import RingPlus from '../../assets/icons/ring+.svg';
import Ring from '../../assets/icons/ring.svg';
import {INTEGRATED_SOCIAL_LIST, TAGG_ICON_DIM} from '../../constants';
import {
+ getNonIntegratedURL,
handlePressForAuthBrowser,
registerNonIntegratedSocialLink,
} from '../../services';
@@ -19,6 +20,7 @@ interface TaggProps {
isIntegrated: boolean;
setTaggsNeedUpdate: (_: boolean) => void;
setSocialDataNeedUpdate: (_: string[]) => void;
+ userId: string;
}
const Tagg: React.FC<TaggProps> = ({
@@ -28,6 +30,7 @@ const Tagg: React.FC<TaggProps> = ({
isIntegrated,
setTaggsNeedUpdate,
setSocialDataNeedUpdate,
+ userId,
}) => {
const navigation = useNavigation();
const [modalVisible, setModalVisible] = useState(false);
@@ -59,10 +62,13 @@ const Tagg: React.FC<TaggProps> = ({
isProfileView: isProfileView,
});
} else {
- // TODO: we don't know what the link is...?
- Linking.openURL(
- `http://google.com/search?q=take+me+to+${social}+profile+page`,
- );
+ getNonIntegratedURL(social, userId).then((socialURL) => {
+ if (socialURL) {
+ Linking.openURL(socialURL);
+ } else {
+ Alert.alert('We were unable to find this profile 😔');
+ }
+ });
}
} else {
if (isIntegrated) {
diff --git a/src/components/taggs/TaggsBar.tsx b/src/components/taggs/TaggsBar.tsx
index 520cc266..62f5f90e 100644
--- a/src/components/taggs/TaggsBar.tsx
+++ b/src/components/taggs/TaggsBar.tsx
@@ -48,6 +48,7 @@ const TaggsBar: React.FC<TaggsBarProps> = ({
isIntegrated={INTEGRATED_SOCIAL_LIST.indexOf(social) !== -1}
setTaggsNeedUpdate={setTaggsNeedUpdate}
setSocialDataNeedUpdate={socialsNeedUpdate}
+ userId={user.userId}
/>,
);
i++;
@@ -62,6 +63,7 @@ const TaggsBar: React.FC<TaggsBarProps> = ({
isIntegrated={INTEGRATED_SOCIAL_LIST.indexOf(social) !== -1}
setTaggsNeedUpdate={setTaggsNeedUpdate}
setSocialDataNeedUpdate={socialsNeedUpdate}
+ userId={user.userId}
/>,
);
i++;
diff --git a/src/constants/constants.ts b/src/constants/constants.ts
index 449b3142..be34f7f0 100644
--- a/src/constants/constants.ts
+++ b/src/constants/constants.ts
@@ -25,7 +25,7 @@ export const SOCIAL_LIST: string[] = [
'Facebook',
'Twitter',
'Snapchat',
- 'Tiktok',
+ 'TikTok',
// TODO: we don't have endpoints to support these yet...
// 'Twitch',
// 'Pinterest',
diff --git a/src/services/SocialLinkingService.ts b/src/services/SocialLinkingService.ts
index 8d67d90e..c9ffcedf 100644
--- a/src/services/SocialLinkingService.ts
+++ b/src/services/SocialLinkingService.ts
@@ -20,21 +20,50 @@ export const integratedEndpoints: {[social: string]: [string, string]} = {
Twitter: [LINK_TWITTER_OAUTH, LINK_TWITTER_ENDPOINT],
};
-export const nonIntegratedEndponits: {[social: string]: string} = {
+export const nonIntegratedEndpoints: {[social: string]: string} = {
Snapchat: LINK_SNAPCHAT_ENDPOINT,
TikTok: LINK_TIKTOK_ENDPOINT,
};
+export const getNonIntegratedURL: (
+ socialType: string,
+ userId: string,
+) => Promise<string> = async (socialType, userId) => {
+ if (!(socialType in nonIntegratedEndpoints)) {
+ return '';
+ }
+ try {
+ const userToken = await AsyncStorage.getItem('token');
+ const response = await fetch(
+ nonIntegratedEndpoints[socialType] + userId + '/',
+ {
+ method: 'GET',
+ headers: {
+ Authorization: `Token ${userToken}`,
+ },
+ },
+ );
+ if (response.status !== 200) {
+ throw 'Unable to fetch profile URL:' + socialType;
+ }
+ const body = await response.json();
+ return body.url || '';
+ } catch (error) {
+ console.log(error);
+ return '';
+ }
+};
+
export const registerNonIntegratedSocialLink: (
socialType: string,
username: string,
) => Promise<boolean> = async (socialType, username) => {
- if (!(socialType in nonIntegratedEndponits)) {
+ if (!(socialType in nonIntegratedEndpoints)) {
return false;
}
try {
const user_token = await AsyncStorage.getItem('token');
- const response = await fetch(nonIntegratedEndponits[socialType], {
+ const response = await fetch(nonIntegratedEndpoints[socialType], {
method: 'POST',
headers: {
Authorization: `Token ${user_token}`,