-
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.
Merge remote-tracking branch 'origin' into eric/app-904-extract-modal…
…-state-into-separate-statecontext * origin: Move invite-state to new persistence + context and replace the notifications with just showing uses in the modal (#1840) Move muted threads to new persistence + context (#1838) Move onboarding state to new persistence + reducer context (#1835) Move require alt-text to new persistence + context (#1839) Move reminders to new persisted state layer (#1834) Add persistent state provider (#1830)
- Loading branch information
Showing
44 changed files
with
1,012 additions
and
699 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react' | ||
import * as persisted from '#/state/persisted' | ||
|
||
type StateContext = persisted.Schema['invites'] | ||
type ApiContext = { | ||
setInviteCopied: (code: string) => void | ||
} | ||
|
||
const stateContext = React.createContext<StateContext>( | ||
persisted.defaults.invites, | ||
) | ||
const apiContext = React.createContext<ApiContext>({ | ||
setInviteCopied(_: string) {}, | ||
}) | ||
|
||
export function Provider({children}: React.PropsWithChildren<{}>) { | ||
const [state, setState] = React.useState(persisted.get('invites')) | ||
|
||
const api = React.useMemo( | ||
() => ({ | ||
setInviteCopied(code: string) { | ||
setState(state => { | ||
state = { | ||
...state, | ||
copiedInvites: state.copiedInvites.includes(code) | ||
? state.copiedInvites | ||
: state.copiedInvites.concat([code]), | ||
} | ||
persisted.write('invites', state) | ||
return state | ||
}) | ||
}, | ||
}), | ||
[setState], | ||
) | ||
|
||
React.useEffect(() => { | ||
return persisted.onUpdate(() => { | ||
setState(persisted.get('invites')) | ||
}) | ||
}, [setState]) | ||
|
||
return ( | ||
<stateContext.Provider value={state}> | ||
<apiContext.Provider value={api}>{children}</apiContext.Provider> | ||
</stateContext.Provider> | ||
) | ||
} | ||
|
||
export function useInvitesState() { | ||
return React.useContext(stateContext) | ||
} | ||
|
||
export function useInvitesAPI() { | ||
return React.useContext(apiContext) | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.