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

ryan/feat(ux: create input loading spinner) #399

Merged
merged 49 commits into from
Sep 20, 2024

Conversation

ryandotfurrer
Copy link
Member

@ryandotfurrer ryandotfurrer commented Jul 13, 2024

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 a min-width/max-width and min-height/max-height equal to tailwind's w-7/w-9 and h-7/h-9 so it fits within the smallest and largest size variants of the Button component.

  • When a user clicks a submit button, the text should be replaced by a spinner
  • When a user clicks a submit button, the button should be disabled from being clicked again

Closes #91

…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.
@ryandotfurrer ryandotfurrer linked an issue Jul 13, 2024 that may be closed by this pull request
2 tasks
Copy link

vercel bot commented Jul 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
gridiron-survivor ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2024 0:28am
gridiron-survivor-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2024 0:28am

Copy link

appwrite bot commented Jul 13, 2024

Gridiron Survivor Application 6616ea581ef9f5521c7d

Function ID Status Action
Your function has been successfully deployed.

Project name: Gridiron Survivor Application
Project ID: 6616ea581ef9f5521c7d

Function ID Status Action
userAuth 6626fef885a9f630442b ready Ready View Logs

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.

💡 Did you know?
You can use Avatars API to generate QR code for any text or URLs

@ryandotfurrer ryandotfurrer marked this pull request as draft July 17, 2024 00:14
@@ -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',
Copy link
Collaborator

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.

Copy link
Member Author

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?

Copy link
Member Author

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.

<p className="text-lg font-bold">
You are not enrolled in any leagues
</p>
<LoadingSpinner height="max-h-32 h-32" />
Copy link
Collaborator

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?

Copy link
Member Author

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

Copy link
Member Author

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?

Copy link
Member Author

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.

@@ -56,9 +58,7 @@ const Leagues = (): JSX.Element => {
))
) : (
<div className="text-center">
<p className="text-lg font-bold">
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 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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed from this page

Copy link
Collaborator

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.

Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Collaborator

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.

Copy link
Member Author

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?

Copy link
Member Author

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.

Copy link
Member Author

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)/login/page.tsx Outdated Show resolved Hide resolved
@@ -115,6 +119,7 @@ const Register = (): JSX.Element => {
/>,
);
} catch (error) {
setIsLoading(false);
Copy link
Contributor

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.

Copy link
Member Author

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.

@vmaineng this was from @Clue355's branch of this branch that was approved and merged in.

Copy link
Member Author

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!" />,
      );
    }
  };

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

@ryandotfurrer ryandotfurrer Sep 4, 2024

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

Copy link
Collaborator

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.

Copy link
Member Author

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

beforeEach(() => {
jest.clearAllMocks();
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@choir27 fixed

Comment on lines +108 to +112
it('should show the loading spinner', async () => {
(useStateMock as jest.Mock).mockImplementation((init: boolean) => [
true,
setIsLoading,
]);
Copy link
Contributor

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

Copy link
Member Author

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!

Copy link
Member Author

Choose a reason for hiding this comment

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

@choir27 fixed

@shashilo shashilo merged commit 36b4ab6 into develop Sep 20, 2024
5 checks passed
@shashilo shashilo deleted the ryan/create-input-loading-spinner branch September 20, 2024 14: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.

UX: Create input loading spinner
6 participants