diff --git a/client/app/contexts/LocationContext.tsx b/client/app/contexts/LocationContext.tsx index e20429c2d..00d7659f1 100644 --- a/client/app/contexts/LocationContext.tsx +++ b/client/app/contexts/LocationContext.tsx @@ -1,7 +1,6 @@ import { LOCATION_REFRESH_RATE } from "@env"; import React, { createContext, useContext, useEffect, useState } from "react"; -import { getLocation } from "@app/services/LocationService"; -import { checkLocationPermission } from "@app/services/PermissionService"; +import { getLocation, checkLocationPermission } from "@app/services/LocationService"; import { LocationContextProps, LocationType } from "@app/types/Location"; diff --git a/client/app/contexts/UserContext.tsx b/client/app/contexts/UserContext.tsx index 9dcaf92b2..26bef57e0 100644 --- a/client/app/contexts/UserContext.tsx +++ b/client/app/contexts/UserContext.tsx @@ -1,7 +1,6 @@ -import React, { createContext, useContext, useEffect, useState } from "react"; - +import React, { createContext, useContext, useState } from "react"; import { UserType } from "../types/User"; -import { generateName } from "@app/utils/scripts"; +import { initializeUser } from "@app/services/UserService"; const UserContext = createContext(null); @@ -10,17 +9,7 @@ export const useUser = () => { }; export const UserProvider = ({ children }: { children: React.ReactNode }) => { - const [user, setUser] = useState({ - displayName: "DefaultDisplayName", - userIcon: { - imagePath: "DefaultImagePath", - colorHex: "#fff", - }, - }); - - useEffect(() => { - user.displayName = generateName() - }, []) + const [user, setUser] = useState(initializeUser); return {children}; }; diff --git a/client/app/services/LocationService.ts b/client/app/services/LocationService.ts index 868a0a369..be23242f6 100644 --- a/client/app/services/LocationService.ts +++ b/client/app/services/LocationService.ts @@ -11,3 +11,13 @@ export const getLocation = async (): Promise => return null; } }; + +// Permission Service to Handle Location Permissions +export const checkLocationPermission = async (): Promise => { + const { status } = await Location.requestForegroundPermissionsAsync(); + if (status !== "granted") { + console.log("Permission to access location was denied"); + return false; + } + return true; +}; diff --git a/client/app/services/PermissionService.ts b/client/app/services/PermissionService.ts deleted file mode 100644 index 9cab26be0..000000000 --- a/client/app/services/PermissionService.ts +++ /dev/null @@ -1,11 +0,0 @@ -import * as Location from "expo-location"; - -// Permission Service to Handle Location Permissions -export const checkLocationPermission = async (): Promise => { - const { status } = await Location.requestForegroundPermissionsAsync(); - if (status !== "granted") { - console.log("Permission to access location was denied"); - return false; - } - return true; -}; diff --git a/client/app/services/UserService.ts b/client/app/services/UserService.ts new file mode 100644 index 000000000..4976d8c7e --- /dev/null +++ b/client/app/services/UserService.ts @@ -0,0 +1,13 @@ +import { UserType } from "../types/User"; +import { generateName } from "@app/utils/scripts"; + +// Function to initialize default user +export const initializeUser = (): UserType => { + return { + displayName: generateName(), + userIcon: { + imagePath: "DefaultImagePath", + colorHex: "#fff", + }, + }; +};