-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* MVP for professor search * Only change the page if page is not already the first * Use constant for number of results per page * Made a little efficiency improvement for those who hold down backspace when deleting * Used debouncer to fix laggy typing * Fixed bug that prevents aggregate filters from having any effect * Fixed an annoying UI issue where there is a loading bar for every single professor entry by hiding loading for professors list but showing it for individual pages * Refactored professors to instructors * Use fuse for fuzzy search for instructors * Remove unused variable * Added missing dispatch dependency * Refactored some code so that search is speedier * Changed getAllInstructors to actually get all instructors rather than just professors * Set the Fuse search to be a global variable in cache.ts * Set the Fuse search to be a global variable in cache.ts * Changed type of fuseIndex --------- Co-authored-by: “xavilien” <“[email protected]”>
- Loading branch information
Showing
15 changed files
with
312 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { RequestHandler } from "express"; | ||
import { PrismaReturn } from "../util.mjs"; | ||
import prisma from "../models/prisma.mjs"; | ||
|
||
const getAllInstructorsDbQuery = { | ||
select: { | ||
instructor: true, | ||
}, | ||
}; | ||
|
||
export interface GetInstructors { | ||
params: unknown; | ||
resBody: PrismaReturn<typeof prisma.fces.findMany<typeof getAllInstructorsDbQuery>>; | ||
reqBody: unknown; | ||
query: unknown; | ||
} | ||
|
||
export const getInstructors: RequestHandler< | ||
GetInstructors["params"], | ||
GetInstructors["resBody"], | ||
GetInstructors["reqBody"], | ||
GetInstructors["query"] | ||
> = async (_, res, next) => { | ||
try { | ||
const instructors = await prisma.fces.findMany({ | ||
select: { | ||
instructor: true, | ||
}, | ||
orderBy: { | ||
instructor: "asc", | ||
}, | ||
distinct: ["instructor"] | ||
}); | ||
res.json(instructors); | ||
} catch (e) { | ||
next(e); | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createAsyncThunk } from "@reduxjs/toolkit"; | ||
import { RootState } from "../store"; | ||
|
||
type FetchAllInstructorsType = { instructor: string }[]; | ||
|
||
export const fetchAllInstructors = createAsyncThunk< | ||
FetchAllInstructorsType, | ||
void, | ||
{ state: RootState } | ||
>("fetchAllInstructors", async (_, thunkAPI) => { | ||
const url = `${process.env.backendUrl}/instructors`; | ||
const state = thunkAPI.getState(); | ||
|
||
if (state.cache.allInstructors.length > 0) return; | ||
|
||
return ( | ||
await fetch(url, { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}) | ||
).json(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; | ||
|
||
export interface InstructorsState { | ||
search: string; | ||
} | ||
|
||
const initialState: InstructorsState = { | ||
search: "", | ||
}; | ||
|
||
export const instructorsSlice = createSlice({ | ||
name: "instructors", | ||
initialState, | ||
reducers: { | ||
updateSearch: (state, action: PayloadAction<string>) => { | ||
state.search = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const reducer = instructorsSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { MagnifyingGlassIcon } from "@heroicons/react/24/solid"; | ||
import React from "react"; | ||
import { useAppDispatch, useAppSelector } from "../app/hooks"; | ||
import { instructorsSlice } from "../app/instructors"; | ||
import { cacheSlice } from "../app/cache"; | ||
import { throttledInstructorFilter } from "../app/store"; | ||
|
||
const InstructorSearch = () => { | ||
const dispatch = useAppDispatch(); | ||
const page = useAppSelector((state) => state.cache.instructorPage); | ||
const search = useAppSelector((state) => state.instructors.search); | ||
|
||
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
dispatch(instructorsSlice.actions.updateSearch(e.target.value)); | ||
if (page !== 1) dispatch(cacheSlice.actions.setInstructorPage(1)); | ||
throttledInstructorFilter(); | ||
}; | ||
|
||
const results = useAppSelector((state) => state.cache.selectedInstructors); | ||
const numResults = results.length; | ||
|
||
return ( | ||
<> | ||
<div className="relative flex border-b border-b-gray-500 text-gray-500 dark:border-b-zinc-400 dark:text-zinc-300"> | ||
<span className="absolute inset-y-0 left-0 flex items-center"> | ||
<MagnifyingGlassIcon className="h-5 w-5" /> | ||
</span> | ||
<input | ||
autoFocus | ||
className="flex-1 py-2 pl-7 text-xl placeholder-gray-300 bg-transparent focus:outline-none dark:placeholder-zinc-500" | ||
type="search" | ||
value={search} | ||
onChange={onChange} | ||
placeholder="Search instructors by name..." | ||
/> | ||
</div> | ||
<div className="flex justify-between"> | ||
<div className="text-gray-400 mt-3 text-sm">{numResults} results</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default InstructorSearch; |
Oops, something went wrong.