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

Fix: Implemented smooth handling of states #2491

Merged
merged 2 commits into from
Feb 23, 2025
Merged

Conversation

Karagwa
Copy link
Contributor

@Karagwa Karagwa commented Feb 20, 2025

Summary of Changes (What does this PR do?)

  • Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Status of maturity (all need to be checked before merging):

  • I've tested this locally
  • I consider this code done
  • This change ready to hit production in its current state
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included issue number in the "Closes #ISSUE-NUMBER" part of the "What are the relevant tickets?" section to link the issue.
  • I've updated corresponding documentation for the changes in this PR.
  • I have written unit and/or e2e tests for my change(s).

How should this be manually tested?

  • Please include the steps to be done inorder to setup and test this PR.

What are the relevant tickets?

Screenshots (optional)

Summary by CodeRabbit

  • New Features

    • Enhanced the authentication flow to provide clear visual feedback during loading, guest, authenticated, and error states.
    • Improved the dashboard experience by displaying a consistent greeting message that adjusts based on the authentication status.
  • Style

    • Refined greeting text formatting for better readability.

Copy link

coderabbitai bot commented Feb 20, 2025

📝 Walkthrough

Walkthrough

The changes refactor the authentication flow across the mobile application. The Decider UI component now uses a BlocBuilder to switch between different screens based on authentication states instead of relying on a FutureBuilder and token lookup via Hive. In parallel, the AuthBloc has been enhanced with dedicated asynchronous methods to handle events, and the authentication state transitions have been made more explicit. The DashboardPage widget is updated to display specific greeting messages during various authentication stages, ensuring consistent user feedback.

Changes

File(s) Change Summary
mobile-v3/lib/main.dart
mobile-v3/lib/src/app/dashboard/pages/dashboard_page.dart
Updated UI components to use BlocBuilder for managing authentication states (AuthLoading, GuestUser, AuthLoaded, AuthLoadingError); removed connectivity logic; added and refined greeting/error messages.
mobile-v3/lib/src/app/auth/bloc/auth_bloc.dart Refactored event handling by introducing dedicated asynchronous methods (_onAppStarted, _onLoginUser, _onRegisterUser); removed the artificial delay; improved error extraction via a private helper method.

Possibly related PRs

  • Enhance authentication flow with loading indicators and error handlin… #2346: The changes in the main PR are related to the modifications in the Decider class's implementation, which directly impacts how authentication states are managed, while the retrieved PR also alters the Decider class's handling of authentication token retrieval, indicating a strong connection at the code level.
  • Refactor authentication handling and remove unused token validation l… #2378: The changes in the main PR are related to the modifications in the Decider class's implementation, which also affects the authentication handling in the main.dart file, while the retrieved PR focuses on removing error handling and token validation logic in the same file.
  • Feedback address #2466: The changes in the main PR are related to the modifications in the AuthBloc class and the handling of authentication states, which are also addressed in the retrieved PR through the restructuring of the AuthBloc and the introduction of the AppStarted event.

Suggested reviewers

  • Baalmart
  • Mozart299

Poem

In the code's gentle stream,
New flows replace the old regime.
Bloc takes charge with states so clear,
Loading, error, guest appear.
A refactored dance in our digital dream!
🚀✨

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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 or @coderabbitai title 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (5)
mobile-v3/lib/main.dart (2)

215-234: Consider reintroducing the connectivity banner or removing ConnectivityBloc.

Your new implementation omits the NoInternetBanner, yet the ConnectivityBloc remains in use. This can introduce confusion for maintainers. If you're no longer showing network warnings, either remove the ConnectivityBloc to reduce complexity or reintroduce the banner to maintain offline handling.


236-247: Display a dedicated error experience for better user feedback.

You're returning a scaffolded error text here, which is acceptable, but consider providing a more descriptive error screen or UX flow (like a retry button or contact support message) to guide users effectively when authentication fails.

mobile-v3/lib/src/app/dashboard/pages/dashboard_page.dart (3)

212-226: Refine fallback when no user data is loaded.

If AuthLoaded is triggered but user data is still unavailable, showing "Hi, 👋🏼" may confuse users. Consider adding a temporary placeholder or a loading indicator to clarify that user info is still being retrieved.


237-247: Use a clear message for error states.

Returning the same greeting as other states makes it difficult to distinguish errors from normal usage. Provide a distinct error message or a remediation step so the user understands what went wrong.


249-258: Minimize repeated greetings in fallback states.

Multiple states default to "Hi, 👋🏼". To enhance maintainability and keep the UX consistent, consider extracting a dedicated fallback widget or message. This approach reduces duplication and simplifies future enhancements.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bd111b5 and f81cad4.

📒 Files selected for processing (3)
  • mobile-v3/lib/main.dart (2 hunks)
  • mobile-v3/lib/src/app/auth/bloc/auth_bloc.dart (1 hunks)
  • mobile-v3/lib/src/app/dashboard/pages/dashboard_page.dart (4 hunks)
🔇 Additional comments (1)
mobile-v3/lib/src/app/auth/bloc/auth_bloc.dart (1)

74-74: Verify that removing the delay does not cause flicker or race conditions.

If there was no specific reason for the half-second pause, removing it is fine. Otherwise, ensure this change doesn't introduce abrupt UI transitions or race conditions during app startup.

Comment on lines +189 to +199
if (authState is AuthLoading) {

return Text(
"Hi, 👋🏼",
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.w700,
color: Theme.of(context).textTheme.headlineLarge?.color,
),
);
}
Copy link

@coderabbitai coderabbitai bot Feb 20, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Show a loading indicator for consistency during AuthLoading.

At present, you return "Hi, 👋🏼" while the auth state is loading, whereas main.dart displays a spinner for loading. Consider showing a similar spinner here to keep a unified loading experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Mozart299 do i need to do this? Initially the app does not show a loading indicator.

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor

Choose a reason for hiding this comment

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

@Karagwa Don't add anything for now

Copy link
Contributor

Choose a reason for hiding this comment

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

@Karagwa I see you have completely removed the connectivity banner and that error state? why?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Karagwa So what happens when someone has internet issues? how do they get warned about that?

Copy link
Contributor

@Mozart299 Mozart299 left a comment

Choose a reason for hiding this comment

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

Read the comments

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
mobile-v3/lib/main.dart (2)

128-138: Remove commented out theme configuration code.

The commented out theme configuration code should be removed since it's not being used and the app is using AppTheme instead.

-            // theme: isLightTheme ? ThemeData(
-            //     splashColor: Colors.transparent,
-            //     highlightColor: Colors.transparent,
-            //     fontFamily: "Inter",
-            //     useMaterial3: true,
-            //     appBarTheme: AppBarTheme(
-            //         scrolledUnderElevation: 0,
-            //         elevation: 0,
-            //         backgroundColor: Theme.of(context).scaffoldBackgroundColor),
-            //     scaffoldBackgroundColor: Theme.of(context).scaffoldBackgroundColor,
-            //     brightness: Brightness.light),

148-203: Remove commented out old Decider implementation.

The old implementation should be removed since it's been replaced with the new BlocBuilder approach. If needed, this code can be retrieved from version control history.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f81cad4 and ab511f1.

📒 Files selected for processing (1)
  • mobile-v3/lib/main.dart (3 hunks)
🔇 Additional comments (2)
mobile-v3/lib/main.dart (2)

33-63: LGTM! Well-structured initialization with proper error handling.

The main function follows best practices with proper error handling, async initialization, and clean dependency injection.


217-250: LGTM! Improved state management with comprehensive error handling.

The new implementation:

  • Uses BlocBuilder for better state management
  • Handles all authentication states properly
  • Provides clear error messages to users
  • Maintains good debugging with state logging

@Karagwa Karagwa requested a review from Mozart299 February 21, 2025 17:29
@Baalmart Baalmart merged commit e301887 into staging Feb 23, 2025
31 checks passed
@Baalmart Baalmart deleted the FeedbackAddress2 branch February 23, 2025 12:56
@Baalmart Baalmart mentioned this pull request Feb 23, 2025
1 task
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.

3 participants