π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix ui rebuilds and flashing
AmanRajSinghMourya4846f27f4b27
diff --git a/mobile/apps/locker/lib/services/collections/collections_service.dart b/mobile/apps/locker/lib/services/collections/collections_service.dartindex 3893b6c485..5c0ffc0633 100644--- a/mobile/apps/locker/lib/services/collections/collections_service.dart+++ b/mobile/apps/locker/lib/services/collections/collections_service.dart@@ -202,12 +202,21 @@ class CollectionService {}}- Future<void> addToCollection(Collection collection, EnteFile file) async {+ /// Adds a file to a collection. By default this triggers a full sync to+ /// update local state. Set [runSync] to false to delay syncing (useful when+ /// adding the same file to multiple collections during an upload).+ Future<void> addToCollection(+ Collection collection,+ EnteFile file, {+ bool runSync = true,+ }) async {try {await _apiClient.addToCollection(collection, [file]);_logger.info("Added file ${file.title} to collection ${collection.name}");- // Let sync update the local state- await sync();+ if (runSync) {+ // Let sync update the local state+ await sync();+ }} catch (e) {_logger.severe("Failed to add file to collection: $e");rethrow;diff --git a/mobile/apps/locker/lib/ui/pages/home_page.dart b/mobile/apps/locker/lib/ui/pages/home_page.dartindex e4db4f84a9..cf7657dd3b 100644--- a/mobile/apps/locker/lib/ui/pages/home_page.dart+++ b/mobile/apps/locker/lib/ui/pages/home_page.dart@@ -65,7 +65,11 @@ class _HomePageState extends UploaderPageState<HomePage>@overridevoid onFileUploadComplete() {- _loadCollections();+ // No-op: CollectionService.sync() already fires CollectionsUpdatedEvent+ // which triggers a single refresh. Avoid calling _loadCollections here to+ // prevent duplicate reloads / UI blinking when uploading to multiple+ // collections.+ return;}@overridediff --git a/mobile/apps/locker/lib/ui/pages/uploader_page.dart b/mobile/apps/locker/lib/ui/pages/uploader_page.dartindex 96c173dad4..c3768b7158 100644--- a/mobile/apps/locker/lib/ui/pages/uploader_page.dart+++ b/mobile/apps/locker/lib/ui/pages/uploader_page.dart@@ -86,10 +86,13 @@ abstract class UploaderPageState<T extends UploaderPage> extends State<T> {for (int cIndex = 1;cIndex < uploadResult.selectedCollections.length;cIndex++) {+ // Don't trigger a sync for each additional collection β do one+ // sync at the end after all files are processed.futures.add(CollectionService.instance.addToCollection(uploadResult.selectedCollections[cIndex],enteFile,+ runSync: false,),);}@@ -113,8 +116,26 @@ abstract class UploaderPageState<T extends UploaderPage> extends State<T> {if (futures.isNotEmpty) {await progressDialog.show();await Future.wait(futures);- await CollectionService.instance.sync();- onFileUploadComplete();++ // If multiple collections were selected we suppressed per-add syncs+ // (runSync: false) for the additional collections above. In that+ // case we must perform one final sync here and then notify the+ // UI via onFileUploadComplete(). If only a single collection was+ // selected the primary upload path is expected to have already+ // performed any necessary syncs and/or emitted the+ // CollectionsUpdatedEvent, so calling sync() again would be+ // redundant and can cause duplicate UI refreshes.+ final shouldPerformFinalSync = (uploadResult != null &&+ uploadResult.selectedCollections.length > 1);++ if (shouldPerformFinalSync) {+ // Perform the final sync. The sync itself fires+ // CollectionsUpdatedEvent which HomePage listens to and will+ // refresh the UI via _loadCollections(). Do NOT call+ // onFileUploadComplete() here to avoid triggering an additional+ // UI refresh that would duplicate the event-driven update.+ await CollectionService.instance.sync();+ }}} catch (e, s) {_logger.severe('Failed to upload file', e, s);