Skip to content

feat: add loading state to Button component and integrate with form submissions#20

Merged
coji merged 1 commit intomainfrom
feat/is-loading
Mar 8, 2025
Merged

feat: add loading state to Button component and integrate with form submissions#20
coji merged 1 commit intomainfrom
feat/is-loading

Conversation

@coji
Copy link
Owner

@coji coji commented Mar 8, 2025

This pull request includes several changes to enhance the Button component by adding a loading state and updating its usage in different parts of the application. The most important changes include modifying the Button component to support a loading state and updating the relevant routes to utilize this new feature.

Enhancements to Button component:

Updates to routes:

Summary by CodeRabbit

  • New Features
    • Enhanced the button component to support a dynamic loading state.
    • Buttons now display a spinner and modified visual cues during active processes, such as post updates and sign-in submissions, providing clearer feedback to users.

@coderabbitai
Copy link

coderabbitai bot commented Mar 8, 2025

Walkthrough

The changes introduce a new isLoading prop to the Button component. The prop is integrated into the component’s interface with a default value of false, and when active, it triggers a variant that applies a cursor-progress style and renders a loading spinner. Additionally, the Button component is now utilized in form routes to reflect loading states during submissions by passing in the new prop based on navigation or fetcher states.

Changes

Files Change Summary
app/components/ui/button.tsx Introduced isLoading prop with default false, updated component props and signature, added a variant that applies cursor-progress style, and renders a loading spinner.
app/routes/.../posts.$id.edit/route.tsx & app/routes/.../sign_in/route.tsx Integrated the Button's new isLoading prop by using useNavigation (and fetcher state) to trigger loading feedback during form submissions.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant P as Parent Component
    participant B as Button Component
    participant S as Spinner

    U->>P: Submits form
    P->>B: Pass isLoading value (true/false)
    alt isLoading true
        B->>B: Apply "cursor-progress" styling
        B->>S: Render loading spinner
    else isLoading false
        B->>B: Render children normally
    end
Loading

Poem

I’m a rabbit bouncing with glee,
Watching our button set itself free,
With a spinner that twirls in a dance so neat,
Loading states now look extra sweet,
In code meadows, I hop with mirth—what a treat! 🐇🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e4b04e8 and 065704b.

📒 Files selected for processing (3)
  • app/components/ui/button.tsx (3 hunks)
  • app/routes/$handle+/posts.$id.edit/route.tsx (3 hunks)
  • app/routes/auth+/sign_in/route.tsx (1 hunks)
🔇 Additional comments (11)
app/components/ui/button.tsx (7)

1-1: Good addition of the Slottable import

The addition of Slottable from Radix UI is appropriate for the new loading state implementation, allowing child elements to render correctly alongside the loading spinner.


29-31: Well-implemented loading state variant

The cursor-progress class is a good choice for indicating loading state to users through the cursor appearance.


36-37: Proper default configuration for loading state

Setting isLoading: false as the default variant is the correct approach to ensure buttons don't show loading state by default.


46-48: Good function signature update

The explicit inclusion of children in the function parameters and setting a default value for isLoading follows best practices.


52-53: Proper type definition for the loading state

The optional boolean type for isLoading correctly reflects the component's API.


59-60: Correct inclusion of loading state in className computation

The buttonVariants function now properly incorporates the isLoading state when determining the button's styling.


62-66: Well-implemented loading spinner with proper child handling

The loading spinner implementation is clean and efficient:

  1. Only renders when isLoading is true
  2. Uses an animated border technique which is lightweight
  3. Wraps children in Slottable to ensure proper rendering alongside the spinner
app/routes/$handle+/posts.$id.edit/route.tsx (3)

9-9: Good addition of useNavigation hook

Adding the useNavigation hook from react-router provides access to navigation state, which is necessary to implement the loading state integration.


98-98: Proper initialization of navigation state

The navigation state is correctly initialized using the useNavigation hook.


134-135: Good implementation of loading state in button

The button correctly shows loading state during form submission, enhancing user experience by providing visual feedback during asynchronous operations.

app/routes/auth+/sign_in/route.tsx (1)

38-42: Effective integration of loading state in sign-in form

The Button component correctly reflects loading state based on the fetcher's current state, providing valuable visual feedback during the authentication process.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

github-actions bot commented Mar 8, 2025

Visit the preview URL for this PR (updated for commit 065704b):

https://remix-spa-example--pr20-feat-is-loading-xmoh8r6l.web.app

(expires Sat, 15 Mar 2025 05:19:29 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 48e666b485811f0b1bcd4fa4838b32a205a3ce05

@coji coji merged commit 5a9d5b7 into main Mar 8, 2025
2 checks passed
@coji coji deleted the feat/is-loading branch March 8, 2025 05:23
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.

1 participant