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

Typed Redux! #655

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"dependencies": {
"@apollo/client": "^3.2.5",
"@types/object-hash": "^3.0.5",
"axios": "^1.2.6",
"bootstrap": "^4.5.2",
"color": "^3.1.3",
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/Berkeleytime.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IconoirProvider } from 'iconoir-react';
import { memo, useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { openBanner, enterMobile, exitMobile, openLandingModal } from './redux/common/actions';
import useDimensions from 'react-cool-dimensions';
import { useDispatch } from 'react-redux';
import { fetchEnrollContext } from 'redux/enrollment/actions';
import easterEgg from 'utils/easterEgg';
import Routes from './Routes';
import { fetchEnrollContext } from 'redux/actions';
import { IconoirProvider } from 'iconoir-react';
import { enterMobile, exitMobile, openBanner, openLandingModal } from './redux/common/actions';

const Berkeleytime = () => {
const dispatch = useDispatch();
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const RemoteScheduler = () => import('./app/Scheduler/RemoteSchedulerPage');
const ViewSchedule = () => import('./app/Scheduler/ViewSchedule');
const PrivacyPolicy = () => import('./views/PrivacyPolicy');
const TermsOfService = () => import('./views/TermsOfService');
const RedirectLink = () => import('./views/RedirectLink');
// const Apply = () => import('./views/Apply');

function ScheduleRedirect() {
Expand Down Expand Up @@ -48,8 +47,7 @@ const router = createBrowserRouter([
{ path: '/schedule/:scheduleId', lazy: ViewSchedule },
{ path: '/error', Component: Error },
{ path: '/legal/privacy', lazy: PrivacyPolicy },
{ path: '/legal/terms', lazy: TermsOfService },
{ path: '/redirect', lazy: RedirectLink },
{ path: '/legal/terms', lazy: TermsOfService }
// { path: '/apply', lazy: Apply }
]
},
Expand Down
25 changes: 11 additions & 14 deletions frontend/src/app/Enrollment/index.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { useLocation, useNavigate } from 'react-router-dom';

import { useCallback, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useLocation, useNavigate } from 'react-router-dom';
import {
enrollRemoveCourse,
enrollReset,
fetchEnrollClass,
fetchEnrollContext,
fetchEnrollFromUrl
} from 'redux/enrollment/actions';
import info from '../../assets/img/images/graphs/info.svg';
import ClassCardList from '../../components/ClassCards/ClassCardList';
import EnrollmentGraphCard from '../../components/GraphCard/EnrollmentGraphCard';
import EnrollmentSearchBar from '../../components/ClassSearchBar/EnrollmentSearchBar';

import info from '../../assets/img/images/graphs/info.svg';

import {
fetchEnrollContext,
fetchEnrollClass,
enrollRemoveCourse,
enrollReset,
fetchEnrollFromUrl
} from '../../redux/actions';
import { useCallback, useEffect, useState } from 'react';
import EnrollmentGraphCard from '../../components/GraphCard/EnrollmentGraphCard';

const toUrlForm = (s) => {
return s.toLowerCase().split(' ').join('-');
Expand Down
23 changes: 10 additions & 13 deletions frontend/src/app/Grades/index.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { useCallback, useEffect, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';

import { useDispatch, useSelector } from 'react-redux';
import { useLocation, useNavigate } from 'react-router-dom';
import {
fetchGradeClass,
fetchGradeContext,
fetchGradeFromUrl,
gradeRemoveCourse,
gradeReset
} from 'redux/grades/actions';
import info from '../../assets/img/images/graphs/info.svg';
import ClassCardList from '../../components/ClassCards/ClassCardList';
import GradesGraphCard from '../../components/GraphCard/GradesGraphCard';
import GradesSearchBar from '../../components/ClassSearchBar/GradesSearchBar';

import info from '../../assets/img/images/graphs/info.svg';

import {
fetchGradeContext,
fetchGradeClass,
gradeRemoveCourse,
gradeReset,
fetchGradeFromUrl
} from '../../redux/actions';
import GradesGraphCard from '../../components/GraphCard/GradesGraphCard';

const toUrlForm = (s) => {
s = s.replace('/', '_');
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/ClassCards/ClassCardList.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Container, Row } from 'react-bootstrap';

import colors from 'utils/colors';
import ClassCard from './ClassCard';
import vars from '../../utils/variables';

export default function ClassCardList({
selectedCourses,
Expand All @@ -19,7 +18,7 @@ export default function ClassCardList({
id={item.id}
course={item.course}
title={item.title}
fill={vars.colors[item.colorId]}
fill={colors[item.colorId]}
semester={item.semester === 'all' ? 'All Semesters' : item.semester}
faculty={item.instructor === 'all' ? 'All Instructors' : item.instructor}
removeCourse={removeCourse}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { Container, Row, Col, Button } from 'react-bootstrap';
import hash from 'object-hash';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { Button, Col, Container, Row } from 'react-bootstrap';

import { fetchEnrollSelected } from '../../redux/actions';
import { useDispatch, useSelector } from 'react-redux';
import BTSelect from 'components/Custom/Select';
import { useDispatch, useSelector } from 'react-redux';
import { fetchEnrollSelected } from 'redux/enrollment/actions';

const buildCoursesOptions = (courses) => {
if (!courses) {
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/components/ClassSearchBar/GradesSearchBar.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { Container, Row, Col, Button } from 'react-bootstrap';
import BTSelect from 'components/Custom/Select';
import hash from 'object-hash';

import { useCallback, useEffect, useMemo, useState } from 'react';
import { Button, Col, Container, Row } from 'react-bootstrap';
import { useDispatch, useSelector } from 'react-redux';

import { fetchGradeSelected } from '../../redux/actions';
import BTSelect from 'components/Custom/Select';
import { fetchGradeSelected } from 'redux/grades/actions';

const sortOptions = [
{ value: 'instructor', label: 'By Instructor' },
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/components/Common/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useSelector, useDispatch } from 'react-redux';
import { Button } from 'bt/custom';
import { closeBanner } from '../../redux/common/actions';

import close from '../../assets/svg/common/close.svg';
import { useDispatch, useSelector } from 'react-redux';
import { closeBanner } from 'redux/common/actions';
import { ReduxState } from 'redux/store';
import close from '../../assets/svg/common/close.svg';

export default function Banner() {
const { banner } = useSelector((state: ReduxState) => state.common);
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/components/Common/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export default function Footer() {
<A href="https://discord.gg/uP2bTPh99U" className="mb-2">
Discord
</A>
<A href="https://facebook.com/berkeleytime" className="mb-2">
Facebook
</A>
</div>
</div>
</Col>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-disable */
import { CurrentScheduleProps } from './type';

function CurrentSchedule({ current }) {
/**
* @audit this file is not used
*/
function CurrentSchedule({ current }: CurrentScheduleProps) {
return (
<div className="card dashboard-card">
<div className="dashboard-container">
Expand All @@ -10,7 +13,7 @@ function CurrentSchedule({ current }) {
<div className="dashboard-schedule-list">
<h5>{current.semester}</h5>
{current.classes.map((currentClass) => (
<p>
<p key={currentClass.name}>
{currentClass.name} <span>{currentClass.units} Units</span>
</p>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
/* eslint-disable */
import { PastScheduleProps } from './type';

function PastSchedule({ past }) {
/**
* @audit this file is not used
*/
function PastSchedule({ past }: PastScheduleProps) {
return (
<div className="card dashboard-card">
<div className="dashboard-container">
<h4 className="dashboard-card-title">
<b>Past Semesters</b>
</h4>
{past.map((semester) => (
<div className="dashboard-schedule-list">
<div className="dashboard-schedule-list" key={semester.semester}>
<h5>{semester.semester}</h5>
{semester.classes.map((pastClass) => (
<p>
<p key={pastClass.name}>
{pastClass.name} <span>{pastClass.units} Units</span>
</p>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable */

import jemma from 'assets/img/about/2020-21/michael_1.jpg';
import { ProfileProps } from './type';

function Profile({ profile }) {
/**
* @audit this file is not used
*/
function Profile({ profile }: ProfileProps) {
return (
<div className="card dashboard-card">
<div className="dashboard-container">
Expand All @@ -16,7 +18,7 @@ function Profile({ profile }) {
<div className="dashboard-profile-info-section">
<h4>Major(s)</h4>
{profile.majors.map((major) => (
<p>{major}</p>
<p key={major}>{major}</p>
))}
</div>
<div className="dashboard-profile-info-section">
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/components/Dashboard/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type CurrentScheduleProps = {
current: ScheduleSemesterType;
};

export type PastScheduleProps = {
past: ScheduleSemesterType[];
};

export type ProfileProps = {
profile: { name: string; pic: string; majors: string[]; academic_career: string; level: string };
};

export type ScheduleSemesterType = {
semester: string;
classes: { name: string; units: number }[];
};
13 changes: 5 additions & 8 deletions frontend/src/components/GraphCard/EnrollmentGraphCard.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { Container, Row, Col } from 'react-bootstrap';

import { Col, Container, Row } from 'react-bootstrap';
import { useDispatch, useSelector } from 'react-redux';
import vars from '../../utils/variables';

import { fetchEnrollData } from 'redux/enrollment/actions';
import colors from 'utils/colors.ts';
import EnrollmentInfoCard from '../EnrollmentInfoCard/EnrollmentInfoCard.jsx';
import EnrollmentGraph from '../Graphs/EnrollmentGraph.jsx';
import GraphEmpty from '../Graphs/GraphEmpty.jsx';
import EnrollmentInfoCard from '../EnrollmentInfoCard/EnrollmentInfoCard.jsx';

import { fetchEnrollData } from '../../redux/actions';

export default function EnrollmentGraphCard({ isMobile, updateClassCardEnrollment }) {
const [hoveredClass, setHoveredClass] = useState(false);
Expand Down Expand Up @@ -144,7 +141,7 @@ export default function EnrollmentGraphCard({ isMobile, updateClassCardEnrollmen
}
todayPoint={hoveredClass.data[hoveredClass.data.length - 1]}
telebears={telebears}
color={vars.colors[hoveredClass.colorId]}
color={colors[hoveredClass.colorId]}
enrolledMax={hoveredClass.enrolled_max}
waitlistedMax={hoveredClass.waitlisted_max}
/>
Expand Down
15 changes: 6 additions & 9 deletions frontend/src/components/GraphCard/GradesGraphCard.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { Container, Row, Col } from 'react-bootstrap';

import { Col, Container, Row } from 'react-bootstrap';
import { useDispatch, useSelector } from 'react-redux';
import vars from '../../utils/variables';

import { fetchGradeData } from 'redux/grades/actions';
import colors from 'utils/colors';
import GradesInfoCard from '../GradesInfoCard/GradesInfoCard';
import GradesGraph from '../Graphs/GradesGraph';
import GraphEmpty from '../Graphs/GraphEmpty';
import GradesInfoCard from '../GradesInfoCard/GradesInfoCard';

import { fetchGradeData } from '../../redux/actions';

export default function GradesGraphCard({ isMobile, updateClassCardGrade }) {
const { gradesData, graphData, selectedCourses } = useSelector((state) => state.grade);
Expand Down Expand Up @@ -117,7 +114,7 @@ export default function GradesGraphCard({ isMobile, updateClassCardGrade }) {
}
selectedPercentiles={hoveredClass[hoveredClass.hoverGrade]}
denominator={hoveredClass.denominator}
color={vars.colors[hoveredClass.colorId]}
color={colors[hoveredClass.colorId]}
isMobile={isMobile}
graphEmpty={graphEmpty}
/>
Expand Down Expand Up @@ -153,7 +150,7 @@ export default function GradesGraphCard({ isMobile, updateClassCardGrade }) {
denominator={hoveredClass.denominator}
selectedPercentiles={hoveredClass[hoveredClass.hoverGrade]}
selectedGrade={hoveredClass.hoverGrade}
color={vars.colors[hoveredClass.colorId]}
color={colors[hoveredClass.colorId]}
/>
)}
</Col>
Expand Down
23 changes: 11 additions & 12 deletions frontend/src/components/Graphs/EnrollmentGraph.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import {
LineChart,
XAxis,
YAxis,
Tooltip,
Line,
Legend,
ReferenceLine,
Label,
ResponsiveContainer
Label,
Legend,
Line,
LineChart,
ReferenceLine,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis
} from 'recharts';

import vars from '../../utils/variables';
import colors from 'utils/colors';
import emptyImage from '../../assets/img/images/graphs/empty.svg';

const EmptyLabel = (props) => {
Expand Down Expand Up @@ -95,7 +94,7 @@ export default function EnrollmentGraph({
name={`${item.title} • ${item.section_name}`}
type="monotone"
dataKey={item.id}
stroke={vars.colors[item.colorId]}
stroke={colors[item.colorId]}
strokeWidth={3}
dot={false}
activeDot={{ onMouseOver: updateLineHover }}
Expand Down
11 changes: 5 additions & 6 deletions frontend/src/components/Graphs/GradesGraph.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { BarChart, Bar, XAxis, YAxis, Tooltip, Legend, ResponsiveContainer } from 'recharts';
import { percentileToString } from '../../utils/utils';

import vars from '../../utils/variables';
import { Bar, BarChart, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
import colors from 'utils/colors';
import emptyImage from '../../assets/img/images/graphs/empty.svg';
import { percentileToString } from '../../utils/utils';

const EmptyLabel = (props) => {
return (
Expand Down Expand Up @@ -99,7 +98,7 @@ export default function GradesGraph({
key={i}
name={`${item.title} • ${item.semester} • ${item.instructor}`}
dataKey={item.id}
fill={vars.colors[item.colorId]}
fill={colors[item.colorId]}
onMouseEnter={updateBarHover}
radius={[4, 4, 0, 0]}
/>
Expand Down Expand Up @@ -143,7 +142,7 @@ export default function GradesGraph({
key={i}
name={`${item.title} • ${item.semester} • ${item.instructor}`}
dataKey={item.id}
fill={vars.colors[item.colorId]}
fill={colors[item.colorId]}
onMouseEnter={updateBarHover}
label={<PercentageLabel />}
radius={[0, 4, 4, 0]}
Expand Down
Loading