|
1 | 1 | /* eslint-disable @typescript-eslint/no-require-imports */
|
2 |
| -import { ThemedText } from '@/components/ThemedText'; |
3 |
| -import { Feather } from '@expo/vector-icons'; |
4 |
| -import { Href, router } from 'expo-router'; |
5 |
| -import React, { useState } from 'react'; |
6 |
| -import { Image, SafeAreaView, Text, TouchableOpacity, View } from 'react-native'; |
| 2 | +import { ThemedText } from "@/components/ThemedText"; |
| 3 | +import { Feather } from "@expo/vector-icons"; |
| 4 | +import { Href, router } from "expo-router"; |
| 5 | +import React, { useEffect, useState } from "react"; |
| 6 | +import { Image, SafeAreaView, TouchableOpacity, View } from "react-native"; |
7 | 7 | //@ts-ignore
|
8 |
| -import ProgressBar from 'react-native-progress/Bar'; |
| 8 | +import ProgressBar from "react-native-progress/Bar"; |
| 9 | + |
| 10 | +type Level = 1 | 2 | 3 | "MAX"; |
9 | 11 |
|
10 | 12 | const Tree = () => {
|
11 |
| - const [progress, setProgress] = useState(0.4); // Example progress value (40%) |
| 13 | + const USER_EXP = 0; |
| 14 | + const USER_TEAM = "1"; |
| 15 | + const [progress, setProgress] = useState<number>(0); |
| 16 | + const [level, setLevel] = useState<Level>(1); |
| 17 | + |
| 18 | + useEffect(() => { |
| 19 | + const calculateLvl = (): Level => { |
| 20 | + if (USER_EXP >= 570) { |
| 21 | + return "MAX"; |
| 22 | + } else if (USER_EXP >= 270) { |
| 23 | + return 3; |
| 24 | + } else if (USER_EXP >= 90) { |
| 25 | + return 2; |
| 26 | + } else { |
| 27 | + return 1; |
| 28 | + } |
| 29 | + }; |
| 30 | + |
| 31 | + // Set the level |
| 32 | + const newLevel = calculateLvl(); |
| 33 | + setLevel(newLevel); |
| 34 | + |
| 35 | + let nextLevelExp = 0; |
| 36 | + if (newLevel === 3) { |
| 37 | + nextLevelExp = 570; |
| 38 | + } else if (newLevel === 2) { |
| 39 | + nextLevelExp = 270; |
| 40 | + } else if (newLevel === 1) { |
| 41 | + nextLevelExp = 90; |
| 42 | + } |
| 43 | + |
| 44 | + if (newLevel !== "MAX") { |
| 45 | + const progressToNextLevel = USER_EXP / nextLevelExp; |
| 46 | + setProgress(progressToNextLevel); |
| 47 | + } else { |
| 48 | + setProgress(1); |
| 49 | + } |
| 50 | + }, [USER_EXP]); |
| 51 | + |
| 52 | + const getImageSource = (): any => { |
| 53 | + switch (level) { |
| 54 | + case 1: |
| 55 | + return require(`@/assets/images/tree${USER_TEAM}-lvl1.png`); |
| 56 | + case 2: |
| 57 | + return require(`@/assets/images/tree${USER_TEAM}-lvl2.png`); |
| 58 | + case 3: |
| 59 | + return require(`@/assets/images/tree${USER_TEAM}-lvl3.png`); |
| 60 | + case "MAX": |
| 61 | + return require(`@/assets/images/tree${USER_TEAM}-lvl3.png`); |
| 62 | + default: |
| 63 | + return require(`@/assets/images/tree${USER_TEAM}-lvl1.png`); |
| 64 | + } |
| 65 | + }; |
12 | 66 |
|
13 | 67 | return (
|
14 | 68 | <SafeAreaView className="flex-1">
|
15 | 69 | {/* Top Navigation Icons */}
|
16 | 70 | <View className="flex flex-row justify-between px-8 mt-2 items-center">
|
17 |
| - <ThemedText |
18 |
| - className="text-4xl font-semibold mb-2" |
19 |
| - > |
| 71 | + <ThemedText className="text-4xl font-semibold mb-2"> |
20 | 72 | Twoje drzewo
|
21 | 73 | </ThemedText>
|
22 |
| - <TouchableOpacity onPress={() => router.push("/shop?redirect=tree" as Href)}> |
| 74 | + <TouchableOpacity |
| 75 | + onPress={() => router.push("/shop?redirect=tree" as Href)} |
| 76 | + > |
23 | 77 | <Feather name="shopping-bag" size={24} color="black" />
|
24 | 78 | </TouchableOpacity>
|
25 | 79 | </View>
|
26 | 80 |
|
27 | 81 | {/* Main Content */}
|
28 | 82 | <View className="px-8 mt-12 flex justify-between h-full">
|
29 | 83 | <Image
|
30 |
| - source={require('@/assets/images/tree15.png')} |
| 84 | + source={getImageSource()} |
31 | 85 | className="h-[510px] w-[300px] mx-auto"
|
32 |
| - // className="h-[595px] w-[300px] mx-auto" |
33 | 86 | />
|
34 |
| - <View className='absolute bottom-32 left-7'> |
35 |
| - <View className='flex-row items-center gap-2'> |
36 |
| - <ThemedText className='font-bold'>Poziom: 3 </ThemedText> |
37 |
| - <ProgressBar progress={0.5} width={250} height={20} color="#606c38" animating borderWidth={2} className="rounded-full" /> |
| 87 | + <View className="absolute bottom-32 left-7"> |
| 88 | + <View className="flex-row items-center gap-2"> |
| 89 | + <ThemedText className="font-bold"> |
| 90 | + {level === "MAX" ? "" : "Poziom:"} {level}{" "} |
| 91 | + </ThemedText> |
| 92 | + <ProgressBar |
| 93 | + progress={progress} |
| 94 | + width={250} |
| 95 | + height={20} |
| 96 | + color="#606c38" |
| 97 | + animating |
| 98 | + borderWidth={2} |
| 99 | + className="rounded-full" |
| 100 | + /> |
38 | 101 | </View>
|
39 | 102 | </View>
|
40 | 103 | </View>
|
|
0 commit comments