-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
150 additions
and
28 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Empty file.
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,50 @@ | ||
import React from 'react' | ||
|
||
import {isWeb} from '#/platform/detection' | ||
import * as persisted from '#/state/persisted' | ||
|
||
type StateContext = persisted.Schema['kawaii'] | ||
|
||
const stateContext = React.createContext<StateContext>( | ||
persisted.defaults.kawaii, | ||
) | ||
|
||
export function Provider({children}: React.PropsWithChildren<{}>) { | ||
const [state, setState] = React.useState(persisted.get('kawaii')) | ||
|
||
const setStateWrapped = React.useCallback( | ||
(kawaii: persisted.Schema['kawaii']) => { | ||
setState(kawaii) | ||
persisted.write('kawaii', kawaii) | ||
}, | ||
[setState], | ||
) | ||
|
||
React.useEffect(() => { | ||
return persisted.onUpdate(() => { | ||
setState(persisted.get('kawaii')) | ||
}) | ||
}, [setStateWrapped]) | ||
|
||
React.useEffect(() => { | ||
// dumb and stupid but it's web only so just refresh the page if you want to change it | ||
|
||
if (isWeb) { | ||
const kawaii = new URLSearchParams(window.location.search).get('kawaii') | ||
switch (kawaii) { | ||
case 'true': | ||
setStateWrapped(true) | ||
break | ||
case 'false': | ||
setStateWrapped(false) | ||
break | ||
} | ||
} | ||
}, [setStateWrapped]) | ||
|
||
return <stateContext.Provider value={state}>{children}</stateContext.Provider> | ||
} | ||
|
||
export function useKawaiiMode() { | ||
return React.useContext(stateContext) | ||
} |
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
81ae7e4
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.
this is great, i love this