Skip to content

Commit

Permalink
Merge branch 'develop' into prefetch-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
TyHil authored Oct 5, 2023
2 parents c1197a6 + e2a6ec7 commit 399aa6b
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 166 deletions.
31 changes: 4 additions & 27 deletions components/common/ExpandableSearchGrid/expandableSearchGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import { CardContent } from '@mui/material';
import { SearchBar } from '../SearchBar/searchBar';
import React from 'react';
import { useRouter } from 'next/router';

type SearchQuery = {
prefix?: string;
number?: string;
professorName?: string;
sectionNumber?: string;
};
import SearchQuery from '../../../modules/SearchQuery/SearchQuery';
import searchQueryLabel from '../../../modules/searchQueryLabel/searchQueryLabel';
import searchQueryColors from '../../../modules/searchQueryColors/searchQueryColors';

type ExpandableSearchGridProps = {
onChange: Function;
Expand Down Expand Up @@ -80,7 +76,7 @@ export const ExpandableSearchGrid = ({
secondaryText={studentTotalFormatter(studentTotals[index])}
key={index}
index={index}
legendColor={colors[index]}
legendColor={searchQueryColors[index]}
onCloseButtonClicked={deleteSearchTerm}
/>
))}
Expand All @@ -107,23 +103,6 @@ function studentTotalFormatter(total: number) {
return total.toLocaleString('en-US') + ' grades';
}

function searchQueryLabel(query: SearchQuery): string {
let result = '';
if (query.prefix !== undefined) {
result += query.prefix;
}
if (query.number !== undefined) {
result += ' ' + query.number;
}
if (query.sectionNumber !== undefined) {
result += '.' + query.sectionNumber;
}
if (query.professorName !== undefined) {
result += ' ' + query.professorName;
}
return result.trim();
}

function parseURIEncodedSearchTerms(
encodedSearchTerms: string | string[] | undefined,
): SearchQuery[] {
Expand Down Expand Up @@ -194,5 +173,3 @@ function parseURIEncodedSearchTerm(encodedSearchTerm: string): SearchQuery {
return { professorName: encodedSearchTerm.trim() };
}
}

const colors = ['#eb5757', '#2d9cdb', '#499F68'];
2 changes: 1 addition & 1 deletion components/common/ProfessorCard/CardContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const CardContents: FC<CardContentProps> = (props: CardContentProps) => {
<Box
className="h-32 w-32 border-2 border-neutral-400 flex items-center justify-center my-4 md:mt-0 mb-8 text-5xl text-neutral-600 font-bold"
sx={{
backgroundColor: getColorForRating(5 - props.averageDifficulty),
backgroundColor: getColorForRating(6 - props.averageDifficulty),
}}
>
{props.averageDifficulty}
Expand Down
45 changes: 6 additions & 39 deletions components/common/SearchBar/searchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { Autocomplete, InputBase, InputAdornment } from '@mui/material';
import Popper from '@mui/material/Popper';
import { Box, Paper } from '@mui/material';
import { useEffect } from 'react';
import SearchQuery from '../../../modules/SearchQuery/SearchQuery';
import searchQueryLabel from '../../../modules/searchQueryLabel/searchQueryLabel';
import searchQueryEqual from '../../../modules/searchQueryEqual/searchQueryEqual';
// import { searchAutocomplete } from '../../autocomplete';

/**
Expand All @@ -17,13 +20,6 @@ type SearchProps = {
disabled?: boolean;
};

type SearchQuery = {
prefix?: string;
number?: string;
professorName?: string;
sectionNumber?: string;
};

/**
* This component returns a custom search bar component that makes use of the Material UI autocomplete component
* Sends a new search value to the parent component when the user selects it from the options list
Expand Down Expand Up @@ -141,21 +137,9 @@ export const SearchBar = (props: SearchProps) => {
</Box>
</li>
)}
isOptionEqualToValue={(option, value) => {
if (option.prefix !== value.prefix) {
return false;
}
if (option.professorName !== value.professorName) {
return false;
}
if (option.number !== value.number) {
return false;
}
if (option.sectionNumber !== value.sectionNumber) {
return false;
}
return true;
}}
isOptionEqualToValue={(option, value) =>
searchQueryEqual(option, value)
}
PopperComponent={(props) => {
return (
<Popper {...props} className="rounded-none" placement="bottom" />
Expand All @@ -179,20 +163,3 @@ export const SearchBar = (props: SearchProps) => {
SearchBar.defaultProps = {
disabled: true,
};

function searchQueryLabel(query: SearchQuery): string {
let result = '';
if (query.prefix !== undefined) {
result += query.prefix;
}
if (query.number !== undefined) {
result += ' ' + query.number;
}
if (query.sectionNumber !== undefined) {
result += '.' + query.sectionNumber;
}
if (query.professorName !== undefined) {
result += ' ' + query.professorName;
}
return result.trim();
}
26 changes: 2 additions & 24 deletions components/common/SplashPageSearchBar/splashPageSearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as React from 'react';
import { Search } from '@mui/icons-material';
import { Autocomplete, InputBase, InputAdornment } from '@mui/material';
import { useEffect } from 'react';
import SearchQuery from '../../../modules/SearchQuery/SearchQuery';
import searchQueryLabel from '../../../modules/searchQueryLabel/searchQueryLabel';
// import { searchAutocomplete } from '../../autocomplete';

/**
Expand All @@ -12,13 +14,6 @@ type SearchProps = {
disabled?: boolean;
};

type SearchQuery = {
prefix?: string;
number?: string;
professorName?: string;
sectionNumber?: string;
};

/**
* This component returns a custom search bar component that makes use of the Material UI autocomplete component
* Sends a new search value to the parent component when the user selects it from the options list
Expand Down Expand Up @@ -121,20 +116,3 @@ export const SplashPageSearchBar = (props: SearchProps) => {
SplashPageSearchBar.defaultProps = {
disabled: true,
};

function searchQueryLabel(query: SearchQuery): string {
let result = '';
if (query.prefix !== undefined) {
result += query.prefix;
}
if (query.number !== undefined) {
result += ' ' + query.number;
}
if (query.sectionNumber !== undefined) {
result += '.' + query.sectionNumber;
}
if (query.professorName !== undefined) {
result += ' ' + query.professorName;
}
return result.trim();
}
2 changes: 1 addition & 1 deletion components/graph/BarGraph/BarGraph.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMediaQuery } from '@mui/material';
import { HorizontalBarGraph } from '../HorizontalBarGraph/HorizontalBarGraph';
import { VerticalBarGraph } from '../VerticalBarGraph/VerticalBarGraph';
import GraphProps from '../../../modules/GraphProps';
import GraphProps from '../../../modules/GraphProps/GraphProps';
import React from 'react';

/**
Expand Down
7 changes: 4 additions & 3 deletions components/graph/BoxGraph/BoxGraph.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import dynamic from 'next/dynamic';
import { ApexOptions } from 'apexcharts';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
import GraphProps from '../../../modules/GraphProps';
import GraphProps from '../../../modules/GraphProps/GraphProps';
import React from 'react';
import searchQueryColors from '../../../modules/searchQueryColors/searchQueryColors';

/**
* Creates a pre-configured ApexCharts box-and-whisker graph. Takes in `series`, `title`, and `xaxisLabels` via `GraphProps`.
Expand Down Expand Up @@ -51,8 +52,8 @@ export function BoxGraph(props: GraphProps) {
},
boxPlot: {
colors: {
upper: '#eb5757',
lower: '#2d9cdb',
upper: searchQueryColors[0],
lower: searchQueryColors[1],
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion components/graph/GraphChoice/GraphChoice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BarGraph } from '../BarGraph/BarGraph';
import { LineGraph } from '../LineGraph/LineGraph';
import { RadarChart } from '../RadarChart/RadarChart';
import { RadialBarChart } from '../RadialBarChart/RadialBarChart';
import GraphProps from '../../../modules/GraphProps';
import GraphProps from '../../../modules/GraphProps/GraphProps';
import { VerticalBarGraph } from '../VerticalBarGraph/VerticalBarGraph';
import { HorizontalBarGraph } from '../HorizontalBarGraph/HorizontalBarGraph';
import { BoxGraph } from '../BoxGraph/BoxGraph';
Expand Down
5 changes: 3 additions & 2 deletions components/graph/HorizontalBarGraph/HorizontalBarGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { useState } from 'react';
import dynamic from 'next/dynamic';
import { ApexOptions } from 'apexcharts';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
import GraphProps from '../../../modules/GraphProps';
import GraphProps from '../../../modules/GraphProps/GraphProps';
import React from 'react';
import searchQueryColors from '../../../modules/searchQueryColors/searchQueryColors';

/**
* Creates a pre-configured ApexCharts horizontal bar graph component. Takes in `series`, `title`, and `xaxisLabels` via `GraphProps`. This component also gets returned from a BarGraph component on a small screen.
Expand Down Expand Up @@ -39,7 +40,7 @@ export function HorizontalBarGraph(props: GraphProps) {
formatter: xaxisFormatter,
},
},
colors: ['#eb5757', '#2d9cdb', '#499F68'],
colors: searchQueryColors,
stroke: {
width: 2,
curve: 'smooth',
Expand Down
5 changes: 3 additions & 2 deletions components/graph/LineGraph/LineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { useState } from 'react';
import dynamic from 'next/dynamic';
import { ApexOptions } from 'apexcharts';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
import GraphProps from '../../../modules/GraphProps';
import GraphProps from '../../../modules/GraphProps/GraphProps';
import React from 'react';
import searchQueryColors from '../../../modules/searchQueryColors/searchQueryColors';

/**
* Creates a pre-configured ApexCharts line graph component. Takes in `series`, `title`, and `xaxisLabels` via `GraphProps`.
Expand Down Expand Up @@ -34,7 +35,7 @@ export function LineGraph(props: GraphProps) {
formatter: props.yaxisFormatter,
},
},
colors: ['#eb5757', '#2d9cdb', '#499F68'],
colors: searchQueryColors,
stroke: {
width: 2,
curve: 'smooth',
Expand Down
5 changes: 3 additions & 2 deletions components/graph/RadarChart/RadarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { useState } from 'react';
import dynamic from 'next/dynamic';
import { ApexOptions } from 'apexcharts';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
import GraphProps from '../../../modules/GraphProps';
import GraphProps from '../../../modules/GraphProps/GraphProps';
import React from 'react';
import searchQueryColors from '../../../modules/searchQueryColors/searchQueryColors';

/**
* Creates a pre-configured ApexCharts radar graph component. Takes in `series`, `title`, and `xaxisLabels` via `GraphProps`.
Expand All @@ -24,7 +25,7 @@ export function RadarChart(props: GraphProps) {
xaxis: {
categories: props.xaxisLabels,
},
colors: ['#eb5757', '#2d9cdb', '#499F68'],
colors: searchQueryColors,
stroke: {
width: 2,
},
Expand Down
5 changes: 3 additions & 2 deletions components/graph/RadialBarChart/RadialBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { useState } from 'react';
import dynamic from 'next/dynamic';
import { ApexOptions } from 'apexcharts';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
import GraphProps from '../../../modules/GraphProps';
import GraphProps from '../../../modules/GraphProps/GraphProps';
import React from 'react';
import searchQueryColors from '../../../modules/searchQueryColors/searchQueryColors';

/**
* Creates a pre-configured ApexCharts radial bar graph component. Takes in `series` and `title` `GraphProps`. The `data` fields in `series` need to each be arrays with just one entry.
Expand All @@ -25,7 +26,7 @@ export function RadialBarChart(props: GraphProps) {
},
},
labels: compiledLabels,
colors: ['#eb5757', '#2d9cdb', '#499F68'],
colors: searchQueryColors,
stroke: {
width: 2,
},
Expand Down
5 changes: 3 additions & 2 deletions components/graph/VerticalBarGraph/VerticalBarGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { useState } from 'react';
import dynamic from 'next/dynamic';
import { ApexOptions } from 'apexcharts';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
import GraphProps from '../../../modules/GraphProps';
import GraphProps from '../../../modules/GraphProps/GraphProps';
import React from 'react';
import searchQueryColors from '../../../modules/searchQueryColors/searchQueryColors';

/**
* Creates a pre-configured ApexCharts vertical bar graph component. Takes in `series`, `title`, and `xaxisLabels` via `GraphProps`. This component also gets returned from a BarGraph component on a large screen.
Expand Down Expand Up @@ -34,7 +35,7 @@ export function VerticalBarGraph(props: GraphProps) {
formatter: props.yaxisFormatter,
},
},
colors: ['#eb5757', '#2d9cdb', '#499F68'],
colors: searchQueryColors,
stroke: {
width: 2,
curve: 'smooth',
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions modules/SearchQuery/SearchQuery.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type SearchQuery = {
prefix?: string;
number?: string;
professorName?: string;
sectionNumber?: string;
};
export default SearchQuery;
2 changes: 2 additions & 0 deletions modules/searchQueryColors/searchQueryColors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const searchQueryColors = ['#eb5757', '#2d9cdb', '#499F68'];
export default searchQueryColors;
19 changes: 19 additions & 0 deletions modules/searchQueryEqual/searchQueryEqual.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import SearchQuery from '../SearchQuery/SearchQuery';

function searchQueryEqual(query1: SearchQuery, query2: SearchQuery): boolean {
if (query1.prefix !== query2.prefix) {
return false;
}
if (query1.professorName !== query2.professorName) {
return false;
}
if (query1.number !== query2.number) {
return false;
}
if (query1.sectionNumber !== query2.sectionNumber) {
return false;
}
return true;
}

export default searchQueryEqual;
20 changes: 20 additions & 0 deletions modules/searchQueryLabel/searchQueryLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import SearchQuery from '../SearchQuery/SearchQuery';

function searchQueryLabel(query: SearchQuery): string {
let result = '';
if (typeof query.prefix !== 'undefined') {
result += query.prefix;
}
if (typeof query.number !== 'undefined') {
result += ' ' + query.number;
}
if (typeof query.sectionNumber !== 'undefined') {
result += '.' + query.sectionNumber;
}
if (typeof query.professorName !== 'undefined') {
result += ' ' + query.professorName;
}
return result.trim();
}

export default searchQueryLabel;
8 changes: 1 addition & 7 deletions pages/api/autocomplete.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { DirectedGraph } from 'graphology';
import autocompleteGraph from '../../data/autocomplete_graph.json';

type SearchQuery = {
prefix?: string;
number?: string;
professorName?: string;
sectionNumber?: string;
};
import SearchQuery from '../../modules/SearchQuery/SearchQuery';

type NodeAttributes = {
c: string;
Expand Down
Loading

0 comments on commit 399aa6b

Please sign in to comment.