Skip to content

Commit

Permalink
Revert "Remove state"
Browse files Browse the repository at this point in the history
This reverts commit 673bbf4.
  • Loading branch information
AbhiramTadepalli committed Nov 8, 2024
1 parent 9dc3e06 commit 17f3293
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/pages/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ function fetchRmpData(
export const Dashboard: NextPage = () => {
const router = useRouter();

const [pageTitle, setPageTitle] = useState<string>('');
//Searches seperated into courses and professors to create combos
const [courses, setCourses] = useState<SearchQuery[]>([]);
const [professors, setProfessors] = useState<SearchQuery[]>([]);
Expand Down Expand Up @@ -264,6 +265,8 @@ export const Dashboard: NextPage = () => {
setCourses(courseSearchTerms);
setProfessors(professorSearchTerms);

updatePageTitle(courseSearchTerms, professorSearchTerms);

//Clear fetched data
setResults({ state: 'loading' });
setAcademicSessions([]);
Expand Down Expand Up @@ -335,6 +338,24 @@ export const Dashboard: NextPage = () => {
}
}, [router.isReady, router.query.searchTerms]);

function updatePageTitle(
courseSearchTerms: SearchQuery[],
professorSearchTerms: SearchQuery[],
) {
let str = '';
courseSearchTerms.map((term) => {
str += searchQueryLabel(term) + ', ';
});
professorSearchTerms.map((term) => {
str += searchQueryLabel(term) + ', ';
});
str =
str.lastIndexOf(', ') === str.length - 2
? str.substring(0, str.lastIndexOf(', ')) + ' - '
: str;
setPageTitle(str);
}

//Compiled list of academic sessions grade data is available for
const [academicSessions, setAcademicSessions] = useState<string[]>([]);
//Selected sessions to perform calculations with, starts as all of them
Expand Down Expand Up @@ -758,18 +779,6 @@ export const Dashboard: NextPage = () => {
);
}

let pageTitle = 'test';
courses.map((term) => {
pageTitle += searchQueryLabel(term) + ', ';
});
professors.map((term) => {
pageTitle += searchQueryLabel(term) + ', ';
});
pageTitle =
pageTitle.lastIndexOf(', ') === pageTitle.length - 2
? pageTitle.substring(0, pageTitle.lastIndexOf(', ')) + ' - '
: pageTitle;

/* Final page */

return (
Expand Down

0 comments on commit 17f3293

Please sign in to comment.