Skip to content

Refatcor sync teh dashboard logic and UI with updated models #27

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

Merged

Conversation

fulleni
Copy link
Member

@fulleni fulleni commented Jul 13, 2025

Status

READY/IN DEVELOPMENT/HOLD

Description

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

fulleni added 30 commits July 12, 2025 18:26
Replaced all instances of the `Category` model with the new `Topic` model in the dependency injection setup.

- Updated `HtDataClient` and `HtDataRepository` to use `Topic`.
- Renamed `categoriesClient` and `categoriesRepository` to `topicsClient` and `topicsRepository` respectively.
- Updated `HtDataInMemory` and `HtDataApi` instantiations for the `Topic` model, including the model name for API calls.
- Updated the `App` widget instantiation to pass the new `htTopicsRepository`.
- Removed `.map(Type.fromJson).toList()` calls.
- Simplified data initialization.
- Improved code readability.
- Minor performance optimization.
- No functional changes.
Replaced all instances of the `AppConfig` model with the new `RemoteConfig` model in the dependency injection setup.

- Updated `HtDataClient` and `HtDataRepository` to use `RemoteConfig`.
- Renamed `appConfigClient` and `appConfigRepository` to `remoteConfigClient` and `remoteConfigRepository` respectively.
- Updated `HtDataInMemory` and `HtDataApi` instantiations for the `RemoteConfig` model, including the model name for API calls.
- Updated the `App` widget instantiation to pass the new `htRemoteConfigRepository`.
Replaced all instances of the `AppConfig` model with the new `RemoteConfig` model in the dependency injection setup.

- Updated `HtDataClient` and `HtDataRepository` to use `RemoteConfig`.
- Renamed `appConfigClient` and `appConfigRepository` to `remoteConfigClient` and `remoteConfigRepository` respectively.
- Updated `HtDataInMemory` and `HtDataApi` instantiations for the `RemoteConfig` model, including the model name for API calls.
- Updated the `App` widget instantiation to pass the new `htRemoteConfigRepository`.
Migrated the App widget to use the new `Topic` and `RemoteConfig` models.

- Updated the `App` widget constructor to accept `HtDataRepository<Topic>` and `HtDataRepository<RemoteConfig>`.
- Updated the `MultiRepositoryProvider` to provide the new repositories to the widget tree.
- Updated the `MultiBlocProvider` to inject the correct repositories into the `AppBloc`, `ContentManagementBloc`, `AppConfigurationBloc`, and `DashboardBloc`.
- Renamed conflicting AppStatus
- Updated import statements
Refactored the `AppBloc` to align with recent model changes.

- Replaced `HtDataRepository<AppConfig>` with `HtDataRepository<RemoteConfig>`.
- Updated the user role check in `_onAppUserChanged` to use the new `user.dashboardRole` enum.
- Implemented the creation of a complete, default `UserAppSettings` object in the `NotFoundException` catch block, providing all required fields.
Refactors the events for the CreateHeadlineBloc to align with the
`Headline` data model and the BLoC's event handlers.

- Renames `CreateHeadlineDescriptionChanged` to `CreateHeadlineExcerptChanged`
  to match the `Headline.excerpt` field.
- Replaces the incorrect `CreateHeadlineCategoryChanged` (which used a
  non-existent `Category` model) with `CreateHeadlineTopicChanged` and
  `CreateHeadlineCountryChanged` to correctly handle `Topic` and `Country`
  selection.

This resolves the compilation errors and ensures the BLoC components
are in sync.
Corrects two issues in `CreateHeadlineBloc`:

1.  Resolves `argument_type_not_assignable` errors in the `_onDataLoaded`
    handler. The type inference for `Future.wait` was too broad, causing
    the resulting lists to be typed as `List<FeedItem>`. The fix is to
    explicitly cast the `PaginatedResponse` objects to their correct
    concrete types before accessing the `.items` property.

2.  Removes an erroneous `hide Topic` clause from the `foundation.dart`
    import, which was causing an `undefined_hidden_name` warning.
Corrects several type and logic errors in the CreateSourceBloc that
prevented a new Source from being created.

- Updates `isFormValid` in `CreateSourceState` to correctly check for
  all required fields (`url`, `sourceType`, `headquarters`).
- In `CreateSourceBloc`, injects a `Uuid` to generate the required `id`
  for the new `Source` instance.
- Fixes type mismatches during `Source` instantiation by passing
  non-nullable values from the state, which is now safe due to the
  improved form validation.
Updates the `isFormValid` getter in `CreateTopicState` to correctly
validate all required fields (`name`, `description`, `iconUrl`) from the
`Topic` data model.

This ensures that the form cannot be submitted with incomplete data,
preventing the creation of invalid `Topic` objects.
Refactors the events for the EditHeadlineBloc to align with the
current `Headline` data model.

- Renames `EditHeadlineDescriptionChanged` to `EditHeadlineExcerptChanged`
  to match the `Headline.excerpt` field.
- Replaces the outdated `EditHeadlineCategoryChanged` with two new events,
  `EditHeadlineTopicChanged` and `EditHeadlineCountryChanged`, to
  correctly handle topic and country selection.
Refactors `EditHeadlineState` to align with the current `Headline`
data model and its dependencies.

- Renames the `description` field to `excerpt`.
- Replaces the outdated `category` and `categories` fields with `topic`,
  `eventCountry`, `topics`, and `countries` to correctly handle topic
  and country data.
- Updates the `isFormValid` getter to validate all required fields
  from the `Headline` model, ensuring form integrity.
- Adjusts the `copyWith` method and `props` to reflect these changes.
Refactors the `EditHeadlineBloc` to align with the current `Headline`
data model and its dependencies.

- Updates the constructor to inject repositories for `Topic` and `Country`
  instead of the outdated `Category` repository.
- Refactors the `_onLoaded` handler to fetch `topics` and `countries`
  and correctly maps `headline.excerpt` to the state.
- Updates event handlers to use the new `EditHeadlineExcerptChanged`,
  `EditHeadlineTopicChanged`, and `EditHeadlineCountryChanged` events.
- Refactors the `_onSubmitted` handler to build the updated `Headline`
  object using the correct fields (`excerpt`, `topic`, `eventCountry`).
Updates the `isFormValid` getter in `EditSourceState` to correctly
validate all required fields from the `Source` model (`name`,
`description`, `url`, `sourceType`, `language`, `headquarters`).

This prevents the submission of incomplete data and aligns the form
logic with the data model's constraints.
Refactors the `EditSourceBloc` to correctly handle the non-nullable
fields of the `Source` data model.

- In the `_onLoaded` handler, removes redundant null-coalescing
  operators for `description`, `url`, and `language`, as these fields
  are guaranteed to be non-nullable `String`s in the `Source` model.
- In the `_onSubmitted` handler, corrects the update logic by passing
  state properties directly to `copyWith`. This fixes a bug that
  prevented fields from being updated to an empty string and relies on
  the more robust form validation in the state.
fulleni added 26 commits July 13, 2025 12:08
Updates the remaining user-facing description strings in `app_en.arb`
to replace "categories" with "topics". This ensures the localization
file is fully consistent with the application's data model.
Updates the arabic localization file (`app_ar.arb`) to reflect the
application-wide migration from "Category" to "Topic".

This involves renaming all relevant keys and updating all user-facing
strings to ensure the UI is consistent with the new data model.
- Updated English, Arabic translations
- Changed "category" to "topic" in UI
- Updated related descriptions and labels
- Corrected loading and error messages
- Reflected changes in dashboard summary
- Added 'excerpt' and 'countryName' fields
- Updated translations for all locales
- Updated ARB files with descriptions
- Renamed category to topic in routes
- Updated route paths and names
- Renamed `appConfig` to `remoteConfig`
- Renamed `originalAppConfig` to `originalRemoteConfig`
- Updated usage in `AppConfigurationState`
- Renamed `appConfig` to `remoteConfig`
- Updated event props accordingly
- Improved code clarity and consistency
- Renamed `AppConfig` to `RemoteConfig`
- Updated repository and bloc usage
- Adjusted variable names accordingly
- Ensured consistent naming throughout
- Updated comments for clarity
- Renamed `AppConfig` to `RemoteConfig`
- Updated variable names accordingly
- Replaced `UserRoles` with `AppUserRole`
- Removed Force Update section
- Improved App Status section
- Added translations for app statuses:
  Maintenance, Operational.
- Added translations for update URLs:
  iOS and Android.
- Improved app status descriptions.
- Added labels and descriptions for update URL fields.
- Removed obsolete `helloWorld` translation.
- Replaced AppUserRole enum with string comparisons.
- Improved code readability and maintainability.
- Fixed potential issues with enum usage.
- Simplified switch statement logic.
- No functional changes.
- Removed unnecessary 'none', 'admin', and 'publisher' cases.
- Simplified conditional rendering logic.
- Improved code readability.
- Improved code readability and maintainability.
- Removed unnecessary DropdownButtonFormField.
- Simplified UserPreferenceLimitsForm and AdConfigForm.
- Updated AppUserRole type to enum.
- Consolidated similar code blocks.
- Improved anonymous user handling.
- Added logging for error handling.
- Created default settings based on user ID.
- Improved error handling during settings load.
- Enhanced user app settings management.
- Replaced direct method call with lambda.
- Improved code readability and maintainability.
- Added Logger to AppBloc
- Improved repository names
- Added doc comment to _AppView
- Updated themeMode switch
- Minor code style improvements
- Replaced AuthenticationUserChanged with
  AuthenticationStatusChanged.
- Updated state management to use
  AuthenticationStatus enum.
- Improved error handling and feedback.
- Enhanced code clarity and readability.
- Standardized error message handling.
- Improved code readability.
- Removed unnecessary line breaks.
- Improved error message display.
- Updated loading indicator logic.
- Refined UI layout and spacing.
- Enhanced code readability.
- Used AppTheme for color consistency.
- Improved error handling in UI.
- Updated state management for clarity.
- Replaced direct state checks with enum.
- Removed unnecessary import of `AppTheme`.
- Improved code cleanliness.
- Changed appConfig type from AppConfig to RemoteConfig
- Updated AppConfig type to RemoteConfig
- Adjusted repository type accordingly
- Modified data fetching logic
- Improved data handling consistency
- Minor code cleanup
- Renamed "Headlines" to "Topics"
- Updated system status display logic
- Improved quick actions button labels
- Replaced `RemoteAppStatus` with `AppStatus`
- Updated icons for better clarity
- Added default settings on creation
- Improved error handling
- Added DisplaySettings, FeedDisplayPreferences
- Used default values for user settings
- Updated UserAppSettings model
@fulleni fulleni merged commit e23e19c into main Jul 13, 2025
1 check failed
@fulleni fulleni deleted the refatcor_sync_teh_dashboard_logic_and_ui_with_updated_models branch July 13, 2025 17:16
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @fulleni, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on a significant refactoring of the dashboard's logic and UI to synchronize with updated data models. It involves renaming core entities, enhancing content management capabilities with new fields and dedicated UIs, and overhauling application state management for better consistency and maintainability. The changes also centralize app configuration, integrate improved logging, and update various dependencies.

Highlights

  • Core Model Updates: The Category data model has been renamed to Topic across the application, including its associated repositories, BLoCs, and UI components. Similarly, AppConfig has been updated to RemoteConfig to better reflect its purpose as a dynamic configuration source.
  • Enhanced Content Management: Headline entities now include new fields such as excerpt (replacing description) and eventCountry. Dedicated BLoCs and UI pages have been introduced for the creation and editing of Topic entities, providing a more structured approach to managing content categories.
  • Refactored Application State: The AuthenticationBloc has undergone a significant refactor, consolidating its various states into a single AuthenticationState class managed by an AuthenticationStatus enum. This simplifies state transitions and improves consistency. The AppBloc's user role checking logic has also been updated to align with new DashboardUserRole and AppUserRole enums.
  • Centralized App Configuration: Application operational status and update settings are now managed more cohesively within the RemoteConfig model, specifically through a new AppStatus sub-model. This streamlines the configuration management UI and logic.
  • Improved Logging and Data Handling: The logging package has been integrated across key BLoCs for more structured and informative logging. Data fetching operations now consistently utilize PaginationOptions and SortOption objects for clearer and more flexible querying.
  • Dependency and Tooling Updates: Several internal ht- package dependencies have been updated to their latest versions, and new external dependencies like logging and uuid have been introduced to support new features and improved practices.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant refactoring to align the application with updated data models. Key improvements include replacing multiple BLoC state classes with a single state and status enum pattern and introducing logging. I've identified a likely bug in the dashboard summary display and an area where code can be made more robust. My comments focus on these points. Overall, this is a great step forward for the codebase.

Comment on lines +68 to +75
icon: Icons.category_outlined,
title: l10n.totalTopics,
value: summary.topicCount.toString(),
),
_SummaryCard(
icon: Icons.category_outlined,
title: l10n.totalCategories,
value: summary.categoryCount.toString(),
title: l10n.totalTopics,
value: summary.topicCount.toString(),

Choose a reason for hiding this comment

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

high

It appears there might be a copy-paste error here. Two _SummaryCard widgets are created with the same icon, title (l10n.totalTopics), and value (summary.topicCount.toString()). The first card was likely intended to display a different metric, such as the total number of headlines. Please verify the intended metrics for the summary cards.

                      _SummaryCard(
                        icon: Icons.article_outlined,
                        title: l10n.totalHeadlines,
                        value: summary.headlineCount.toString(),
                      ),

ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(
SnackBar(
content: Text(
// Provide a more user-friendly error message if possible
state.errorMessage,
state.errorMessage!,

Choose a reason for hiding this comment

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

medium

Using the non-null assertion operator (!) on state.errorMessage can lead to runtime errors if the state is ever failure without an errorMessage. It's safer to provide a fallback value using the null-coalescing operator (??).

This pattern is also present in email_code_verification_page.dart and request_code_page.dart and should be addressed there as well.

                      state.errorMessage ?? l10n.unknownError

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