-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from FYP-2024-IQMA/SCRUM-170-Create-Frontend-f…
…or-All-Badges-and-Integrate-with-Backend SCRUM-170 Create frontend for all badges
- Loading branch information
Showing
4 changed files
with
247 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
import { | ||
Text, | ||
View, | ||
TextInput, | ||
TouchableOpacity, | ||
StyleSheet, | ||
ScrollView, | ||
Image, | ||
} from 'react-native'; | ||
import {useState, useContext, useEffect} from 'react'; | ||
import {AuthContext} from '@/context/AuthContext'; | ||
import {LoadingIndicator} from '@/components/LoadingIndicator'; | ||
import * as gamificationEndpoints from '@/helpers/gamificationEndpoints'; | ||
import {Colors} from '@/constants/Colors'; | ||
import { formatSection } from '@/helpers/formatSectionID'; | ||
|
||
export default function Achievements() { | ||
const {currentUser} = useContext(AuthContext); | ||
const [badges, setBadges] = useState<any[]>([]); | ||
const [loading, setLoading] = useState<boolean>(true); | ||
|
||
const mock = [ | ||
{ | ||
sectionID: 'SEC0001', | ||
badges: [ | ||
{ | ||
unitName: 'Foundations of Communication', | ||
badgeUrl: | ||
'https://lugppkebziopzwushqcg.supabase.co/storage/v1/object/public/badges/placeholder.png', | ||
}, | ||
{ | ||
unitName: 'Written Communication Proficiency', | ||
badgeUrl: | ||
'https://lugppkebziopzwushqcg.supabase.co/storage/v1/object/public/badges/placeholder.png', | ||
}, | ||
{ | ||
unitName: 'Visual Communication Strategies', | ||
badgeUrl: | ||
'https://lugppkebziopzwushqcg.supabase.co/storage/v1/object/public/badges/placeholder.png', | ||
}, | ||
{ | ||
unitName: 'Stakeholder Analysis and Audience Engagement', | ||
badgeUrl: | ||
'https://lugppkebziopzwushqcg.supabase.co/storage/v1/object/public/badges/placeholder.png', | ||
}, | ||
{ | ||
unitName: 'Interpersonal Communication Excellence', | ||
badgeUrl: | ||
'https://lugppkebziopzwushqcg.supabase.co/storage/v1/object/public/badges/SEC0001/unit3.png', | ||
}, | ||
{ | ||
unitName: 'Mastering Two-Way Communication', | ||
badgeUrl: | ||
'https://lugppkebziopzwushqcg.supabase.co/storage/v1/object/public/badges/SEC0001/unit2.png', | ||
}, | ||
{ | ||
unitName: 'The Art of Persuasion', | ||
badgeUrl: | ||
"https://lugppkebziopzwushqcg.supabase.co/storage/v1/object/public/badges/locked.png", | ||
}, | ||
], | ||
}, | ||
{ | ||
sectionID: 'SEC0002', | ||
badges: [ | ||
{ | ||
unitName: 'Foundations of Communication', | ||
badgeUrl: | ||
'https://lugppkebziopzwushqcg.supabase.co/storage/v1/object/public/badges/placeholder.png', | ||
}, | ||
{ | ||
unitName: 'Written Communication Proficiency', | ||
badgeUrl: | ||
"https://lugppkebziopzwushqcg.supabase.co/storage/v1/object/public/badges/locked.png", | ||
}, | ||
{ | ||
unitName: 'Visual Communication Strategies', | ||
badgeUrl: | ||
"https://lugppkebziopzwushqcg.supabase.co/storage/v1/object/public/badges/locked.png", | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const fetchAchievements = async () => { | ||
try { | ||
const badges = await gamificationEndpoints.getBadges( | ||
currentUser.sub | ||
); | ||
|
||
setBadges(badges); | ||
|
||
console.log(badges); | ||
} catch (error) { | ||
console.error('Error fetching achievements', error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchAchievements(); | ||
}, []); | ||
|
||
if (loading) { | ||
return <LoadingIndicator />; | ||
} | ||
|
||
return ( | ||
<ScrollView style={styles.container}> | ||
<View> | ||
{badges.map((section) => ( | ||
<> | ||
<View style={styles.sectionContainer}> | ||
<Text style={styles.sectionHeading}> | ||
{/* {section.sectionID} */} | ||
Section {formatSection(section.sectionID)} | ||
</Text> | ||
<View | ||
key={section.sectionID} | ||
style={styles.badgeOuterContainer} | ||
> | ||
{section.badges.map( | ||
(badge: { | ||
badgeUrl: string; | ||
unitName: string; | ||
}) => ( | ||
<View style={styles.badgeContainer}> | ||
<Image | ||
source={{uri: badge.badgeUrl}} | ||
style={styles.badgeImage} | ||
/> | ||
{/* <Text style={styles.unlockedBadgeText}> */} | ||
<Text | ||
style={ | ||
badge.badgeUrl.endsWith( | ||
'locked.png' | ||
) | ||
? styles.lockedBadgeText | ||
: styles.unlockedBadgeText | ||
} | ||
> | ||
{badge.unitName} | ||
</Text> | ||
</View> | ||
) | ||
)} | ||
</View> | ||
</View> | ||
</> | ||
))} | ||
</View> | ||
</ScrollView> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
// flex: 1, | ||
// padding: 20, | ||
paddingHorizontal: 20, | ||
}, | ||
sectionContainer: { | ||
marginTop: 20, | ||
}, | ||
sectionHeading: { | ||
color: Colors.light.color, | ||
fontWeight: 'bold', | ||
fontSize: 16, | ||
textAlign: "center" | ||
}, | ||
badgeOuterContainer: { | ||
flexDirection: 'row', | ||
flexWrap: 'wrap', | ||
justifyContent: 'space-between', | ||
marginTop: 10, | ||
// backgroundColor: 'red', | ||
}, | ||
badgeImage: { | ||
width: '100%', | ||
aspectRatio: 1, | ||
resizeMode: 'contain', | ||
}, | ||
badgeContainer: { | ||
width: '30%', | ||
marginBottom: 20, | ||
alignItems: 'center', | ||
}, | ||
unlockedBadgeText: { | ||
marginTop: 10, | ||
textAlign: 'center', | ||
// color: Colors.light.text, | ||
color: Colors.default.purple500, | ||
fontWeight: 'bold', | ||
}, | ||
lockedBadgeText: { | ||
marginTop: 10, | ||
textAlign: 'center', | ||
color: Colors.light.text, | ||
fontWeight: 'bold', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters