-
Notifications
You must be signed in to change notification settings - Fork 120
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
Modal components refactoring #2515
Conversation
eb5cc45
to
acedb7e
Compare
Branch's history has been dated to make it easier to gradual review and merge. Working is still in progress on trezor modals. |
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.
@guilhermemntt Code look good, thanks.
Added some inline comments.
import Modal from "./AddAccountModalContent"; | ||
import useAddAccountModal from "./hooks"; | ||
|
||
function AddAccountModal({ onCancelModal, onSubmit, ...props }) { |
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.
I would recommend using const with arrow function here and for all other modals
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.
Fixed.
updatePrivatePassphrase, | ||
updateConfirmPrivatePassphrase, | ||
onTriggerPassphraseModalSubmit, | ||
...state |
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.
Where is this state
defined?
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 repeating in all modals, is it needed? the hooks seem to return all the values, so not sure if this needed.
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.
The state
variables are the hook states used in ***Content.jsx
components and/or their children. The unused states in their children components aren't being returned from hooks.js
. It can be changed if returned values from hooks are declared and passed as props explicitly as well. I'm open to suggestions here.
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.
I prefer declare and explicit call them, because it makes it easier to know what props a component is using. Also, with hooks there are no more states declaration, so I think it may be confunsing.
setConfirmPrivPassError(privPass !== confirmPrivPass); | ||
}, [privPass, confirmPrivPass]); | ||
|
||
const isValid = useCallback(() => { |
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.
use useMemo
here as it returns an object and not a function, same for all hooks, some of them include variables which should be wrapped with useMemo
instead of useCallback
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.
Fixed, as the old Modals.js
no longer depends on it as a function.
c358ed6
to
8a4aa70
Compare
Modals not yet refactored may have some layout bugs since |
4b61864
to
ac3685f
Compare
I'm opening this PR to merge as tests with Trezor require previous corrections due to #2539. Some points here:
|
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.
I noticed you import modal.module.css
in many views and component which aren't really related to the modals (left inline comments but I guess there are more in other components).
Please create local css modules for all these files and move the styling away from modal.module.css, actually this is one of the main reasons why css modules exists and they are much predictable & encapsulated approach.
Will do another review cycle when done.
Edit: just saw your comment about that, let's just create a module css without fully migrating the components, just copy over the ones you already have in modal.module.css and all the rest migration work will come later.
@@ -7,11 +7,12 @@ import { ShowWarning, Subtitle } from "shared"; | |||
import "style/PurchaseTickets.less"; | |||
import { InfoDocModalButton } from "buttons"; | |||
import UnsignedTickets from "./UnsignedTickets"; | |||
import modalStyle from "../../../modals/Modals.module.css"; |
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.
Please create a module for TicketsPage and use it here, this import doesn't make sense here
@@ -1,6 +1,7 @@ | |||
import { FormattedMessage as T } from "react-intl"; | |||
import { SettingsInput, NumericInput } from "inputs"; | |||
import { InfoDocFieldModalButton } from "buttons"; | |||
import modalStyle from "../../modals/Modals.module.css"; |
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.
same here, but as i'm already refactoring this part please leave a TODO and I could handle it later
I've implemented the changes. It seems to be ok now. |
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.
Thanks for this PR! Good job on it. I have some small nits, but looks really good overall.
Looks like there are some modals which are not properly working.
- Ticket auto buyer
- VSP remove confirmation
Keep in mind in decrediton we have a right alignment design #1940, Keep that on our modals. I noticed some of them are with the button aligned at the left. Also the import redeem script modal is a bit off alignment as well:
Also I think we could have a copy to clipboard button at the confirm redeem script modal, but not really related to this PR:
The copy seed modal looks too wide:
Here is its spec: #2223
updatePrivatePassphrase, | ||
updateConfirmPrivatePassphrase, | ||
onTriggerPassphraseModalSubmit, | ||
...state |
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.
I prefer declare and explicit call them, because it makes it easier to know what props a component is using. Also, with hooks there are no more states declaration, so I think it may be confunsing.
Refactor ChangePassphraseModal Refactor ImportScriptModal
Refactor PassphraseModal Refactor Modal
Refactor BackupRedeemScriptModal Refactor AddMixerAccountsModal Refactor AutobuyerRunningModal
Refactor DocumentationInfoModal Refactor InfoConfirmModal Refactor InfoModal
Remove unnecessary CSS class rules
7fc646c
to
8330814
Compare
@vctt94, I've created a remove VSP confirmation modal: and opened the issue #2547. To keep the standard, some lines have been added in In general, other GUI changes have been implemented in Info modals, according to #1940. |
app/components/modals/AboutModal.jsx
Outdated
/>{" "} | ||
<a | ||
onClick={() => | ||
shell.openExternal("https://decred.org/contributors/") |
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.
Given this wasn't a pure file move, I think you should go ahead and replace these inline links for the ExternalLink
component
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.
Replaced.
app/components/modals/AboutModal.jsx
Outdated
)} | ||
</div> | ||
<div className={style.aboutBottomAreaMiddle}> | ||
Copyright © 2019{" "} |
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.
2020
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.
Fixed.
Add useAboutModal custom hook
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.
Thanks! LGTM.
This PR is part of the effort to update Decrediton to modern React code using hooks and functional components (#2438) and to increase modularity using specific
CSS
modules also (#2439). Generally, modals have no or few dynamic controls, so some of them have been moved directly toapp/components/modals/
without the need for a specific subdirectory. The latest modals implemented as class components have been refactored to functional components. The style rules will be located inModals.modules.css
in the same directory. I am totally open to suggestions, especially regarding the organization of the files innerapp/components/modals/
.Before:
After: