Skip to content

Commit

Permalink
redid the UserContext, and I merged permission service into Location …
Browse files Browse the repository at this point in the history
…service to have the Location Context importing from one file
  • Loading branch information
KalebE36 committed Oct 2, 2024
1 parent c51a166 commit 4878316
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
3 changes: 1 addition & 2 deletions client/app/contexts/LocationContext.tsx
Original file line number Diff line number Diff line change
@@ -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";


Expand Down
17 changes: 3 additions & 14 deletions client/app/contexts/UserContext.tsx
Original file line number Diff line number Diff line change
@@ -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<UserType | null>(null);

Expand All @@ -10,17 +9,7 @@ export const useUser = () => {
};

export const UserProvider = ({ children }: { children: React.ReactNode }) => {
const [user, setUser] = useState<UserType>({
displayName: "DefaultDisplayName",
userIcon: {
imagePath: "DefaultImagePath",
colorHex: "#fff",
},
});

useEffect(() => {
user.displayName = generateName()
}, [])
const [user, setUser] = useState<UserType>(initializeUser);

Check warning on line 12 in client/app/contexts/UserContext.tsx

View workflow job for this annotation

GitHub Actions / lint (21.x)

'setUser' is assigned a value but never used

return <UserContext.Provider value={user}>{children}</UserContext.Provider>;
};
10 changes: 10 additions & 0 deletions client/app/services/LocationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ export const getLocation = async (): Promise<Location.LocationObject | null> =>
return null;
}
};

// Permission Service to Handle Location Permissions
export const checkLocationPermission = async (): Promise<boolean> => {
const { status } = await Location.requestForegroundPermissionsAsync();
if (status !== "granted") {
console.log("Permission to access location was denied");
return false;
}
return true;
};
11 changes: 0 additions & 11 deletions client/app/services/PermissionService.ts

This file was deleted.

13 changes: 13 additions & 0 deletions client/app/services/UserService.ts
Original file line number Diff line number Diff line change
@@ -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",
},
};
};

0 comments on commit 4878316

Please sign in to comment.