-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(zbugs): Fix react-refresh/only-export-components warnings (#3415)
By splitting files as needed.
- Loading branch information
Showing
20 changed files
with
172 additions
and
175 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import emojiDataSource from 'emoji-picker-element-data/en/emojibase/data.json?url'; | ||
|
||
export {emojiDataSource}; |
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,25 @@ | ||
import {useCallback, useSyncExternalStore} from 'react'; | ||
import {loginContext} from '../hooks/use-login.js'; | ||
import {clearJwt} from '../jwt.js'; | ||
import {authRef} from '../zero-setup.js'; | ||
|
||
export function LoginProvider({children}: {children: React.ReactNode}) { | ||
const loginState = useSyncExternalStore( | ||
authRef.onChange, | ||
useCallback(() => authRef.value, []), | ||
); | ||
|
||
return ( | ||
<loginContext.Provider | ||
value={{ | ||
logout: () => { | ||
clearJwt(); | ||
authRef.value = undefined; | ||
}, | ||
loginState, | ||
}} | ||
> | ||
{children} | ||
</loginContext.Provider> | ||
); | ||
} |
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,16 @@ | ||
import Database from 'emoji-picker-element/database.js'; | ||
import {useEffect} from 'react'; | ||
import {emojiDataSource} from '../components/emoji-data-source.js'; | ||
|
||
export function useEmojiDataSourcePreload() { | ||
useEffect(() => { | ||
// Do this on a timer to not compete with other work. | ||
const timer = setTimeout( | ||
() => { | ||
new Database({dataSource: emojiDataSource}); | ||
}, | ||
1000 + Math.random() * 1000, | ||
); | ||
return () => clearTimeout(timer); | ||
}, []); | ||
} |
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 |
---|---|---|
@@ -1,45 +1,17 @@ | ||
import { | ||
createContext, | ||
useCallback, | ||
useContext, | ||
useSyncExternalStore, | ||
} from 'react'; | ||
import {clearJwt} from '../jwt.js'; | ||
import {type LoginState, authRef} from '../zero-setup.js'; | ||
import {createContext, useContext} from 'react'; | ||
import {type LoginState} from '../zero-setup.js'; | ||
|
||
export type LoginContext = { | ||
logout: () => void; | ||
loginState: LoginState | undefined; | ||
}; | ||
|
||
const loginContext = createContext<LoginContext | undefined>(undefined); | ||
export const loginContext = createContext<LoginContext | undefined>(undefined); | ||
|
||
// eslint-disable-next-line react-refresh/only-export-components | ||
export function useLogin() { | ||
export function useLogin(): LoginContext { | ||
const state = useContext(loginContext); | ||
if (state === undefined) { | ||
throw new Error('useLogin must be used within a LoginProvider'); | ||
} | ||
return state; | ||
} | ||
|
||
export function LoginProvider({children}: {children: React.ReactNode}) { | ||
const loginState = useSyncExternalStore( | ||
authRef.onChange, | ||
useCallback(() => authRef.value, []), | ||
); | ||
|
||
return ( | ||
<loginContext.Provider | ||
value={{ | ||
logout: () => { | ||
clearJwt(); | ||
authRef.value = undefined; | ||
}, | ||
loginState, | ||
}} | ||
> | ||
{children} | ||
</loginContext.Provider> | ||
); | ||
} |
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.