Skip to content

Commit

Permalink
Merge pull request #149 from AarshShah9/Aarsh/Tags
Browse files Browse the repository at this point in the history
DRAFT
  • Loading branch information
JamesRobert20 authored Jun 5, 2024
2 parents 8a46531 + bfeb4ac commit 75bf768
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 37 deletions.
25 changes: 25 additions & 0 deletions backend/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,28 @@ export const defaultRolePermissions: Record<

// The radius to look for events around the user (institution)
export const defaultDistance = 75;

// Tags
export const tagMapping: Record<any, number> = {
Sports: 0,
Fitness: 1,
Culture: 2,
Theatre: 3,
Academic: 4,
Music: 5,
Community: 6,
Tech: 7,
Food: 8,
Wellness: 9,
Science: 10,
Business: 11,
Engineering: 12,
Art: 13,
Games: 14,
Social: 15,
Software: 16,
Mechanical: 17,
Electrical: 18,
Outdoors: 19,
Networking: 20,
};
8 changes: 8 additions & 0 deletions backend/controllers/notification.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const sendChatNotification = async (
select: {
firstName: true,
lastName: true,
id: true,
},
});
if (!user) {
Expand All @@ -165,6 +166,13 @@ export const sendChatNotification = async (
const pushNotification: SendPushNotificationProps = {
title: `${user.firstName} ${user.lastName}`,
body: message,
data: {
route: true,
routeName: "Messages",
routeParams: {
userId: recipientId,
},
},
};

// send the notification
Expand Down
77 changes: 77 additions & 0 deletions backend/controllers/tag.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { RequestExtended } from "../middleware/verifyAuth";
import { Response, NextFunction } from "express";
import prisma from "../prisma/client";
import { AppError, AppErrorName } from "../utils/AppError";

export const getAllTags = async (
req: RequestExtended,
res: Response,
next: NextFunction,
) => {
try {
const tags = await prisma.topic.findMany({
select: {
topicName: true,
},
});

if (!tags) {
throw new AppError(AppErrorName.NOT_FOUND_ERROR, "Tags not found", 404);
}

res.status(200).json({
data: { tags: tags.map((tag) => tag.topicName) },
message: "Tags fetched successfully",
});
} catch (error) {
next(error);
}
};

export const getUserSubscriptions = async (
req: RequestExtended,
res: Response,
next: NextFunction,
) => {
// modify during integration
const loggedInUserId = req.body.userId;
const user = await prisma.user.findUnique({
where: {
id: loggedInUserId,
},
include: {
subscriptions: {
include: {
topic: {
select: {
id: true,
topicName: true,
},
},
},
},
},
});

if (!user) {
throw new AppError(AppErrorName.NOT_FOUND_ERROR, "User not found", 404);
}

res.status(200).json({
topics: user.subscriptions.map((sub) => {
return {
id: sub.topic.id,
name: sub.topic.topicName,
};
}),
});
};

export const modifyUserTags = async (
req: RequestExtended,
res: Response,
next: NextFunction,
) => {
// modify during integration
const loggedInUserId = req.body.userId;
};
2 changes: 2 additions & 0 deletions backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import profile from "./routes/profile.routes";
import notification from "./routes/notification.routes";
import moderation from "./routes/moderation.routes";
import search from "./routes/search.routes";
import tag from "./routes/tag.routes";
import { validateEnv } from "./utils/validateEnv";
import { upcomingEventReminderTask } from "./utils/cronTasks";
import { initializeApp } from "firebase-admin/app";
Expand Down Expand Up @@ -78,6 +79,7 @@ app.use("/api/notification", notification);
app.use("/api/moderation", moderation);
app.use("/api/search", search);
app.use("/api/seed", seed);
app.use("/api/tags", tag);

app.get("/Test", (req: Request, res: Response) => {
console.log("The backend is hit");
Expand Down
16 changes: 16 additions & 0 deletions backend/routes/tag.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import express from "express";
import {
getAllTags,
modifyUserTags,
getUserSubscriptions,
} from "../controllers/tag.controller";
import { verifyAuthentication } from "../middleware/verifyAuth";

const router = express.Router();

router.use(verifyAuthentication);
router.get("/getAllTags", getAllTags);
router.get("/readUserTags", getUserSubscriptions);
router.post("/modifyUserTags", modifyUserTags);

export default router;
1 change: 0 additions & 1 deletion frontend/src/components/CommentsBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { View, StyleSheet, Image, TouchableOpacity } from "react-native";
import { Text } from "react-native-paper";
import ReplyChip from "./ReplyChip";
import { commentType } from "~/screens/LookingForCommentsScreen";
import { generateImageURL } from "~/lib/CDNFunctions";
import { convertUTCToTimeAndDate } from "~/lib/timeFunctions";
Expand Down
12 changes: 0 additions & 12 deletions frontend/src/components/ReusableStackScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { memo } from "react";
import { TouchableOpacity, Text } from "react-native";
import { Feather } from "@expo/vector-icons";
import useNavigationContext from "~/hooks/useNavigationContext";
import Interests from "~/screens/Interests";

const MapDetailsLeftHeader = () => {
const { navigateBack } = useNavigationContext();
Expand Down Expand Up @@ -53,17 +52,6 @@ function ReusableStackScreens({ name, component, options }: Props) {
return (
<Stack.Navigator>
<Stack.Screen name={name} component={component} options={options} />
<Stack.Screen
name={`Interests-${name}`}
component={Interests}
options={{
title: "",
headerShown: true,
headerBackTitle: "Back",
headerTintColor: theme.colors.onSecondary,
headerStyle: { backgroundColor: theme.colors.primary },
}}
/>
<Stack.Screen
name={`UserProfile-${name}`}
component={ProfilePage}
Expand Down
17 changes: 13 additions & 4 deletions frontend/src/contexts/authContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ type authContext = {
organization?: OrganizationDataType;
userType: UserType;
registerUser: (arg: userRegistrationData) => Promise<void>;
signIn: (email: string, password: string) => Promise<boolean | undefined>;
signIn: (
email: string,
password: string,
) => Promise<{ succeeded: boolean; user: UserDataType }>;
logOut: () => Promise<void>;
getInstitutions: () => Promise<any>;
setUser: React.Dispatch<React.SetStateAction<UserDataType | undefined>>;
Expand Down Expand Up @@ -127,12 +130,18 @@ export const AuthContextProvider = ({
setUser(loginRes.data);
} else {
Alert.alert("Error Logging In", "Something went wrong!");
return false;
return { succeeded: false, user: null };
}
return true;
return {
succeeded: true,
user: loginRes.data,
};
} catch (error) {
Alert.alert("Error Logging In", "Something went wrong!");
return false;
return {
succeeded: false,
user: null,
};
}
}, []);

Expand Down
11 changes: 5 additions & 6 deletions frontend/src/contexts/navigationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ export const NavigationContextProvider = ({
screen: page,
params,
});
} else {
let pageToRoute: string = page;
if (duplicatedScreens.includes(page as any)) {
pageToRoute = `${page}-${currentMainTab}`;
}
navigate(pageToRoute, { ...params });
} else {let pageToRoute: string = page;
if (duplicatedScreens.includes(page as any)) {
pageToRoute = `${page}-${currentMainTab}`;
}
navigate(pageToRoute, { ...params });
}
},
[navigate, currentMainTab],
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions frontend/src/hooks/usePushNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default function usePushNotifications(
const navigation = useNavigation<any>();
const onTap = (notification: Notifications.NotificationResponse) => {
onTapNotification?.(notification);
console.log("notification", notification.notification.request.content);
if (notification.notification.request.content.data?.route) {
switch (notification.notification.request.content.data.routeName) {
case "EventDetails":
Expand All @@ -97,6 +98,12 @@ export default function usePushNotifications(
.eventId,
});
break;
case "Messages":
navigation.navigate("ChatScreen", {
userId:
notification.notification.request.content.data.routeParams.userId,
});
break;
default:
break;
}
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/lib/apiFunctions/Profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,11 @@ export const deleteItem = async (id: string) => {
params: { id },
});
};

export const getAllTags = async () => {
try {
return (await CBRequest("GET", "/api/tags/getAllTags")).data;
} catch (err) {
console.log(err);
}
};
1 change: 1 addition & 0 deletions frontend/src/lib/requestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ const allowedEndpoints = [
"/api/notification/storePushToken",
"/api/notification/sendChatNotification",
"/api/search/",
"/api/tags/getAllTags",
] as const;

// Type alias for allowed endpoints to restrict function parameters to valid endpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ export default function ChatScreenHeader() {

return (
<View style={{ flexDirection: "row", alignItems: "center" }}>
<View style={styles.iconContainer}>
{icon ? (
<Image
style={{ width: "100%", height: "100%" }}
source={{ uri: icon }}
/>
) : (
<View
style={styles.iconContainer}>
{icon ? (
<Image
style={{ width: "100%", height: "100%" }}
source={{ uri: icon }}
/>
) : (
<MaterialIcons name="person" size={30} color="#333" />
)}
</View>
)}</View>
<ThemedText
style={[styles.userName, { color: theme.colors.onSecondary }]}
>
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import AuthenticationGroup from "./AuthenticationGroup";
import LandingGroup from "./LandingGroup";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { NavigationContextProvider } from "~/contexts/navigationContext";
import Interests from "~/screens/Interests";
import useAuthContext from "~/hooks/useAuthContext";

const Stack = createNativeStackNavigator();

Expand All @@ -22,6 +24,17 @@ export default function Navigation() {
name="AuthenticationGroup"
component={AuthenticationGroup}
/>
<Stack.Screen
name={"Interests"}
component={Interests}
options={{
title: "",
headerShown: true,
headerBackTitle: "Back",
headerTintColor: theme.colors.onSecondary,
headerStyle: { backgroundColor: theme.colors.primary },
}}
/>
<Stack.Screen name="LandingGroup" component={LandingGroup} />
</Stack.Navigator>
</NavigationContextProvider>
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/screens/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function Login() {
const { theme } = useThemeContext();
const { dismissKeyboard } = useAppContext();
const { navigateTo, replaceStackWith } = useNavigationContext();
const { signIn } = useAuthContext();
const { signIn, user } = useAuthContext();
const [isKeyboardVisible, setIsKeyboardVisible] = useState(false);
const [passwordVisible, setPasswordVisible] = useState(false);

Expand Down Expand Up @@ -72,9 +72,13 @@ export default function Login() {
data.password = "hashed-password1238";
}

signIn(data.email, data.password).then((succeeded) => {
if (succeeded) {
replaceStackWith("LandingGroup");
signIn(data.email, data.password).then((res) => {
if (res.succeeded) {
if (res.user.firstTimeLogin) {
replaceStackWith("Interests");
} else {
replaceStackWith("LandingGroup");
}
}
});
}, []);
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/types/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,5 @@ export type NavigableStacks =
| "AuthenticationGroup"
| "LandingGroup"
| "ConfirmEmail"
| "OrgCreationConfirmation";
| "OrgCreationConfirmation"
| "Interests";

0 comments on commit 75bf768

Please sign in to comment.