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] 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