Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IWB-2: added blacklist management functionality #292

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ac7e815
black list feature works
FrankreedX Jul 16, 2024
999af90
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Jul 16, 2024
9fa672f
some unused stuff removal
FrankreedX Jul 16, 2024
f5a1855
simplified removeBlacklist.js
FrankreedX Jul 19, 2024
4f5ac10
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Jul 21, 2024
6ac7af1
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Jul 21, 2024
52b16f8
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Jul 21, 2024
54469bf
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Jul 23, 2024
51e60d3
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Aug 2, 2024
5e1dc1b
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Aug 4, 2024
b3481a3
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Aug 4, 2024
1ae93ef
changed console log wording in removeBlacklist
FrankreedX Aug 4, 2024
f869cfb
removed copied over comment
FrankreedX Aug 4, 2024
30081f4
Merge remote-tracking branch 'origin/frankreed/foreignManagement2_bla…
FrankreedX Aug 4, 2024
a066201
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Aug 4, 2024
6c48415
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Aug 4, 2024
7619df3
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Aug 6, 2024
06c7b91
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Aug 7, 2024
c8d412e
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Aug 7, 2024
68aad1c
added key
FrankreedX Aug 7, 2024
fbee72c
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Aug 12, 2024
8951322
Merge branch 'frankreed/foreignManagement1_blacklist_hook' into frank…
FrankreedX Aug 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 51 additions & 37 deletions app/content/team/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,48 +244,62 @@ function Index() {
<Header
title={"Team"}
postChildren={
currentUserInfo.role === "owner" ? (
<Menu
visible={menuVisible}
onDismiss={() => {
setMenuVisible(false);
}}
anchor={
<Appbar.Action
icon="dots-horizontal-circle-outline"
onPress={() => {
setMenuVisible(true);
}}
color={themeColors.accent}
/>
}
statusBarHeight={45}
anchorPosition="bottom"
contentStyle={{
backgroundColor: themeColors.background,
}}
>
<Menu.Item
leadingIcon="pencil-outline"
<>
{currentUserInfo.role === "coach" ||
currentUserInfo.role === "owner" ? (
FrankreedX marked this conversation as resolved.
Show resolved Hide resolved
<Appbar.Action
icon="account-cog-outline"
onPress={() => {
bottomSheetModalRef.current?.present();
setMenuVisible(false);
router.push("/segments/(team)/manageForeignRequests");
}}
title="Edit Team"
color={themeColors.accent}
/>
<Menu.Item
leadingIcon="restart"
onPress={() => {
console.log("Reset Season Pressed!");
) : (
<></>
)}
{currentUserInfo.role === "owner" ? (
<Menu
visible={menuVisible}
onDismiss={() => {
setMenuVisible(false);
setResetDialogVisible(true);
}}
title="Reset Season"
/>
</Menu>
) : (
<></>
)
anchor={
<Appbar.Action
icon="dots-horizontal-circle-outline"
onPress={() => {
setMenuVisible(true);
}}
color={themeColors.accent}
/>
}
statusBarHeight={45}
anchorPosition="bottom"
contentStyle={{
backgroundColor: themeColors.background,
}}
>
<Menu.Item
leadingIcon="pencil-outline"
onPress={() => {
bottomSheetModalRef.current?.present();
setMenuVisible(false);
}}
title="Edit Team"
/>
<Menu.Item
leadingIcon="restart"
onPress={() => {
console.log("Reset Season Pressed!");
setMenuVisible(false);
setResetDialogVisible(true);
}}
title="Reset Season"
/>
</Menu>
) : (
<></>
)}
</>
}
/>
<BottomSheetWrapper
Expand Down
72 changes: 72 additions & 0 deletions app/segments/(team)/blacklist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { useQueryClient } from "@tanstack/react-query";
import { ScrollView, View } from "react-native";
import { Button, List } from "react-native-paper";
import { themeColors } from "~/Constants";
import ErrorComponent from "~/components/errorComponent";
import Loading from "~/components/loading";
import RefreshInvalidate from "~/components/refreshInvalidate";
import { useAuthContext } from "~/context/Auth";
import { useBlackList } from "~/dbOperations/hooks/useBlackList";
import { invalidateMultipleKeys } from "~/dbOperations/invalidateMultipleKeys";
import { removeBlacklist } from "~/dbOperations/removeBlacklist";

function Blacklist() {
const {
data: blacklist,
error: blacklistError,
isLoading: blacklistIsLoading,
} = useBlackList();

const { currentTeamId } = useAuthContext();

const queryClient = useQueryClient(); // also called here for updating name

const invalidateKeys = [["blacklist"]];

if (blacklistIsLoading) return <Loading />;

if (blacklistError) return <ErrorComponent errorList={[blacklistError]} />;

return (
<ScrollView
refreshControl={<RefreshInvalidate invalidateKeys={invalidateKeys} />}
>
<List.Section
style={{
margin: 5,
borderRadius: 5,
}}
>
{Object.keys(blacklist).map((userId) => {
return (
<List.Item
title={blacklist[userId].email}
key={userId}
right={() => (
<View
style={{
flexDirection: "row",
alignItems: "center",
paddingLeft: 10,
}}
>
<Button
onPress={async () => {
await removeBlacklist(currentTeamId, userId);
await invalidateMultipleKeys(queryClient, invalidateKeys);
}}
textColor={themeColors.accent}
>
Unban
</Button>
</View>
)}
/>
);
})}
</List.Section>
</ScrollView>
);
}

export default Blacklist;
99 changes: 99 additions & 0 deletions app/segments/(team)/manageForeignRequests.js
Original file line number Diff line number Diff line change
@@ -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: <Blacklist />,
}),
[],
);

return (
<SafeAreaView
style={{
flex: 1,
}}
>
<Header
title="Manage Foreign Requests"
preChildren={
<Appbar.BackAction
onPress={() => {
navigation.goBack();
}}
color={themeColors.accent}
/>
}
/>
<SegmentedButtons
value={tabValue}
onValueChange={setTabValue}
style={{
marginLeft: 10,
marginRight: 10,
backgroundColor: themeColors.highlight,
borderRadius: 20,
}}
theme={{
colors: {
secondaryContainer: segmentedColor(tabValue),
onSecondaryContainer: segmentedTextColor(tabValue),
},
}}
buttons={[
{
value: "invites",
label: "Invites",
},
{
value: "waitlist",
label: "Waitlist",
},
{
value: "blacklist",
label: "Blacklist",
},
]}
/>
{tabComponent[tabValue]}
</SafeAreaView>
);
}

export default ManageForeignRequests;
13 changes: 13 additions & 0 deletions dbOperations/removeBlacklist.js
Original file line number Diff line number Diff line change
@@ -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 };
32 changes: 17 additions & 15 deletions update_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))})

# 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()))})
Loading