diff --git a/app.json b/app.json index c72bb3d..a63fa14 100644 --- a/app.json +++ b/app.json @@ -1,4 +1,4 @@ { - "name": "pokemon_city_stats", - "displayName": "pokemon_city_stats" -} \ No newline at end of file + "name": "pokemon_city_stats", + "displayName": "Pokemon City Statistics" +} diff --git a/package-lock.json b/package-lock.json index 5cce4b7..62c3dc2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3320,11 +3320,6 @@ "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", "integrity": "sha512-hjf+xovcEn31w/EUYdTXQh/8smFL/dzYjohQGEIgjyNavaJfBY2p5F527Bo1VPATxv0VYTUC2bOcXvqFwk78Og==" }, - "dedent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/dedent/-/dedent-0.6.0.tgz", - "integrity": "sha512-cSfRWjXJtZQeRuZGVvDrJroCR5V2UvBNUMHsPCdNYzuAG8b9V8aAy3KUcdQrGQPXs17Y+ojbPh1aOCplg9YR9g==" - }, "deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", @@ -6059,15 +6054,6 @@ "js-tokens": "^3.0.0 || ^4.0.0" } }, - "lottie-react-native": { - "version": "5.1.4", - "resolved": "https://registry.npmjs.org/lottie-react-native/-/lottie-react-native-5.1.4.tgz", - "integrity": "sha512-Lu6mSG92Wck+vXEX6gfj/9ciqqoz0tJQZqgX0SumGvX/oZu4MbKO/oLApyHdy2V9Rb7qvwF9whOtitADxTswPA==", - "requires": { - "invariant": "^2.2.2", - "react-native-safe-modules": "^1.0.3" - } - }, "lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -7417,14 +7403,6 @@ } } }, - "react-native-animated-pull-to-refresh": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/react-native-animated-pull-to-refresh/-/react-native-animated-pull-to-refresh-1.0.3.tgz", - "integrity": "sha512-JpUKzqor8XIt6b1LUUYH7oMnzpeyp0YoWEm/miKZfFmglHTNq+CILTa3kTPJerThb0+jEeswiCJI3NgoLbtUJg==", - "requires": { - "prop-types": "^15.7.2" - } - }, "react-native-codegen": { "version": "0.70.6", "resolved": "https://registry.npmjs.org/react-native-codegen/-/react-native-codegen-0.70.6.tgz", @@ -7496,14 +7474,6 @@ "resolved": "https://registry.npmjs.org/react-native-safe-area-context/-/react-native-safe-area-context-4.4.1.tgz", "integrity": "sha512-N9XTjiuD73ZpVlejHrUWIFZc+6Z14co1K/p1IFMkImU7+avD69F3y+lhkqA2hN/+vljdZrBSiOwXPkuo43nFQA==" }, - "react-native-safe-modules": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/react-native-safe-modules/-/react-native-safe-modules-1.0.3.tgz", - "integrity": "sha512-DUxti4Z+AgJ/ZsO5U7p3uSCUBko8JT8GvFlCeOXk9bMd+4qjpoDvMYpfbixXKgL88M+HwmU/KI1YFN6gsQZyBA==", - "requires": { - "dedent": "^0.6.0" - } - }, "react-native-screens": { "version": "3.18.2", "resolved": "https://registry.npmjs.org/react-native-screens/-/react-native-screens-3.18.2.tgz", @@ -7840,11 +7810,6 @@ "glob": "^7.1.3" } }, - "rn-sprite-sheet": { - "version": "1.1.12", - "resolved": "https://registry.npmjs.org/rn-sprite-sheet/-/rn-sprite-sheet-1.1.12.tgz", - "integrity": "sha512-Cl8asom4asoSRwCqs2wz3sKXk6b6s32yDIF28xx/EFhTi4H+y45YZyMB/WHpZ1YSc28sWRFiHW0z1Han8jYT4w==" - }, "rsvp": { "version": "4.8.5", "resolved": "https://registry.npmjs.org/rsvp/-/rsvp-4.8.5.tgz", diff --git a/package.json b/package.json index 5478849..c237df9 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,8 @@ "@rneui/base": "^4.0.0-rc.6", "@rneui/themed": "^4.0.0-rc.6", "axios": "^0.27.2", - "lottie-react-native": "^5.1.4", "react": "18.1.0", "react-native": "0.70.3", - "react-native-animated-pull-to-refresh": "^1.0.3", "react-native-element-dropdown": "^2.3.1", "react-native-fast-image": "^8.6.3", "react-native-gesture-handler": "^2.8.0", @@ -29,8 +27,7 @@ "react-native-root-toast": "^3.4.0", "react-native-safe-area-context": "^4.4.1", "react-native-screens": "^3.18.2", - "react-native-vector-icons": "^9.2.0", - "rn-sprite-sheet": "^1.1.12" + "react-native-vector-icons": "^9.2.0" }, "devDependencies": { "@babel/core": "^7.12.9", diff --git a/src/components/users/UserRanking.tsx b/src/components/users/UserRanking.tsx index 35f1527..77744b3 100644 --- a/src/components/users/UserRanking.tsx +++ b/src/components/users/UserRanking.tsx @@ -1,5 +1,5 @@ import React, { useContext, useEffect, useState } from "react"; -import { ScrollView, StyleSheet, Text, View } from "react-native"; +import { ScrollView } from "react-native"; import { RefreshControl } from "react-native-gesture-handler"; import UserService from "../../api/UserService"; import { UserContext } from "../../context/Context"; diff --git a/src/context/AuthContextProvider.tsx b/src/context/AuthContextProvider.tsx index ef8c48b..2d03264 100644 --- a/src/context/AuthContextProvider.tsx +++ b/src/context/AuthContextProvider.tsx @@ -2,7 +2,15 @@ import React, { createContext, ReactElement, useState } from "react"; import AuthContextType from "../types/context/AuthContextType"; import { AuthContext } from "./Context"; +/** + * Component that wraps its children in the provider for the authContext + * All children can now user the useContext hook to access the auth state + * They also get access to the setLoggedIn method that sets if the user is logged in or not + */ const AuthContextProvider = ({ children }: { children: JSX.Element[] | JSX.Element }) => { + // Holds the actual context object + // LoggedIn is true if the user is logged in + // setLoggedIn calls the setter of the state where the context is stored, so updates the context const getAuthContextValue = (): AuthContextType => { return { loggedIn: false, @@ -15,6 +23,11 @@ const AuthContextProvider = ({ children }: { children: JSX.Element[] | JSX.Eleme }; }; + // State that holds the authContext + // Placing this in a state triggers a re-render on every change + // This state will be the same as the global context + // => Context makes the state global + // => State triggers the re-render on change const [authContextValue, setAuthContextValue] = useState(getAuthContextValue()); return {children}; diff --git a/src/routes/Navigator.tsx b/src/routes/Navigator.tsx index acd3089..c584cc6 100644 --- a/src/routes/Navigator.tsx +++ b/src/routes/Navigator.tsx @@ -19,17 +19,30 @@ const SearchUserStack = createNativeStackNavigator(); const AccountStack = createNativeStackNavigator(); const Tab = createBottomTabNavigator(); +/** + * Main application component holding all the different screens + * It shows the correct stack depending on the state of the application: + * - Loading: If the app is still checking the auth state + * - Login: If the user is not logged in + * - Tabs: If the user is logged in + * -> Each tab consists of a stack navigator + */ const Navigator = () => { const [loading, setLoading] = useState(true); const authContext = useContext(AuthContext); + // Checks if the user is authenticated and sets the global state for it useEffect(() => { AuthService.isAuthenticated().then(authenticated => { + console.log(authenticated); authContext.setLoggedIn(authenticated); setLoading(false); }); }, []); + /** + * Creates the correct stack for the current state of the application + */ const buildNavigator = () => { if (loading) { return ( diff --git a/src/screens/AccountScreen.tsx b/src/screens/AccountScreen.tsx index 59fb435..f981831 100644 --- a/src/screens/AccountScreen.tsx +++ b/src/screens/AccountScreen.tsx @@ -1,8 +1,10 @@ -import { Text } from "@rneui/base"; import React from "react"; import ScreenContent from "../components/content/ScreenContent"; import Account from "../components/users/Account"; +/** + * Screen holding the account information + */ const AccountScreen = () => { return ( diff --git a/src/screens/CityPreviewScreen.tsx b/src/screens/CityPreviewScreen.tsx index c258602..cb523fd 100644 --- a/src/screens/CityPreviewScreen.tsx +++ b/src/screens/CityPreviewScreen.tsx @@ -2,6 +2,9 @@ import React from "react"; import World from "../components/cityPreview/World"; import ScreenContent from "../components/content/ScreenContent"; +/** + * Screen showing the preview of a city of the selected user + */ const CityPreviewScreen = ({ route }: any) => { const userId: Readonly = route.params; diff --git a/src/screens/LeaderboardScreen.tsx b/src/screens/LeaderboardScreen.tsx index 0ce9e1a..0fb9172 100644 --- a/src/screens/LeaderboardScreen.tsx +++ b/src/screens/LeaderboardScreen.tsx @@ -1,9 +1,10 @@ -import { Text } from "@rneui/base"; import React from "react"; -import { View } from "react-native"; import ScreenContent from "../components/content/ScreenContent"; import UserRanking from "../components/users/UserRanking"; +/** + * Screen showing the ranking of the users + */ const LeaderboardScreen = () => { return ( diff --git a/src/screens/LoadingScreen.tsx b/src/screens/LoadingScreen.tsx index 483de22..dce8b59 100644 --- a/src/screens/LoadingScreen.tsx +++ b/src/screens/LoadingScreen.tsx @@ -1,8 +1,10 @@ -import { Text } from "@rneui/base"; import React from "react"; import { View } from "react-native"; import LoadingAnimation from "../components/LoadingAnimation"; +/** + * Screen showing the loading animation + */ const LoadingScreen = () => { return ( diff --git a/src/screens/LoginScreen.tsx b/src/screens/LoginScreen.tsx index 8e79bf6..44b3e7e 100644 --- a/src/screens/LoginScreen.tsx +++ b/src/screens/LoginScreen.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from "react"; +import React, { useContext, useState } from "react"; import { NativeSyntheticEvent, Pressable, StyleSheet, TextInput, TextInputChangeEventData, TextInputComponent, View } from "react-native"; import { Text } from "@rneui/base"; import { Immersive } from "react-native-immersive"; @@ -6,24 +6,39 @@ import LoginScreenStyle from "../styles/screens/LoginScreenStyle"; import AuthService from "../api/AuthService"; import { AuthContext } from "../context/Context"; +/** + * Screen showing the login form and handling login actions + */ const LoginScreen = () => { const authContext = useContext(AuthContext); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); + /** + * Updates the username state if the value of the input field changes + */ const handleUsernameChange = (event: NativeSyntheticEvent) => { setUsername(event.nativeEvent.text); }; + /** + * Updates the password state if the value of the input field changes + */ const handlePasswordChange = (event: NativeSyntheticEvent) => { setPassword(event.nativeEvent.text); }; + /** + * Handles clicking the login button by calling the userservice to login + */ const handleLoginClick = async () => { const loggedIn = await AuthService.login(username, password); authContext.setLoggedIn(loggedIn); }; + /** + * Handles unfocussing the input field by going back into fullscreen mode + */ const handleInputBlur = () => { Immersive.setImmersive(true); }; diff --git a/src/screens/SearchUserScreen.tsx b/src/screens/SearchUserScreen.tsx index a2b26af..b3f67fc 100644 --- a/src/screens/SearchUserScreen.tsx +++ b/src/screens/SearchUserScreen.tsx @@ -1,4 +1,4 @@ -import { Tab, TabView, Text } from "@rneui/base"; +import { TabView, Text } from "@rneui/base"; import React, { useState } from "react"; import { View, Pressable } from "react-native"; import ScreenContent from "../components/content/ScreenContent"; @@ -6,6 +6,9 @@ import SearchUserByNumericForm from "../components/form/SearchUserByNumericForm" import SearchUserByUsernameForm from "../components/form/SearchUserByUsernameForm"; import SearchUserScreenStyle from "../styles/screens/SearchUserScreenStyle"; +/** + * Screen holding the two forms to search users + */ const SearchUserScreen = () => { const [tabIndex, setTabIndex] = useState(0); diff --git a/src/screens/UserDetailsScreen.tsx b/src/screens/UserDetailsScreen.tsx index a3a247a..fee3278 100644 --- a/src/screens/UserDetailsScreen.tsx +++ b/src/screens/UserDetailsScreen.tsx @@ -1,4 +1,4 @@ -import { Route, useNavigation } from "@react-navigation/native"; +import { useNavigation } from "@react-navigation/native"; import { NativeStackScreenProps } from "@react-navigation/native-stack"; import { Text } from "@rneui/base"; import React from "react"; @@ -9,6 +9,9 @@ import UserData from "../types/model/UserData"; import StringUtils from "../utils/StringUtils"; import Icon from "react-native-vector-icons/FontAwesome5"; +/** + * Screen showing the details of a certain user which information is passed via the route param + */ const UserDetailsScreen = ({ route }: NativeStackScreenProps) => { const userData: Readonly | undefined = route.params; const navigator = useNavigation(); @@ -21,6 +24,9 @@ const UserDetailsScreen = ({ route }: NativeStackScreenProps) => { ); } + /** + * Handles pressing the view city button by navigation to the city preview screen + */ const handleViewCityPress = () => { navigator.navigate("CityPreview" as never, userData.id as never); }; diff --git a/src/utils/SpritesheetUtils.ts b/src/utils/SpritesheetUtils.ts index a20dd2d..320fbb1 100644 --- a/src/utils/SpritesheetUtils.ts +++ b/src/utils/SpritesheetUtils.ts @@ -3,6 +3,7 @@ import SpritesheetConfig from "../config/SpritesheetConfig"; import SpritesheetDimension from "../types/model/SpritesheetDimensions"; import SpritesheetLocation from "../types/model/SpritesheetLocation"; +/** Module containing util functions concerning spritesheets */ const SpritesheetUtils = (() => { /** * Calculates the dimensions of the object on the spriteshee given the first and last tile index