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

Adding confirmation dialog provider #373

Merged
merged 2 commits into from
Oct 16, 2023
Merged

Conversation

mikefranze
Copy link
Collaborator

@mikefranze mikefranze commented Oct 16, 2023

Description

Made this as part of a larger task. Creates a context provider and hook for accessing confirmation dialog. The current dialog is just the MUI dialog, we can update the styling using #344. Basically, it adds a single dialog component at the top level of the app and uses a context provider to allow other components to open it, update the title and message, and get the response.

Built based on this tutorial https://akashhamirwasia.com/blog/building-expressive-confirm-dialog-api-in-react/
Uses some useRef and useCallback optimizations that are explained in there.

Screenshots / Videos (frontend only)

image
image

Related Issues

@mikefranze mikefranze requested a review from ArendPeter October 16, 2023 04:33
Copy link
Member

@ArendPeter ArendPeter left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for adding this

export function ConfirmDialogProvider({ children }) {


const [state, setState] = useState({ isOpen: false, title: '', message: '' });
Copy link
Member

Choose a reason for hiding this comment

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

nit

One thing we need to be careful of with this pattern is, manipulating state (like state.isOpen = true), won't trigger a refresh. Only reinstantiating the object with trigger a refresh

Looks like that's what's happening here, and I see that it makes the code cleaner, but I wanted to mention it anyway so that we're careful with it in the future

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using the setState function in the callback should reinstate the object though right?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, it's being reinstantiated in the callback, so it's fine

@mikefranze mikefranze merged commit d733daf into Equal-Vote:main Oct 16, 2023
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.

2 participants