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

feat: add loader state for buttons and use it for API CTA #1077

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Elmenax2
Copy link
Contributor

  • Added a loading state of FantasyButton and StyledButton
  • Use the loading state for all the CTA that do an API request
  • Went through all the user views (did not do Admin views as I assume that is not used by many?)
  • Tested all the buttons but let me know if I have missed anything

Comment on lines +103 to +110
{loading && (
<Box sx={{ position: 'absolute', left: '50%', top: '50%', transform: 'translate(-50%, -50%)' }}>
<Loader size={loaderSize} color="inherit" />
</Box>
)}
<Box sx={{ visibility: loading ? 'hidden' : 'initial', }}>
{children}
</Box>
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of absolute positioning, I would rather only display the loader instead of the children if the loading state is true, and not use the visibility CSS rule, as it's handled differently on pretty much every browser out there.
(I didn't check if the loader was correctly aligned in my suggestion)

Suggested change
{loading && (
<Box sx={{ position: 'absolute', left: '50%', top: '50%', transform: 'translate(-50%, -50%)' }}>
<Loader size={loaderSize} color="inherit" />
</Box>
)}
<Box sx={{ visibility: loading ? 'hidden' : 'initial', }}>
{children}
</Box>
{loading ? (
<Loader size={loaderSize} color="inherit" />
) : children}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally went for that solution, however it does not render well because the button will adjust its width, causing the button to be smaller (since the loader will be smaller than the text). That is why I went with the visibility and absolute positioning, to make sure the button would keep its current width.

If you think that it does not matter to have the button size changes when switching to loading state, I can follow your suggestion

Copy link
Owner

Choose a reason for hiding this comment

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

Alright, I understand, then your solution can work, however, you need to add more css rules to hide the box parent to the children, since visibility is poorly handled (Also I didn't check yet, but make sure the added box doesn't add more padding/margin)

Comment on lines +97 to +104
{loading && (
<Box sx={{ position: 'absolute', left: '50%', top: '50%', transform: 'translate(-50%, -50%)' }}>
<Loader size={16} color="inherit" />
</Box>
)}
<Box sx={{ visibility: loading ? 'hidden' : 'initial', }}>
{children}
</Box>
Copy link
Owner

Choose a reason for hiding this comment

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

Same notes as the FantasyButton, only display the loader, not the children if it's loading

@@ -99,6 +102,7 @@ const CellTournament = ({
shadow={false}
contrast={false}
onClick={registerBrute}
disabled={isRegisteringBrute}
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't it use your new loading attribute instead?

@Zenoo
Copy link
Owner

Zenoo commented Feb 15, 2025

Are you still working on this @Elmenax2 ?

@Elmenax2
Copy link
Contributor Author

Are you still working on this @Elmenax2 ?

Yes, I'm planning to finish that. I have been quite busy in the last weeks, but I'll wrap it up! Sorry about the delay

@Zenoo
Copy link
Owner

Zenoo commented Feb 15, 2025

No problem, take your time.

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