From 0cc8363a5890ec7fa15f48996fb813f47b6c71b4 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Tue, 1 Jun 2021 17:40:33 -0400 Subject: Convert local badges to display badges, Cleanup code --- src/utils/common.ts | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src/utils/common.ts') diff --git a/src/utils/common.ts b/src/utils/common.ts index 95e77f64..6804558f 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -1,12 +1,18 @@ import AsyncStorage from '@react-native-community/async-storage'; +import {HeaderTitle} from '@react-navigation/stack'; import moment from 'moment'; import {Linking} from 'react-native'; import {getAll} from 'react-native-contacts'; -import {BROWSABLE_SOCIAL_URLS, TOGGLE_BUTTON_TYPE} from '../constants'; +import { + BADGE_DATA, + BROWSABLE_SOCIAL_URLS, + TOGGLE_BUTTON_TYPE, +} from '../constants'; import { ContactType, NotificationType, - UniversityBadgeType, + UniversityBadge, + UniversityBadgeDisplayType, UniversityType, } from './../types/types'; @@ -197,3 +203,28 @@ export const validateImageLink = async (url: string | undefined) => { return false; }); }; + +/** + * Turns a list badges into display badges (with img) by looking up the img source + * from our badge asset lookup constant. + * @param badges list of university badges + * @returns list of display badges + */ +export const badgesToDisplayBadges = (badges: UniversityBadge[]) => { + const displayBadges: UniversityBadgeDisplayType[] = []; + badges.forEach((badge) => { + BADGE_DATA[badge.university].forEach((category) => { + if (category.title === badge.category) { + category.data.forEach((badgeInfo) => { + if (badgeInfo.badgeName === badge.name) { + displayBadges.push({ + ...badge, + img: badgeInfo.badgeImage, + }); + } + }); + } + }); + }); + return displayBadges; +}; -- cgit v1.2.3-70-g09d2