-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lift some course pane state to store
- Loading branch information
1 parent
2f2f056
commit 70aa35d
Showing
4 changed files
with
76 additions
and
59 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
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,49 @@ | ||
import { create } from 'zustand'; | ||
|
||
interface CoursePaneStore { | ||
/** Whether the search form is displayed (or the classes view) */ | ||
searchIsDisplayed: boolean; | ||
/** Switch to the course search form */ | ||
displaySearch: () => void; | ||
/** Switch to the classes view */ | ||
displaySections: () => void; | ||
|
||
manualSearchEnabled: boolean; | ||
enableManualSearch: () => void; | ||
disableManualSearch: () => void; | ||
toggleManualSearch: () => void; | ||
} | ||
|
||
function paramsAreInURL() { | ||
const search = new URLSearchParams(window.location.search); | ||
|
||
// TODO: This should be standardized | ||
const searchParams = ['courseCode', 'courseNumber', 'deptLabel', 'GE', 'deptValue', 'term']; | ||
|
||
return searchParams.some((param) => search.get(param) !== null); | ||
} | ||
|
||
export const useCoursePaneStore = create<CoursePaneStore>((set) => { | ||
return { | ||
searchIsDisplayed: true, | ||
displaySearch: () => { | ||
console.log('switching to search'); | ||
set({ searchIsDisplayed: true }); | ||
}, | ||
displaySections: () => { | ||
console.log('Switching to sections'); | ||
set({ searchIsDisplayed: false }); | ||
}, | ||
|
||
manualSearchEnabled: paramsAreInURL(), | ||
enableManualSearch: () => set({ manualSearchEnabled: true }), | ||
disableManualSearch: () => set({ manualSearchEnabled: false }), | ||
toggleManualSearch: () => set((state) => ({ manualSearchEnabled: !state.manualSearchEnabled })), | ||
}; | ||
}); | ||
|
||
export default useCoursePaneStore; | ||
|
||
setInterval(() => { | ||
console.log(useCoursePaneStore.getState().searchIsDisplayed); | ||
}, 5000); |