-
Notifications
You must be signed in to change notification settings - Fork 1
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
ryan/feat(ux: create input loading spinner) #399
Conversation
…mponent optional props expect strings (tailwind classes) so the loader takes up the same amount of space as the element it is replacing before it loads in.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Gridiron Survivor Application
Project name: Gridiron Survivor Application
Only deployments on the production branch are activated automatically. If you'd like to activate this deployment, navigate to your deployments. Learn more about Appwrite Function deployments.
|
…m/LetsGetTechnical/gridiron-survivor into ryan/create-input-loading-spinner
components/LeagueCard/LeagueCard.tsx
Outdated
@@ -23,7 +23,7 @@ const LeagueCard = React.forwardRef<HTMLAnchorElement, ILeagueCardProps>( | |||
data-testid="LeagueCard" | |||
href={href} | |||
className={cn( | |||
'LeagueCard flex max-h-32 place-items-center gap-6 rounded-lg border bg-card p-4 text-card-foreground shadow-sm dark:border-zinc-800 hover:bg-zinc-800 transition', | |||
'LeagueCard flex max-h-32 h-32 place-items-center gap-6 rounded-lg border bg-card p-4 text-card-foreground shadow-sm dark:border-zinc-800', |
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.
DO NOT set a hard height on this component. This will remove its flexibility and create bugs when content overflows.
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.
@shashilo This is outdated, can it be resolved?
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.
@shashilo pinging you for a reminder, please advise.
app/(main)/league/all/page.tsx
Outdated
<p className="text-lg font-bold"> | ||
You are not enrolled in any leagues | ||
</p> | ||
<LoadingSpinner height="max-h-32 h-32" /> |
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.
Why is this max and hard set height?
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 added props to the loader so you can set the height of it to match the element it's replacing. I'll revise this so it takes up 100% of the height and width of what it's replacing by default
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.
@shashilo This is outdated, can it be resolved?
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.
@shashilo pinging you for a reminder, please advise.
app/(main)/league/all/page.tsx
Outdated
@@ -56,9 +58,7 @@ const Leagues = (): JSX.Element => { | |||
)) | |||
) : ( | |||
<div className="text-center"> | |||
<p className="text-lg font-bold"> |
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 incorrect. The loader should replace to submit content as the API is waiting for a response. This message is correct when there are 0 leagues associated with the user.
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.
Removed from this page
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.
You reverted the
back, but the styles were not carried over.
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.
@shashilo what loader is meant to be used on the LeagueCard component? I thought this input spinner was for buttons only?
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.
@ryandotfurrer Was this question addressed?
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.
<p className="text-lg font-bold">
These classes were removed. Wondering if this is intentional or not.
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.
@ryandotfurrer Was this question addressed?
It was not. @shashilo, what loader is meant to be used on the LeagueCard component? I thought this input spinner was for buttons only?
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.
<p className="text-lg font-bold">
These classes were removed. Wondering if this is intentional or not.
These are back in and will be reflected upon the next commit.
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.
@ryandotfurrer Was this question addressed?
It was not. @shashilo, what loader is meant to be used on the LeagueCard component? I thought this input spinner was for buttons only?
@shashilo pinging you for a reminder, please advise.
app/(main)/register/page.tsx
Outdated
@@ -115,6 +119,7 @@ const Register = (): JSX.Element => { | |||
/>, | |||
); | |||
} catch (error) { | |||
setIsLoading(false); |
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.
Could you please explain why setIsLoading(false)
is used twice? One in the try
part and in the catch
.
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.
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.
Though I'd like to make this as similar to my code on the login page as possible.
@shashilo @Clue355 @vmaineng @chris-nowicki thoughts on me changing the onSubmit
on the register/page.tsx
to be inline with the one on the login/page.tsx
?
Current Login onSubmit
const onSubmit: SubmitHandler<LoginUserSchemaType> = async (
data: LoginUserSchemaType,
): Promise<void> => {
try {
setIsLoading(true);
await login(data);
} catch (error) {
console.error(error);
throw new Error('An error occurred while logging in');
} finally {
setIsLoading(false);
}
};
Current Register onSubmit
const onSubmit: SubmitHandler<RegisterUserSchemaType> = async (
data: RegisterUserSchemaType,
): Promise<void> => {
try {
setIsLoading(true);
await registerAccount(data);
await login(data);
setIsLoading(false);
router.push('/league/all');
toast.custom(
<Alert
variant={AlertVariants.Success}
message="You have successfully registered your account."
/>,
);
} catch (error) {
setIsLoading(false);
console.error('Registration Failed', error);
toast.custom(
<Alert variant={AlertVariants.Error} message="Something went wrong!" />,
);
}
};
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.
@shashilo @Clue355 @vmaineng @chris-nowicki Please advise on the comment above.
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.
@ryandotfurrer in what ways to you plan to make it inline? by adding a finally to the register try/catch?
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.
@ryandotfurrer in what ways to you plan to make it inline? by adding a finally to the register try/catch?
@chris-nowicki precisely. Just to make them consistent. @vmaineng
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 finally. It allows you to only call the setIsLoading false once.
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 finally. It allows you to only call the setIsLoading false once.
@shashilo added in the latest commit
app/(main)/login/page.test.tsx
Outdated
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
jest.spyOn(React, 'useState').mockImplementation(useStateMock); |
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.
Does this not return an error in your local machine? I tried using this syntax for my loadingSpinner test, but it kept returning an error for me.
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.
@choir27 it does; and it did before. I just haven't been able to get back to this one :P
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.
@choir27 fixed
it('should show the loading spinner', async () => { | ||
(useStateMock as jest.Mock).mockImplementation((init: boolean) => [ | ||
true, | ||
setIsLoading, | ||
]); |
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.
Your tests seem to be failing, please look into this and make sure it's changing the loading state properly
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.
@choir27 I was aware :P Just been busy working on other things and unable to get back to this. TY!
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.
@choir27 fixed
input-loading-spinner.mp4
I created the
LoadingSpinner
component which is designed to be used in buttons when sending data to the database. It has amin-width/max-width
andmin-height/max-height
equal to tailwind'sw-7/w-9
andh-7/h-9
so it fits within the smallest and largest size variants of theButton
component.Closes #91