Skip to content

Commit

Permalink
partial fix for getCurrentActivity + findCurrentActivity so easier fo…
Browse files Browse the repository at this point in the history
…r future subcom to continue
  • Loading branch information
Shzmj committed Nov 15, 2024
1 parent ce67f1b commit 816438a
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 163 deletions.
2 changes: 1 addition & 1 deletion client/src/api/getCourseInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,4 @@ const getCourseInfo = async (
}
};

export default getCourseInfo;
export default getCourseInfo;
1 change: 0 additions & 1 deletion client/src/components/friends/ActivityBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { styled } from '@mui/system';
import React from 'react';

import FriendsActivity from './FriendsActivity';

Expand Down
3 changes: 1 addition & 2 deletions client/src/components/friends/Friends.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import styled from '@emotion/styled';
import React, { useContext } from 'react';
import { useContext } from 'react';

import { unknownErrorMessage } from '../../constants/timetable';
import { AppContext } from '../../context/AppContext';
import { CourseContext } from '../../context/CourseContext';
import { UserContext } from '../../context/UserContext';
import { ClassData } from '../../interfaces/Periods';
import Timetable from '../timetable/Timetable';
import ActivityBar from './ActivityBar';
import GroupInfoNavbar from './GroupInfoNavbar';

const Container = styled('div')`
Expand Down
163 changes: 54 additions & 109 deletions client/src/components/friends/FriendsActivity.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { styled } from '@mui/system';
import React, { useContext, useEffect } from 'react';
import { useContext, useEffect } from 'react';

import { API_URL } from '../../api/config';
import getCourseInfo from '../../api/getCourseInfo';
import { getAvailableTermDetails } from '../../constants/timetable';
import { UserContext } from '../../context/UserContext';
import NetworkError from '../../interfaces/NetworkError';
import {
ClassPeriod,
CourseCode,
CourseData,
EventPeriod,
ScrapedClassDTO,
SelectedClasses,
} from '../../interfaces/Periods';
import timeoutPromise from '../../utils/timeoutPromise';



const Container = styled('div')`
display: flex;
Expand Down Expand Up @@ -78,6 +68,17 @@ const UserProfile = styled('div')`
background-color: white;
`;

/*
TODO: tldr just need to fix getCurrentActivity and findCurrentActivity to return a useful object like the below from the database timetable object
export type CurrentActivity = {
friendName: string;
activityTitle: string; // i.e. in a [activity] tutorial
location: string; // so this will be `[course_code] at [room location]`
time_slot: string; // i.e. 12:00 - 14:00
};
^ or if its a custom event then minor changes based on the event info
*/

////////////////////////////////////////////////////// CHANEL'S BE STUFF //////////////////////////////////////////////////////
export interface Friend {
name: string;
Expand All @@ -89,13 +90,13 @@ export interface Friend {
export type FriendsList = Friend[];

export type CurrentActivity = {
type: 'class' | 'event';
start: Date;
end: Date;
friendName: string;
activityTitle: string; // i.e. in a [activity] tutorial
location: string; // so this will be `[course_code] at [room location]`
time_slot: string; // i.e. 12:00 - 14:00
};

const getCurrentActivity = async (userId: string): Promise<CurrentActivity | null> => {
// get the user's timetable data
try {
const res = await fetch(`${API_URL.server}/user/timetable/${userId}`, {
method: 'GET',
Expand All @@ -104,101 +105,33 @@ const getCurrentActivity = async (userId: string): Promise<CurrentActivity | nul
'Content-Type': 'application/json',
},
});
if (res.status !== 200) throw new NetworkError("Couldn't get response");

const friendTimetablesStatus = await res.json();
const friendTimetables = friendTimetablesStatus.data;

if (friendTimetables.length === 0) {
return null;
if (!res.ok) {
throw new Error('Failed to fetch timetable data');
}

const mainTimetable = friendTimetables[0];
/*
TODO: tldr just need to fix getCurrentActivity and findCurrentActivity to return a useful object like the below from the database timetable object
export type CurrentActivity = {
friendName: string;
activityTitle: string; // i.e. in a [activity] tutorial
location: string; // so this will be `[course_code] at [room location]`
time_slot: string; // i.e. 12:00 - 14:00
};
^ or if its a custom event then minor changes based on the event info
*/

// const classesList: ClassPeriod[] = mainTimetable.selectedClasses.map((classDTO: any) => {
// return {
// type: 'class',
// classId: classDTO.classID,
// courseCode: classDTO.courseCode,
// activity: classDTO.activity,
// subActivity: classDTO.subActivity,
// time: classDTO.time,
// locations: classDTO.locations,
// };
// });

// console.log('classeslIST', classesList);

// const eventsList: EventPeriod[] = mainTimetable.createdEvents.map((eventDTO: any) => {
// return {
// type: 'event',
// subtype: eventDTO.subtype,
// time: {
// day: eventDTO.day,
// start: eventDTO.start,
// end: eventDTO.end,
// },
// event: {
// id: eventDTO.id,
// name: eventDTO.name,
// location: eventDTO.location,
// description: eventDTO.description || '',
// color: eventDTO.colour,
// },
// };
// });
// console.log('eventsList', eventsList);

return findCurrentActivity(mainTimetable.selectedClasses, mainTimetable.createdEvents, new Date());
const timetable = await res.json();
// Currently we only consider the first timetable as the main
return findCurrentActivity(timetable.data[0]);
} catch (error) {
console.log('error', error);
throw new NetworkError('Could not connect to server');
console.error('Error fetching current activity:', error);
return null;
}
};

/*
TODO: tldr just need to fix getCurrentActivity and findCurrentActivity to return a useful object like the below from the database timetable object
export type CurrentActivity = {
friendName: string;
activityTitle: string; // i.e. in a [activity] tutorial
location: string; // so this will be `[course_code] at [room location]`
time_slot: string; // i.e. 12:00 - 14:00
};
^ or if its a custom event then minor changes based on the event info
*/

const findCurrentActivity = (courseInfos: CourseData[], events: EventPeriod[], now: Date): CurrentActivity | null => {
for (const courseInfo of courseInfos) {
for (const courseClass of Object.values(courseInfo.activities)) {
for (const classData of courseClass) {
for (const period of classData.periods) {
const classStart = new Date(period.time.start);
const classEnd = new Date(period.time.end);

if (classStart <= now && now <= classEnd) {
return { ...courseClass, type: 'class', start: classStart, end: classEnd } as CurrentActivity;
}
}
}
}
}

for (const event of events) {
const eventStart = new Date(event.time.start);
const eventEnd = new Date(event.time.end);

if (eventStart <= now && now <= eventEnd) {
return { ...event, type: 'event', start: eventStart, end: eventEnd } as CurrentActivity;
const findCurrentActivity = (timetable: any): CurrentActivity | null => {
const now = new Date();
const currentDay = now.toLocaleString('en-US', { weekday: 'long' }).slice(0, 3);
const currentTime = now.toTimeString().split(' ')[0].slice(0, 5);

for (const clz of timetable.selectedClasses) {
if (clz.times.day === currentDay && clz.times.time.start <= currentTime && clz.times.time.end >= currentTime) {
return {
friendName: timetable.friendName,
activityTitle: `in a ${clz.activity} tutorial`,
location: `${clz.courseCode} at ${clz.times.location}`,
time_slot: `${clz.times.time.start} - ${clz.times.time.end}`,
};
}
}

Expand All @@ -210,7 +143,7 @@ const FriendsActivity = () => {
const { user } = useContext(UserContext);

useEffect(() => {
// TODO: fix this integration here
// TODO: fix this integration here and store friend activity in state...
const dosomething = async () => {
for (const friend of user.friends) {
console.log('friend', friend);
Expand All @@ -227,7 +160,7 @@ const FriendsActivity = () => {
<UserDetailsContainer>
<UserProfile />
<TextContainer>
<UserNameText>Rayian Ahmed</UserNameText>
<UserNameText>Raiyan Ahmed</UserNameText>
<UserActivity>Currently teaching</UserActivity>
</TextContainer>
</UserDetailsContainer>
Expand All @@ -240,15 +173,27 @@ const FriendsActivity = () => {
<UserDetailsContainer>
<UserProfile />
<TextContainer>
<UserNameText>Rayian Ahmed</UserNameText>
<UserNameText>Shaam Jevan</UserNameText>
<UserActivity>Currently teaching</UserActivity>
</TextContainer>
</UserDetailsContainer>
<ClassLocationContainer>
<Location>COMP1531 at TablaK17G7</Location>
<Location>COMP3121 at DA_BASEMENT</Location>
<ClassTime>14:00 - 16:00</ClassTime>
</ClassLocationContainer>
</FriendContainer>
<FriendContainer>
<UserDetailsContainer>
<UserProfile />
<TextContainer>
<UserNameText>Jeremy Le</UserNameText>
<UserActivity>Chilln</UserActivity>
</TextContainer>
</UserDetailsContainer>
<ClassLocationContainer>
<Location>Ainsworth L3</Location>
</ClassLocationContainer>
</FriendContainer>
</Container>
);
};
Expand Down
3 changes: 1 addition & 2 deletions client/src/components/friends/FriendsTimetable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { contentPadding, inventoryMargin } from '../../constants/theme';
import { timetableWidth } from '../../constants/timetable';
import { AppContext } from '../../context/AppContext';
import { EventPeriod } from '../../interfaces/Periods';
import { TimetableLayout } from '../timetable/TimetableLayout';
import ActivityBar from './ActivityBar';

const StyledTimetable = styled(Box, {
Expand Down Expand Up @@ -68,7 +67,7 @@ const FriendsTimetable: React.FC = () => {
<StyledTimetable cols={days.length} rows={numRows}>
<TimetableContainer>
<Timetable></Timetable>
{/* <TimetableLayout copiedEvent={copiedEvent} setCopiedEvent={setCopiedEvent} /> */}
{/* <TimetableLayout copiedEvent={copiedEvent} setCopiedEvent={setCopiedEvent} /> */}
<ActivityBar />
</TimetableContainer>
</StyledTimetable>
Expand Down
3 changes: 1 addition & 2 deletions client/src/components/friends/GroupInfoNavbar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import styled from '@emotion/styled';
import { ConnectWithoutContact as FriendsActivityIcon } from '@mui/icons-material';
import { IconButton, Tooltip } from '@mui/material';
import React, { useContext, useState } from 'react';
import { useContext, useState } from 'react';

import { UserContext } from '../../context/UserContext';
import UserIcon from '../user/UserIcon';
import ActivityBar from './ActivityBar';
import { Group } from '../../interfaces/Group';

const Container = styled('div')`
position: fixed;
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/landingPage/flip-words.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import { AnimatePresence,motion } from 'framer-motion';
import { AnimatePresence, motion } from 'framer-motion';
import { useCallback, useEffect, useState } from 'react';

import { cn } from '../../lib/utils';
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/sidebar/CustomModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Close } from '@mui/icons-material';
import { Dialog, DialogContent, DialogTitle, Divider, IconButton, Tooltip, Typography } from '@mui/material';
import { styled } from '@mui/system';
import React from 'react';
import { useNavigate } from 'react-router-dom';

import { CustomModalProps } from '../../interfaces/PropTypes';
import { useNavigate } from 'react-router-dom';

const StyledDialogTitle = styled(DialogTitle)`
background-color: ${({ theme }) => theme.palette.background.paper};
Expand Down Expand Up @@ -57,7 +57,7 @@ const CustomModal: React.FC<CustomModalProps> = ({
const navigate = useNavigate();

const toggleIsOpen = () => {
setIsOpen(!isOpen);
setIsOpen(!isOpen);
};

const handleClick = () => {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/user/UserIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ const UserIcon: React.FC<UserIconProps> = ({ url, size, tooltipTitle }) => {
);
};

export default UserIcon;
export default UserIcon;
4 changes: 1 addition & 3 deletions client/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import '@fontsource-variable/roboto-flex';
import './index.css';

import { ApolloProvider } from '@apollo/client';
import { BrowserTracing } from '@sentry/browser';
import * as Sentry from '@sentry/react';
import React from 'react';
import { createRoot } from 'react-dom/client';
import { BrowserRouter, Route, Routes } from 'react-router-dom';

import { client } from './api/config';
import App from './App';
import EventShareModal from './components/EventShareModal';
import LandingPage from './components/landingPage/LandingPage';
import Friends from './components/friends/Friends';
import LandingPage from './components/landingPage/LandingPage';
import AppContextProvider from './context/AppContext';
import CourseContextProvider from './context/CourseContext';
import UserContextProvider from './context/UserContext';
Expand Down
5 changes: 1 addition & 4 deletions client/src/utils/DbCourse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ const dbTimesToPeriod = (dbTimes: DbTimes, classData: ClassData, isConvertToLoca
* const json: DBCourse = await data.json()
* const courseInfo = dbCourseToCourseData(json)
*/
export const dbCourseToCourseData = (
dbCourse: DbCourse,
isConvertToLocalTimezone: boolean,
): CourseData => {
export const dbCourseToCourseData = (dbCourse: DbCourse, isConvertToLocalTimezone: boolean): CourseData => {
const courseData: CourseData = {
code: dbCourse.courseCode,
name: dbCourse.name,
Expand Down
2 changes: 1 addition & 1 deletion client/src/utils/syncTimetables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,4 @@ const runSync = (
}, 5000);
};

export { parseTimetableDTO, runSync };
export { parseTimetableDTO, runSync };
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.4.2",
"@prisma/client": "5.17.0",
"@prisma/client": "5.22.0",
"@quixo3/prisma-session-store": "^3.1.13",
"@types/express-session": "^1.18.0",
"class-transformer": "^0.5.1",
Expand Down Expand Up @@ -64,7 +64,7 @@
"grpc_tools_node_protoc_ts": "^5.3.3",
"jest": "^29.5.0",
"prettier": "^3.0.0",
"prisma": "5.17.0",
"prisma": "5.22.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
Expand Down
Loading

0 comments on commit 816438a

Please sign in to comment.