All files / atlas-mobile-ts/src/components/Profile ProfileHeader.tsx

0% Statements 0/17
0% Branches 0/2
0% Functions 0/7
0% Lines 0/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                                                         
/* Copyright (C) Click & Push Accessibility, Inc - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * Written and maintained by the Click & Push Development team 
 * <dev@clicknpush.ca>, January 2022
 */
 
import React, { memo } from "react"
import { View, Text } from "react-native"
import { useLandmarks } from "../../hooks/useLandmarks"
import { UserProfile } from "../../hooks/useProfile"
 
export const ProfileHeader: React.FC<{profile?: UserProfile}> = memo(({profile}) => {
    const {landmarks} = useLandmarks()
 
    const getLandmarkCount = () => {
        return landmarks?.filter(lm => lm.user == profile?.id).length
    }
 
    const getTotalLandmarkRating = () => {
        const userLandmarks = landmarks?.filter(lm => lm.user == profile?.id)
        if (userLandmarks?.length > 0)
            return userLandmarks?.filter(lm => lm.user == profile?.id)?.reduce((prev, current) => {return {rating: prev.rating + current.rating}}).rating
        else 
            return 0
    }
 
    return (
        <View style={{marginTop: 10, flexDirection: 'row', width: '100%', marginBottom: 20}}>
            <View style={{flexBasis: "50%"}}>
            <Text style={{fontSize: 17, textAlign: 'center'}}>{getLandmarkCount()}</Text>
                <Text style={{textAlign: 'center'}}>Landmarks</Text>
            </View>
            {/* This will be implemented when the social network feature is added
            <View style={{flexBasis: "33%"}}>
                <Text style={{fontSize: 10, textAlign: 'center'}}>Not yet implemented</Text>
                <Text style={{textAlign: 'center'}}>Friends</Text>
            </View> */}
            <View style={{flexBasis: "50%"}}>
                <Text style={{fontSize: 17, textAlign: 'center'}}>{getTotalLandmarkRating()}</Text>
                <Text style={{textAlign: 'center'}}>Rating</Text>
            </View>
        </View>
    )
})