-
Notifications
You must be signed in to change notification settings - Fork 29
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
Instructor Search #137
Merged
Merged
Instructor Search #137
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d8c6b5b
MVP for professor search
Xavilien cb48cfe
Only change the page if page is not already the first
Xavilien 752b14d
Use constant for number of results per page
Xavilien 96fcbc0
Made a little efficiency improvement for those who hold down backspac…
Xavilien 69cf4e2
Used debouncer to fix laggy typing
Xavilien 5405491
Fixed bug that prevents aggregate filters from having any effect
Xavilien 3776b71
Fixed an annoying UI issue where there is a loading bar for every sin…
Xavilien f6694ef
Refactored professors to instructors
Xavilien a276146
Use fuse for fuzzy search for instructors
Xavilien c709eeb
Remove unused variable
Xavilien b54b933
Added missing dispatch dependency
Xavilien d75fda4
Refactored some code so that search is speedier
Xavilien 9edb0eb
Changed getAllInstructors to actually get all instructors rather than…
Xavilien 12ca24b
Set the Fuse search to be a global variable in cache.ts
e9c0982
Set the Fuse search to be a global variable in cache.ts
0ae2223
Changed type of fuseIndex
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too sure on the
Fuse
library API so I will trust this hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was basing it of this https://www.fusejs.io/api/indexing.html#fuse-createindex