-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract settings slice behind useSettings
- Loading branch information
Showing
16 changed files
with
79 additions
and
53 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
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,43 @@ | ||
import { useCallback } from 'react'; | ||
import { useAppDispatch, useAppSelector } from 'hooks'; | ||
import { | ||
toggleLockedCourses as toggleLocked, | ||
toggleShowMarks as toggleMarks, | ||
toggleShowPastWarnings as togglePastWarnings, | ||
toggleTheme | ||
} from 'reducers/settingsSlice'; | ||
|
||
interface Settings { | ||
theme: string; | ||
showMarks: boolean; | ||
showLockedCourses: boolean; | ||
showPastWarnings: boolean; | ||
mutateTheme: (theme: 'light' | 'dark') => void; | ||
toggleShowMarks: () => void; | ||
toggleLockedCourses: () => void; | ||
toggleShowPastWarnings: () => void; | ||
} | ||
|
||
function useSettings(): Settings { | ||
const settings = useAppSelector((state) => state.settings); | ||
const dispatch = useAppDispatch(); | ||
|
||
const mutateTheme = useCallback( | ||
(theme: 'light' | 'dark') => dispatch(toggleTheme(theme)), | ||
[dispatch] | ||
); | ||
|
||
const toggleShowMarks = useCallback(() => dispatch(toggleMarks()), [dispatch]); | ||
const toggleLockedCourses = useCallback(() => dispatch(toggleLocked()), [dispatch]); | ||
const toggleShowPastWarnings = useCallback(() => dispatch(togglePastWarnings()), [dispatch]); | ||
|
||
return { | ||
...settings, | ||
mutateTheme, | ||
toggleShowMarks, | ||
toggleLockedCourses, | ||
toggleShowPastWarnings | ||
}; | ||
} | ||
|
||
export default useSettings; |
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
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
Oops, something went wrong.