Skip to content

Commit

Permalink
Fixed Small Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazan10x committed Dec 18, 2023
1 parent 24de457 commit 0f16541
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 42 deletions.
1 change: 0 additions & 1 deletion backend/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def get_top_users() -> Response:
}
)


except CarbonTrackError as e:
abort(code=400, description=f"{e}")

Expand Down
3 changes: 3 additions & 0 deletions backend/utils/update_user_level_and_footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def update_user_level_and_footprint(user_id: ObjectId) -> None:
if entry.calculate_carbon_emissions() != 0 and _is_within_one_month(entry.date)]
weekly_entries_completed += transportation_entries_overall.__len__()
if transportation_entries_overall.__len__() != 0:
overall_score += 25
last_entry = transportation_entries_overall[0]
for entry in transportation_entries_overall[1:]:
if last_entry.calculate_carbon_emissions() > entry.calculate_carbon_emissions():
Expand Down Expand Up @@ -91,6 +92,7 @@ def update_user_level_and_footprint(user_id: ObjectId) -> None:
if entry.calculate_carbon_emissions() != 0 and _is_within_one_month(entry.date)]
weekly_entries_completed += food_entries_overall.__len__()
if food_entries_overall.__len__() != 0:
overall_score += 25
last_entry = food_entries_overall[0]
for entry in food_entries_overall[1:]:
if last_entry.calculate_carbon_emissions() > entry.calculate_carbon_emissions():
Expand Down Expand Up @@ -123,6 +125,7 @@ def update_user_level_and_footprint(user_id: ObjectId) -> None:
if entry.calculate_carbon_emissions() != 0 and _is_within_one_month(entry.date)]
weekly_entries_completed += energy_entries_overall.__len__()
if energy_entries_overall.__len__() != 0:
overall_score += 25
last_entry = energy_entries_overall[0]
for entry in energy_entries_overall[1:]:
if last_entry.calculate_carbon_emissions() > entry.calculate_carbon_emissions():
Expand Down
79 changes: 44 additions & 35 deletions frontend/src/screens/communityHub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@ export default function DashBoardScreen(): JSX.Element {
});

const [topUsersMonthly, setMonthlyUsers] = useState<RankUser[]>([]);
const [, setYearlyUsers] = useState<RankUser[]>([]);
const [topUsersYearly, setYearlyUsers] = useState<RankUser[]>([]);
const [topUsersOverall, setOverallUsers] = useState<RankUser[]>([]);
const [refreshing, setRefreshing] = useState(false);

// User's monthly rank
const userRankMonthly: RankUser = { rank: 89, name: 'Squishyhoshi', footprint: 200, score: 5 };
// User's yearly/overall rank
const userRankOverall: RankUser = { rank: 89, name: 'Squishyhoshi', footprint: 200, score: 5 };

const MonthlyLeaderboard = (): JSX.Element => {
return (
<View>
Expand All @@ -61,14 +56,31 @@ export default function DashBoardScreen(): JSX.Element {
nestedScrollEnabled
/>
</ScrollView>
<View style={styles.leaderBoardBottom}>
<Text style={[styles.item, styles.rankItem]}>{userRankMonthly.rank}</Text>
<Text ellipsizeMode="tail" numberOfLines={1} style={[styles.item, styles.nameItem]}>
{userRankMonthly.name}
</Text>
<Text style={styles.item}>{userRankMonthly.footprint}</Text>
<Text style={styles.item}>{getUserLevel(userRankMonthly.score)}</Text>
</View>
</View>
);
};

const YearlyLeaderboard = (): JSX.Element => {
return (
<View>
<ScrollView style={styles.scrollLeaderBoardContainer} horizontal>
<FlatList
data={topUsersYearly}
keyExtractor={(item) => item.rank.toString()}
style={styles.flatListContainer}
renderItem={({ item }) => (
<View style={styles.row}>
<Text style={[styles.item, styles.rankItem]}>{item.rank}</Text>
<Text ellipsizeMode="tail" numberOfLines={1} style={[styles.item, styles.nameItem]}>
{item.name}
</Text>
<Text style={styles.item}>{item.footprint}</Text>
<Text style={styles.item}>{getUserLevel(item.score)}</Text>
</View>
)}
nestedScrollEnabled
/>
</ScrollView>
</View>
);
};
Expand All @@ -94,19 +106,11 @@ export default function DashBoardScreen(): JSX.Element {
nestedScrollEnabled
/>
</ScrollView>
<View style={styles.leaderBoardBottom}>
<Text style={[styles.item, styles.rankItem]}>{userRankOverall.rank}</Text>
<Text ellipsizeMode="tail" numberOfLines={1} style={[styles.item, styles.nameItem]}>
{userRankOverall.name}
</Text>
<Text style={styles.item}>{userRankOverall.footprint}</Text>
<Text style={styles.item}>{getUserLevel(userRankOverall.score)}</Text>
</View>
</View>
);
};

const [activeTab, setActiveTab] = useState<'monthly' | 'overall'>('monthly');
const [activeTab, setActiveTab] = useState<'monthly' | 'yearly' | 'overall'>('monthly');

const [expandedItem, setExpandedItem] = useState<number | null>(null);

Expand Down Expand Up @@ -243,6 +247,12 @@ export default function DashBoardScreen(): JSX.Element {
>
<Text style={styles.tabText}>Monthly</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.tab, activeTab === 'yearly' && styles.activeTab]}
onPress={() => setActiveTab('yearly')}
>
<Text style={styles.tabText}>Yearly</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.tab, activeTab === 'overall' && styles.activeTab]}
onPress={() => setActiveTab('overall')}
Expand All @@ -258,7 +268,15 @@ export default function DashBoardScreen(): JSX.Element {
<Text style={styles.headerItem}>Level</Text>
</View>

<View>{activeTab === 'monthly' ? <MonthlyLeaderboard /> : <OverallLeaderboard />}</View>
<View>
{activeTab === 'monthly' ? (
<MonthlyLeaderboard />
) : activeTab === 'yearly' ? (
<YearlyLeaderboard />
) : (
<OverallLeaderboard />
)}
</View>
</View>
</View>

Expand Down Expand Up @@ -337,15 +355,6 @@ const styles = StyleSheet.create({
marginTop: 20,
borderColor: Colors.LIGHTFGREEN,
},
leaderBoardBottom: {
flexDirection: 'row',
borderTopWidth: 1.5,
paddingBottom: 5,
marginBottom: 10,
marginTop: 10,
paddingTop: 5,
borderColor: Colors.LIGHTFGREEN,
},
headerItem: {
flex: 1,
fontWeight: 'bold',
Expand Down Expand Up @@ -375,7 +384,7 @@ const styles = StyleSheet.create({
flex: 1.5,
},
scrollLeaderBoardContainer: {
maxHeight: 150,
maxHeight: 350,
width: 500,
},
scrollChallengesContainer: {
Expand Down Expand Up @@ -422,7 +431,7 @@ const styles = StyleSheet.create({
flexDirection: 'row',
marginTop: 15,
justifyContent: 'space-between',
paddingHorizontal: 70,
paddingHorizontal: 15,
},
tab: {
paddingVertical: 8,
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/widgets/carbonWidgetBox.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import { View, Text,StyleSheet } from 'react-native';
import Colors from '../../assets/colorConstants';
import { type carbonWidgetProps } from '../components/types';
import {type carbonWidgetProps } from '../components/types';
import { useFonts } from 'expo-font';


const CarbonWidgetBox: React.FC<carbonWidgetProps> = ({ carbonUser }) => {
const [loaded] = useFonts({
Montserrat: require('../../assets/fonts/MontserratThinRegular.ttf'),
Expand All @@ -18,7 +19,10 @@ const CarbonWidgetBox: React.FC<carbonWidgetProps> = ({ carbonUser }) => {
<View style={styles.boxContainer}>
<View>
<Text style={styles.header}> Carbon Footprint </Text>
<Text style={styles.footprint}> getUserFootprint </Text>
<Text
style={styles.footprint}
> Access Your Carbon Foootprint Hisotry and Recommendations
</Text>

</View>
</View>
Expand All @@ -45,7 +49,7 @@ const styles = StyleSheet.create({
textAlign: 'center',
color: Colors.WHITE,
fontSize: 14,
paddingLeft: '30%',
paddingLeft: '10%',
paddingTop: '10%',
},
header: {
Expand Down
16 changes: 13 additions & 3 deletions frontend/src/widgets/profileWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import React, { useCallback, useState } from 'react';
import { View, Text, Image, StyleSheet, TouchableOpacity } from 'react-native';
import Colors from '../../assets/colorConstants';
import { type profileWidgetBoxProps } from '../components/types';
import { type RootStackParamList, type profileWidgetBoxProps } from '../components/types';
import { useFonts } from 'expo-font';
import ExpProgressBar from '../components/expProgressBar';
import firebaseService from '../utilities/firebase';
import { useFocusEffect } from '@react-navigation/native';
import { useFocusEffect, useNavigation } from '@react-navigation/native';
import { type StackNavigationProp } from '@react-navigation/stack';
export type StackNavigation = StackNavigationProp<RootStackParamList>;

const ProfileWidgetBox: React.FC<profileWidgetBoxProps> = ({ user }) => {
const navigation = useNavigation<StackNavigation>();
const [loaded] = useFonts({
Montserrat: require('../../assets/fonts/MontserratThinRegular.ttf'),
Josefin: require('../../assets/fonts/JosefinSansThinRegular.ttf'),
Expand Down Expand Up @@ -52,7 +55,14 @@ const ProfileWidgetBox: React.FC<profileWidgetBoxProps> = ({ user }) => {
<Text style={styles.buttonText} > Badges </Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button}>
<Text style={styles.buttonText}> Rank getUserRank </Text>
<Text
style={styles.buttonText}
onPress={() => {
navigation.navigate('CommunityHub');
}}
>
Access Leaderboard
</Text>
</TouchableOpacity>

</View>
Expand Down

0 comments on commit 0f16541

Please sign in to comment.