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

Implement clean up space #119

Merged
merged 9 commits into from
Jan 21, 2025
Merged

Implement clean up space #119

merged 9 commits into from
Jan 21, 2025

Conversation

cp-pratik-k
Copy link
Member

@cp-pratik-k cp-pratik-k commented Jan 17, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new "Clean Up" feature to help users manage and delete media.
    • Introduced a dedicated Clean Up screen for media management.
    • Added localized tab titles for Home, Transfer, Albums, and Accounts.
    • Implemented a new option in account settings for media cleanup.
  • Improvements

    • Enhanced localization support for tab labels.
    • Improved media deletion process with better error handling.
    • Added new database functionality for tracking media cleanup.
  • User Interface

    • Updated main screen with localized tab titles.
    • Implemented a grid view for selecting media to delete.
    • Added user-facing messages for the clean-up feature.
    • Enhanced the presentation of media metadata with a modal bottom sheet layout.

Copy link

coderabbitai bot commented Jan 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces a comprehensive clean-up feature for media management. The changes span multiple components, including localization, UI screens, state management, routing, and database services. A new "Clean Up" functionality is added, allowing users to view and delete media items across different providers. The implementation includes a dedicated screen, state notifier, route, and database management for tracking media that can be cleaned up.

Changes

File Change Summary
app/assets/locales/app_en.arb Added localization entries for tab titles and clean-up screen
app/lib/ui/flow/accounts/components/settings_action_list.dart Added clean-up media action to settings list
app/lib/ui/flow/clean_up/* Created new clean-up screen, state notifier, and related components
app/lib/ui/navigation/app_route.dart Added new route for clean-up screen
data/lib/domain/config.dart Added cleanUpDatabaseName and cleanUpTable constants
data/lib/models/clean_up/* Created CleanUpMedia model with Freezed and JSON serialization
data/lib/services/local_media_service.dart Added methods for managing clean-up media database
data/lib/repositories/media_process_repository.dart Updated upload methods to track media for cleanup
data/lib/services/google_drive_service.dart Fixed query string formatting in media retrieval methods
data/lib/services/local_media_service.dart Added new methods for managing a clean-up database

Sequence Diagram

sequenceDiagram
    participant User
    participant SettingsScreen
    participant CleanUpScreen
    participant CleanUpStateNotifier
    participant LocalMediaService
    participant Database

    User->>SettingsScreen: Tap "Clean Up" action
    SettingsScreen->>CleanUpScreen: Navigate
    CleanUpScreen->>CleanUpStateNotifier: Load clean-up medias
    CleanUpStateNotifier->>LocalMediaService: Retrieve media
    LocalMediaService->>Database: Query clean-up media
    Database-->>LocalMediaService: Return media list
    LocalMediaService-->>CleanUpStateNotifier: Return media list
    CleanUpStateNotifier-->>CleanUpScreen: Update UI with media
    User->>CleanUpScreen: Select media to delete
    User->>CleanUpScreen: Tap delete button
    CleanUpScreen->>CleanUpStateNotifier: Delete selected media
    CleanUpStateNotifier->>LocalMediaService: Remove media
    LocalMediaService->>Database: Delete media entries
Loading

Possibly related PRs

  • Implement clean up space #119: The main PR introduces new localization entries related to a clean-up feature, which aligns with the changes in the retrieved PR that implements the clean-up space functionality, including the addition of a CleanUpScreen and related state management.
  • Account Ui Improvement #76: This PR modifies the SettingsActionList to include a clean-up action, which is directly related to the clean-up functionality introduced in the main PR.
  • Improve auto backup flow #60: Although primarily focused on auto backup, this PR's changes in media handling may relate to the clean-up processes introduced in the main PR, as both involve media management.

Poem

🐰 A Rabbit's Clean-Up Ballad 🧹

In folders dark and cluttered wide,
Where forgotten memories reside,
A clean-up feature now takes flight,
Sweeping pixels left and right!

Tap and clear with bunny might! 🐾


📜 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 c21a1f9 and 80286ef.

📒 Files selected for processing (8)
  • app/lib/ui/flow/clean_up/clean_up_state_notifier.dart (1 hunks)
  • app/lib/ui/flow/media_metadata_details/media_metadata_details.dart (1 hunks)
  • app/lib/ui/flow/media_preview/components/top_bar.dart (2 hunks)
  • app/lib/ui/flow/media_preview/media_preview_screen.dart (5 hunks)
  • app/lib/ui/navigation/app_route.dart (3 hunks)
  • app/lib/ui/navigation/app_route.g.dart (2 hunks)
  • data/lib/services/local_media_service.dart (2 hunks)
  • style/lib/animations/dismissible_page.dart (3 hunks)

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 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.

@cp-pratik-k cp-pratik-k changed the title Delete after upload Implement clean up space screen Jan 17, 2025
@cp-pratik-k cp-pratik-k changed the title Implement clean up space screen Implement clean up space Jan 17, 2025
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: 12

🧹 Nitpick comments (5)
data/lib/services/local_media_service.dart (1)

109-124: Consider adding indexes for frequently queried columns.

The table creation looks good, but consider adding indexes on provider and created_at columns as they are likely to be frequently used in WHERE clauses and sorting operations.

 await db.execute(
   'CREATE TABLE IF NOT EXISTS ${LocalDatabaseConstants.cleanUpTable} ('
   'id TEXT PRIMARY KEY, '
   'provider TEXT NOT NULL, '
   'created_at TEXT NOT NULL, '
   'provider_ref_id TEXT'
   ')',
 );
+await db.execute(
+  'CREATE INDEX IF NOT EXISTS idx_cleanup_provider ON ${LocalDatabaseConstants.cleanUpTable}(provider)'
+);
+await db.execute(
+  'CREATE INDEX IF NOT EXISTS idx_cleanup_created_at ON ${LocalDatabaseConstants.cleanUpTable}(created_at)'
+);
data/lib/models/clean_up/clean_up.freezed.dart (1)

24-24: Consider using camelCase for Dart property names.

The properties provider_ref_id and created_at use snake_case naming, which deviates from Dart naming conventions. Consider using camelCase:

  • providerRefId
  • createdAt

Also applies to: 47-47, 102-104, 211-213

app/lib/ui/flow/home/home_screen_view_model.dart (1)

631-636: Good improvement to deletion error handling.

The changes properly handle deletion results and prevent unnecessary notifications for failed deletions. Consider adding a debug log when returning early to help with troubleshooting.

     final res = await _localMediaService.deleteMedias(ids);

-    if (res.isEmpty) return;
+    if (res.isEmpty) {
+      _logger.d("No media was deleted successfully");
+      return;
+    }
data/lib/models/clean_up/clean_up.dart (2)

13-16: Use camelCase for field names to follow Dart conventions

The fields are currently named using snake_case, which is against Dart naming conventions. Consider renaming them to camelCase for consistency and maintainability. Use @JsonKey annotations to map the JSON keys.

Apply this diff to rename the fields:

       const factory CleanUpMedia({
           required String id,
-          String? provider_ref_id,
+          @JsonKey(name: 'provider_ref_id') String? providerRefId,
           required AppMediaSource provider,
-          @DateTimeJsonConverter() required DateTime created_at,
+          @DateTimeJsonConverter() @JsonKey(name: 'created_at') required DateTime createdAt,
         }) = _CleanUpMedia;

Also, update references to these fields throughout the codebase.


1-1: Remove unnecessary ignore comment

After renaming the fields to follow Dart conventions, the ignore_for_file directive is no longer needed.

Apply this diff to remove the unnecessary comment:

-// ignore_for_file: non_constant_identifier_names
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b1522f1 and e9f8eb5.

📒 Files selected for processing (17)
  • app/assets/locales/app_en.arb (2 hunks)
  • app/lib/ui/flow/accounts/components/settings_action_list.dart (2 hunks)
  • app/lib/ui/flow/clean_up/clean_up_screen.dart (1 hunks)
  • app/lib/ui/flow/clean_up/clean_up_state_notifier.dart (1 hunks)
  • app/lib/ui/flow/clean_up/clean_up_state_notifier.freezed.dart (1 hunks)
  • app/lib/ui/flow/home/home_screen_view_model.dart (1 hunks)
  • app/lib/ui/flow/main/main_screen.dart (2 hunks)
  • app/lib/ui/flow/media_preview/media_preview_view_model.dart (1 hunks)
  • app/lib/ui/navigation/app_route.dart (3 hunks)
  • app/lib/ui/navigation/app_route.g.dart (2 hunks)
  • data/lib/domain/config.dart (1 hunks)
  • data/lib/models/clean_up/clean_up.dart (1 hunks)
  • data/lib/models/clean_up/clean_up.freezed.dart (1 hunks)
  • data/lib/models/clean_up/clean_up.g.dart (1 hunks)
  • data/lib/repositories/media_process_repository.dart (3 hunks)
  • data/lib/services/google_drive_service.dart (1 hunks)
  • data/lib/services/local_media_service.dart (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • data/lib/models/clean_up/clean_up.g.dart
  • data/lib/services/google_drive_service.dart
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (10)
app/lib/ui/flow/clean_up/clean_up_screen.dart (1)

16-41: LGTM! Well-structured implementation with proper state management.

The screen is properly implemented with:

  • Clean separation of concerns using Riverpod
  • Proper error handling through state observation
app/lib/ui/flow/accounts/components/settings_action_list.dart (1)

15-15: LGTM! Clean implementation of the clean-up action.

The implementation follows the established patterns:

  • Consistent with other action items in the list
  • Proper use of localization
  • Clear navigation logic

Also applies to: 28-28, 36-51

app/assets/locales/app_en.arb (1)

166-167: LGTM! Well-structured localization entries.

The new clean-up related messages are:

  • Properly organized under a dedicated section
  • Follow consistent naming patterns
  • Use friendly and clear language

Also applies to: 168-172

data/lib/models/clean_up/clean_up.freezed.dart (1)

1-236: LGTM! Well-structured data model.

The CleanUpMedia model is well-implemented with:

  • Proper immutability using Freezed
  • Correct use of JSON serialization
  • Appropriate handling of DateTime using converter
app/lib/ui/navigation/app_route.g.dart (1)

12-12: LGTM! Clean implementation of the clean-up route.

The route implementation:

  • Follows the established routing patterns
  • Provides all necessary navigation methods
  • Uses a consistent path format

Also applies to: 153-173

app/lib/ui/flow/clean_up/clean_up_state_notifier.freezed.dart (1)

17-32: Well-structured state management for clean-up feature.

The state implementation properly tracks all necessary aspects of the clean-up process including:

  • Deletion loading states (both bulk and selected items)
  • Media items and selections
  • Error handling
app/lib/ui/flow/clean_up/clean_up_state_notifier.dart (1)

40-40: Ensure the nonNulls extension method is available

The use of value.nonNulls.toList() assumes the presence of a nonNulls extension method. Please verify that this extension is imported and available in the context to prevent runtime errors.

Run the following script to confirm the availability of the nonNulls extension:

✅ Verification successful

nonNulls is a built-in Dart extension method

The nonNulls extension method is a built-in Dart feature available on Iterable<T?> that filters out null values. Its widespread use across the codebase confirms it's working as expected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for the definition of 'nonNulls' extension method.

# Search the codebase for 'nonNulls' extension.
rg --type dart --word-regexp 'extension.*nonNulls'

Length of output: 52


Script:

#!/bin/bash
# Search for any occurrence of nonNulls
echo "=== Searching for nonNulls usage ==="
rg --type dart "nonNulls"

echo -e "\n=== Checking imports in the file ==="
cat "app/lib/ui/flow/clean_up/clean_up_state_notifier.dart"

echo -e "\n=== Looking for extension method definitions ==="
ast-grep --pattern 'extension $_ {
  $$$
  nonNulls$_ {
    $$$
  }
  $$$
}'

Length of output: 5168

data/lib/domain/config.dart (1)

16-16: LGTM

The addition of cleanUpTable aligns with existing naming conventions in LocalDatabaseConstants.

app/lib/ui/flow/main/main_screen.dart (1)

7-7: LGTM! Good localization improvements.

The changes properly implement localization for tab labels using context.l10n, making the app more maintainable and ready for internationalization.

Also applies to: 28-28, 33-33, 38-38, 43-43

app/lib/ui/navigation/app_route.dart (1)

23-23: LGTM! Clean route implementation.

The new clean up route follows the established patterns:

  • Consistent path naming
  • Proper use of TypedGoRoute annotation
  • Matches the structure of other routes in the file

Also applies to: 81-88

data/lib/services/local_media_service.dart Outdated Show resolved Hide resolved
data/lib/services/local_media_service.dart Outdated Show resolved Hide resolved
data/lib/services/local_media_service.dart Outdated Show resolved Hide resolved
data/lib/services/local_media_service.dart Outdated Show resolved Hide resolved
app/lib/ui/flow/clean_up/clean_up_screen.dart Show resolved Hide resolved
app/lib/ui/flow/clean_up/clean_up_state_notifier.dart Outdated Show resolved Hide resolved
app/lib/ui/flow/clean_up/clean_up_state_notifier.dart Outdated Show resolved Hide resolved
app/lib/ui/flow/clean_up/clean_up_state_notifier.dart Outdated Show resolved Hide resolved
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 (1)
data/lib/services/local_media_service.dart (1)

109-124: Consider adding indexes for query optimization.

While the schema is well-structured, consider adding indexes on frequently queried columns like provider and created_at to improve query performance.

 await db.execute(
   'CREATE TABLE IF NOT EXISTS ${LocalDatabaseConstants.cleanUpTable} ('
   'id TEXT PRIMARY KEY, '
   'provider TEXT NOT NULL, '
   'created_at TEXT NOT NULL, '
   'provider_ref_id TEXT'
   ')',
 );
+await db.execute(
+  'CREATE INDEX IF NOT EXISTS idx_cleanup_provider '
+  'ON ${LocalDatabaseConstants.cleanUpTable}(provider)'
+);
+await db.execute(
+  'CREATE INDEX IF NOT EXISTS idx_cleanup_created_at '
+  'ON ${LocalDatabaseConstants.cleanUpTable}(created_at)'
+);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e9f8eb5 and c21a1f9.

📒 Files selected for processing (2)
  • data/lib/domain/config.dart (1 hunks)
  • data/lib/services/local_media_service.dart (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (5)
data/lib/domain/config.dart (1)

13-13: LGTM! Constants follow existing naming patterns.

The new database and table name constants follow the established naming conventions and are appropriately placed within the configuration file.

Also applies to: 17-17

data/lib/services/local_media_service.dart (4)

126-138: Previous review comment is still applicable.

The suggestions about adding error handling and ensuring database closure are still relevant.


140-147: Previous review comment is still applicable.

The suggestions about input validation and ensuring database closure are still relevant.


149-152: Previous review comment is still applicable.

The suggestion about ensuring database closure is still relevant.


154-159: Previous review comment is still applicable and consider adding consistent sorting.

  1. The suggestions about pagination and ensuring database closure are still relevant.
  2. Additionally, consider adding a consistent sort order to ensure predictable results.
 Future<List<CleanUpMedia>> getCleanUpMedias() async {
   final database = await openCleanUpDatabase();
-  final res = await database.query(LocalDatabaseConstants.cleanUpTable);
+  final res = await database.query(
+    LocalDatabaseConstants.cleanUpTable,
+    orderBy: 'created_at DESC',
+  );
   return res.map((e) => CleanUpMedia.fromJson(e)).toList();
 }

@cp-pratik-k cp-pratik-k merged commit 8908a7b into main Jan 21, 2025
2 checks passed
@cp-pratik-k cp-pratik-k deleted the delete-after-upload branch January 22, 2025 09:08
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