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

Added showAll option for the Search page as a tri-state checkbox #163

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 16 additions & 0 deletions apps/frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}

export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
5 changes: 5 additions & 0 deletions apps/frontend/src/app/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface UserState {
showCourseInfos: boolean;
showSchedules: boolean;
loggedIn: boolean;
showAll: boolean;
fceAggregation: {
numSemesters: number;
counted: {
Expand All @@ -31,6 +32,7 @@ const initialState: UserState = {
showCourseInfos: true,
showSchedules: false,
loggedIn: false,
showAll: false,
fceAggregation: {
numSemesters: 2,
counted: {
Expand Down Expand Up @@ -69,6 +71,9 @@ export const userSlice = createSlice({
showSchedules: (state, action: PayloadAction<boolean>) => {
state.showSchedules = action.payload;
},
showAll : (state, action: PayloadAction<boolean>) => {
state.showAll = action.payload;
},
logIn: (state) => {
state.loggedIn = true;
},
Expand Down
48 changes: 47 additions & 1 deletion apps/frontend/src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect } from "react";
import React, { useCallback, useEffect, useRef } from "react";
import { useAppDispatch, useAppSelector } from "~/app/hooks";
import { throttledFilter } from "~/app/store";
import { MagnifyingGlassIcon, XMarkIcon } from "@heroicons/react/24/solid";
Expand Down Expand Up @@ -153,6 +153,34 @@ const SearchBar = () => {
const showFCEs = useAppSelector((state) => state.user.showFCEs);
const showCourseInfos = useAppSelector((state) => state.user.showCourseInfos);
const showSchedules = useAppSelector((state) => state.user.showSchedules);
const showAll = useAppSelector((state) => state.user.showAll);

const showAllRef = useRef<any>(null);
useEffect(() => {
if (showAllRef.current) {
if (loggedIn) {
if ((showFCEs && showCourseInfos && showSchedules)) {
showAllRef.current.indeterminate = false;
showAllRef.current.checked = true;
} else if (!(showFCEs || showCourseInfos || showSchedules)) {
showAllRef.current.indeterminate = false;
showAllRef.current.checked = false;
} else
showAllRef.current.indeterminate = true;
} else {
console.log(showFCEs, showCourseInfos, showSchedules);
if ((showCourseInfos && showSchedules)) {
showAllRef.current.indeterminate = false;
showAllRef.current.checked = true;
} else if (!(showCourseInfos || showSchedules)) {
showAllRef.current.indeterminate = false;
showAllRef.current.checked = false;
} else
showAllRef.current.indeterminate = true;
}
}
}, [showAllRef, showAllRef.current, showFCEs, showCourseInfos, showSchedules]);


const setShowFCEs = (e: React.ChangeEvent<HTMLInputElement>) => {
dispatch(userSlice.actions.showFCEs(e.target.checked));
Expand All @@ -166,6 +194,13 @@ const SearchBar = () => {
dispatch(userSlice.actions.showSchedules(e.target.checked));
};

const setShowAll = (e: React.ChangeEvent<HTMLInputElement>) => {
dispatch(userSlice.actions.showAll(e.target.checked));
if (loggedIn) {dispatch(userSlice.actions.showFCEs(e.target.checked));}
dispatch(userSlice.actions.showCourseInfos(e.target.checked));
dispatch(userSlice.actions.showSchedules(e.target.checked));
};

const numResults = useAppSelector((state) => state.cache.totalDocs);

return (
Expand All @@ -187,6 +222,17 @@ const SearchBar = () => {
<div className="mt-3 text-sm text-gray-400">{numResults} results</div>
<div className="mt-3 flex justify-end text-gray-500">
<div className="mr-6 hidden md:block">Show</div>
<div className="mr-6">
<input
id="selectAll"
type="checkbox"
className="mr-2"
onChange={setShowAll}
checked={showAll}
ref = {showAllRef}
/>
<span>All</span>
</div>
<div className="mr-6">
<input
type="checkbox"
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/components/StarRating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const StarRating = ({ rating }: { rating: number }) => {
starEmptyColor={
darkMode
? 'zinc-300'
: 'gray-500'
: 'gray-300'
}
/>
);
Expand Down
Loading