From 088c141293267d160b2247f6f893314f770d1ea5 Mon Sep 17 00:00:00 2001 From: Frank Nguyen <41023671+FrankreedX@users.noreply.github.com> Date: Thu, 15 Aug 2024 20:00:15 +0700 Subject: [PATCH 1/3] simple fix (#314) --- context/Auth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/Auth.js b/context/Auth.js index ad7168ea..a5550086 100644 --- a/context/Auth.js +++ b/context/Auth.js @@ -37,7 +37,7 @@ export const AuthProvider = ({ children }) => { const [currentUserId, setCurrentUserId] = useState(null); const [currentUserInfo, setCurrentUserInfo] = useState(null); const [currentTeamId, setCurrentTeamId] = useState("1"); - const [currentUserVerified, setCurrentUserVerified] = useState(false); + const [currentUserVerified, setCurrentUserVerified] = useState(true); useProtectedRoute(currentUserId); From 76fb5c78698a2a544a4fb7d7a682f36b4e1cb967 Mon Sep 17 00:00:00 2001 From: Frank Nguyen <41023671+FrankreedX@users.noreply.github.com> Date: Thu, 15 Aug 2024 20:00:29 +0700 Subject: [PATCH 2/3] IWB-1: added useBlacklist hook (#289) * added blacklist hook * removed transaction and hope that it works * fixed useBlackList.js hook firestore error, and made blacklist check functional * added refresh spinner for chooseTeam.js * kinda works lmao * minor comment change Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * fix - added email to blacklist record * fix - added assertion if pfp exists when removing a user * fixed "invalid-argument" * removed redundant remove user fix * pretty * added missing state from merge * simple fix --------- Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> Co-authored-by: Jake Gehrke --- app/segments/(team)/chooseTeam.js | 51 ++++++++++++------------------ context/Auth.js | 2 +- dbOperations/hooks/useBlackList.js | 31 ++++++++++++++++++ 3 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 dbOperations/hooks/useBlackList.js diff --git a/app/segments/(team)/chooseTeam.js b/app/segments/(team)/chooseTeam.js index 7b49e0fa..a2cd92a5 100644 --- a/app/segments/(team)/chooseTeam.js +++ b/app/segments/(team)/chooseTeam.js @@ -5,7 +5,7 @@ import { sendEmailVerification, signOut as signoutFireBase, } from "firebase/auth"; -import { doc, getDoc, setDoc } from "firebase/firestore"; +import { doc, setDoc } from "firebase/firestore"; import { useCallback, useEffect, useState } from "react"; import { RefreshControl, ScrollView, Text, View } from "react-native"; import { Button } from "react-native-paper"; @@ -13,8 +13,10 @@ import { SafeAreaView } from "react-native-safe-area-context"; import { TESTING, themeColors } from "~/Constants"; import { getErrorString } from "~/Utility"; import ErrorComponent from "~/components/errorComponent"; +import Loading from "~/components/loading"; import { useAlertContext } from "~/context/Alert"; import { useAuthContext } from "~/context/Auth"; +import { useBlackList } from "~/dbOperations/hooks/useBlackList"; import { invalidateMultipleKeys } from "~/dbOperations/invalidateMultipleKeys"; import { auth, db } from "~/firebaseConfig"; @@ -25,12 +27,17 @@ function ChooseTeam() { const { showDialog, showSnackBar } = useAlertContext(); - const [blacklist, setBlacklist] = useState(false); + const { + data: blacklist, + error: blacklistError, + isLoading: blacklistIsLoading, + } = useBlackList(); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); + const invalidateKeys = [["blacklist"]]; const [verified, setVerified] = useState(false); + const [refreshing, setRefreshing] = useState(false); //for Refresh Control + const [loading, setLoading] = useState(false); //for resend email button async function handleSignOut() { try { @@ -42,27 +49,6 @@ function ChooseTeam() { } } - // TODO: make an actual hook for this? Shouldn't be related tho, as is coach pov? - useEffect(() => { - const fetchBlacklistDoc = async () => { - try { - const docRef = doc(db, "teams", "1", "blacklist", currentUserId); - const docSnap = await getDoc(docRef); - - //See if the user is on blacklist - setBlacklist(docSnap.exists()); - } catch (e) { - setError(e); - } finally { - setLoading(false); - } - }; - - if (currentUserId) { - fetchBlacklistDoc(); - } - }, [currentUserId]); - useEffect(() => { if (TESTING) { setVerified(true); @@ -95,23 +81,26 @@ function ChooseTeam() { }; }, []); - const [refreshing, setRefreshing] = useState(false); - const onRefresh = useCallback(async () => { setRefreshing(true); await auth.currentUser.reload(); + await invalidateMultipleKeys(queryClient, invalidateKeys); setRefreshing(false); }, []); - if (error) { - return ; + if (blacklistIsLoading) { + return ; + } + + if (blacklistError) { + return ; } return ( - {blacklist ? ( + {blacklist[currentUserId] ? ( { } } }); - }, [currentUserVerified]); + }, []); return ( { + const { currentTeamId } = useAuthContext(); + + const { data, error, isLoading } = useQuery({ + queryKey: ["blacklist"], + queryFn: async () => { + console.log("fetching blacklist"); + const newBlacklist = {}; + // Fetch blacklist + const querySnapshot = await getDocs( + collection(db, "teams", currentTeamId, "blacklist"), + ); + querySnapshot.forEach((doc) => { + newBlacklist[doc.id] = doc.data(); + }); + return newBlacklist; + }, + enabled, + }); + + return { + data, + error, + isLoading, + }; +}; From 2589d27347e1f93b63dda20356ba9b1056ffe0ae Mon Sep 17 00:00:00 2001 From: Frank Nguyen <41023671+FrankreedX@users.noreply.github.com> Date: Thu, 15 Aug 2024 20:00:46 +0700 Subject: [PATCH 3/3] IWB-2: added blacklist management functionality (#310) * added blacklist hook * black list feature works * some unused stuff removal * simplified removeBlacklist.js * removed transaction and hope that it works * fixed useBlackList.js hook firestore error, and made blacklist check functional * added refresh spinner for chooseTeam.js * kinda works lmao * minor comment change Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * changed console log wording in removeBlacklist Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * removed copied over comment * fix - added email to blacklist record * fix - added assertion if pfp exists when removing a user * fixed "invalid-argument" * added key * removed redundant remove user fix * pretty * added missing state from merge * simple fix --------- Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> Co-authored-by: Jake Gehrke --- app/content/team/index.js | 88 +++++++++-------- app/segments/(team)/blacklist.js | 72 ++++++++++++++ app/segments/(team)/manageForeignRequests.js | 99 ++++++++++++++++++++ dbOperations/removeBlacklist.js | 13 +++ update_unique.py | 32 ++++--- 5 files changed, 252 insertions(+), 52 deletions(-) create mode 100644 app/segments/(team)/blacklist.js create mode 100644 app/segments/(team)/manageForeignRequests.js create mode 100644 dbOperations/removeBlacklist.js diff --git a/app/content/team/index.js b/app/content/team/index.js index 589c73e8..6ae0b7dc 100644 --- a/app/content/team/index.js +++ b/app/content/team/index.js @@ -244,48 +244,62 @@ function Index() {
{ - setMenuVisible(false); - }} - anchor={ - { - setMenuVisible(true); - }} - color={themeColors.accent} - /> - } - statusBarHeight={45} - anchorPosition="bottom" - contentStyle={{ - backgroundColor: themeColors.background, - }} - > - + {currentUserInfo.role === "coach" || + currentUserInfo.role === "owner" ? ( + { - bottomSheetModalRef.current?.present(); - setMenuVisible(false); + router.push("/segments/(team)/manageForeignRequests"); }} - title="Edit Team" + color={themeColors.accent} /> - { - console.log("Reset Season Pressed!"); + ) : ( + <> + )} + {currentUserInfo.role === "owner" ? ( + { setMenuVisible(false); - setResetDialogVisible(true); }} - title="Reset Season" - /> - - ) : ( - <> - ) + anchor={ + { + setMenuVisible(true); + }} + color={themeColors.accent} + /> + } + statusBarHeight={45} + anchorPosition="bottom" + contentStyle={{ + backgroundColor: themeColors.background, + }} + > + { + bottomSheetModalRef.current?.present(); + setMenuVisible(false); + }} + title="Edit Team" + /> + { + console.log("Reset Season Pressed!"); + setMenuVisible(false); + setResetDialogVisible(true); + }} + title="Reset Season" + /> + + ) : ( + <> + )} + } /> ; + + if (blacklistError) return ; + + return ( + } + > + + {Object.keys(blacklist).map((userId) => { + return ( + ( + + + + )} + /> + ); + })} + + + ); +} + +export default Blacklist; diff --git a/app/segments/(team)/manageForeignRequests.js b/app/segments/(team)/manageForeignRequests.js new file mode 100644 index 00000000..89da5618 --- /dev/null +++ b/app/segments/(team)/manageForeignRequests.js @@ -0,0 +1,99 @@ +import { useNavigation } from "expo-router"; +import { useMemo, useState } from "react"; +import { Appbar, SegmentedButtons } from "react-native-paper"; +import { SafeAreaView } from "react-native-safe-area-context"; +import { themeColors } from "~/Constants"; +import Blacklist from "~/app/segments/(team)/blacklist"; +import Header from "~/components/header"; + +function ManageForeignRequests() { + const [tabValue, setTabValue] = useState("invites"); + const navigation = useNavigation(); + + const segmentedColor = (tab) => { + switch (tab) { + case "invites": + return "#008001"; + case "waitlist": + return "#FFE900"; + case "blacklist": + return "#FE0100"; + default: + return themeColors.overlay; + } + }; + + const segmentedTextColor = (tab) => { + switch (tab) { + case "invites": + case "blacklist": + return "white"; + case "waitlist": + return "black"; + default: + return "black"; + } + }; + + const tabComponent = useMemo( + () => ({ + invites: <>, + waitlist: <>, + blacklist: , + }), + [], + ); + + return ( + +
{ + navigation.goBack(); + }} + color={themeColors.accent} + /> + } + /> + + {tabComponent[tabValue]} + + ); +} + +export default ManageForeignRequests; diff --git a/dbOperations/removeBlacklist.js b/dbOperations/removeBlacklist.js new file mode 100644 index 00000000..1a69eea7 --- /dev/null +++ b/dbOperations/removeBlacklist.js @@ -0,0 +1,13 @@ +import { deleteDoc, doc } from "firebase/firestore"; +import { db } from "~/firebaseConfig"; + +async function removeBlacklist(teamId, userId) { + try { + await deleteDoc(doc(db, "teams", teamId, "blacklist", userId)); + } catch (e) { + console.log("Remove User from Blacklist failed: ", e); + throw e; // Rethrow the error to handle it at the caller's level if needed + } +} + +module.exports = { removeBlacklist }; diff --git a/update_unique.py b/update_unique.py index 622f9ab8..3c7e5839 100644 --- a/update_unique.py +++ b/update_unique.py @@ -4,24 +4,26 @@ app = firebase_admin.initialize_app() db = firestore.client() -drillInfoRef = db.collection("teams").document("1").collection("drills") -userInfoRef = db.collection("teams").document("1").collection("users") -attemptsRef = db.collection("teams").document("1").collection("attempts") +blacklistRef = db.collection("teams").document("1").collection("blacklist") -newBestAttempts = {} # reset leaderboard -drills = [drill.to_dict() for drill in drillInfoRef.stream()] -users = [user.to_dict() for user in userInfoRef.stream()] -attempts = [attempt.to_dict() for attempt in attemptsRef.stream()] +blacklist = [user for user in blacklistRef.stream()] -userUniqueDrills = {} +for user in blacklist: + userInfoRef = db.collection("users").document(user.id) -for attempt in attempts: - if attempt["uid"] not in userUniqueDrills: - userUniqueDrills[attempt["uid"]] = set() - userUniqueDrills[attempt["uid"]].add(attempt["did"]) + blacklistEntryRef = blacklistRef.document(user.id) + blacklistEntryRef.update({"email": userInfoRef.get().to_dict()["email"]}) + + print(userInfoRef.get().to_dict()["email"]) -for user in users: - userRef = db.collection("teams").document("1").collection("users").document(user["uid"]) - userRef.update({"uniqueDrills": list(userUniqueDrills.get(user["uid"], set()))}) \ No newline at end of file + +# for attempt in attempts: +# if attempt["uid"] not in userUniqueDrills: +# userUniqueDrills[attempt["uid"]] = set() +# userUniqueDrills[attempt["uid"]].add(attempt["did"]) + +# for user in users: +# userRef = db.collection("teams").document("1").collection("users").document(user["uid"]) +# userRef.update({"uniqueDrills": list(userUniqueDrills.get(user["uid"], set()))}) \ No newline at end of file