Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modal state provider, replace usage except methods #1833

Merged

Conversation

estrattonbailey
Copy link
Member

No description provided.

const closeModal = React.useCallback(() => {
let totalActiveModals = 0
setActiveModals(activeModals => {
activeModals.pop()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mutative. We shouldn't mutate inside updaters, which need to be pure functions.

We should enable Strict Mode to catch these better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good shout, this should be improved at some point. We should also do the portaling thing we talked about.

This is just a direct port of the existing functionality, so I'd like to just leave as is until we can come back and do it right.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make this a non-mutation now though right? Not terribly hard

src/state/modals/index.tsx Outdated Show resolved Hide resolved
src/state/modals/index.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. accept with small changes

…-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)
…-state-into-separate-statecontext

* origin:
  State layer cleanup: move alt-text-required into preferences and fix a bug in reminders (#1845)
  Move language preferences to new persistence + context (#1837)
opts: CropperOptions,
): Promise<RNImage> {
// TODO handle more opts
return new Promise((resolve, reject) => {
store.shell.openModal({
unstable__openModal({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this hacky global I'd need to pass through 2 mobx models and into this file 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the only reason the store model was being passed to these methods was for that. I'm fine with this hack but we should also ditch that param at some point (can be later)

@@ -363,7 +145,7 @@ export class ShellUiModel {
setupLoginModals() {
this.rootStore.onSessionReady(() => {
if (shouldRequestEmailConfirmation(this.rootStore.session)) {
this.openModal({name: 'verify-email', showReminder: true})
unstable__openModal({name: 'verify-email', showReminder: true})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same idea here

Comment on lines +221 to +226
/**
* @deprecated DO NOT USE THIS unless you have no other choice.
*/
export let unstable__openModal: (modal: Modal) => void = () => {
throw new Error(`ModalContext is not initialized`)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hack

Copy link
Collaborator

@pfrazee pfrazee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I think any further changes can be in followups

@pfrazee pfrazee merged commit f18b152 into main Nov 8, 2023
4 checks passed
@pfrazee pfrazee deleted the eric/app-904-extract-modal-state-into-separate-statecontext branch November 8, 2023 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants