Skip to content

Commit

Permalink
fix(mobile): simplify state management in backup selection page (immi…
Browse files Browse the repository at this point in the history
…ch-app#5655)

* fix(mobile): simplify album selection backup state management

* remove search bar'

* log available albums
  • Loading branch information
alextran1502 authored Dec 13, 2023
1 parent f7429c3 commit 885eba2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 50 deletions.
2 changes: 1 addition & 1 deletion mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 599d8aeb73728400c15364e734525722250a5382

COCOAPODS: 1.12.1
COCOAPODS: 1.11.3
4 changes: 3 additions & 1 deletion mobile/lib/modules/backup/providers/backup.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ class BackupNotifier extends StateNotifier<BackUpState> {
albumMap[album.id] = album;
}
}

state = state.copyWith(availableAlbums: availableAlbums);

final List<BackupAlbum> excludedBackupAlbums =
Expand Down Expand Up @@ -295,6 +294,9 @@ class BackupNotifier extends StateNotifier<BackUpState> {
excludedBackupAlbums: excludedAlbums,
);

log.info(
"_getBackupAlbumsInfo: Found ${availableAlbums.length} available albums",
);
debugPrint("_getBackupAlbumsInfo takes ${stopwatch.elapsedMilliseconds}ms");
}

Expand Down
91 changes: 43 additions & 48 deletions mobile/lib/modules/backup/views/backup_album_selection_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ class BackupAlbumSelectionPage extends HookConsumerWidget {
final selectedBackupAlbums = ref.watch(backupProvider).selectedBackupAlbums;
final excludedBackupAlbums = ref.watch(backupProvider).excludedBackupAlbums;
final isDarkTheme = context.isDarkTheme;
final allAlbums = ref.watch(backupProvider).availableAlbums;

// Albums which are displayed to the user
// by filtering out based on search
final filteredAlbums = useState(allAlbums);
final albums = filteredAlbums.value;
final albums = ref.watch(backupProvider).availableAlbums;

useEffect(
() {
Expand Down Expand Up @@ -153,47 +148,47 @@ class BackupAlbumSelectionPage extends HookConsumerWidget {
}).toSet();
}

buildSearchBar() {
return Padding(
padding: const EdgeInsets.only(left: 16.0, right: 16, bottom: 8.0),
child: TextFormField(
onChanged: (searchValue) {
if (searchValue.isEmpty) {
filteredAlbums.value = allAlbums;
} else {
filteredAlbums.value = allAlbums
.where(
(album) => album.name
.toLowerCase()
.contains(searchValue.toLowerCase()),
)
.toList();
}
},
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(
horizontal: 8.0,
vertical: 8.0,
),
hintText: "Search",
hintStyle: TextStyle(
color: isDarkTheme ? Colors.white : Colors.grey,
fontSize: 14.0,
),
prefixIcon: const Icon(
Icons.search,
color: Colors.grey,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide.none,
),
filled: true,
fillColor: isDarkTheme ? Colors.white30 : Colors.grey[200],
),
),
);
}
// buildSearchBar() {
// return Padding(
// padding: const EdgeInsets.only(left: 16.0, right: 16, bottom: 8.0),
// child: TextFormField(
// onChanged: (searchValue) {
// // if (searchValue.isEmpty) {
// // albums = availableAlbums;
// // } else {
// // albums.value = availableAlbums
// // .where(
// // (album) => album.name
// // .toLowerCase()
// // .contains(searchValue.toLowerCase()),
// // )
// // .toList();
// // }
// },
// decoration: InputDecoration(
// contentPadding: const EdgeInsets.symmetric(
// horizontal: 8.0,
// vertical: 8.0,
// ),
// hintText: "Search",
// hintStyle: TextStyle(
// color: isDarkTheme ? Colors.white : Colors.grey,
// fontSize: 14.0,
// ),
// prefixIcon: const Icon(
// Icons.search,
// color: Colors.grey,
// ),
// border: OutlineInputBorder(
// borderRadius: BorderRadius.circular(10),
// borderSide: BorderSide.none,
// ),
// filled: true,
// fillColor: isDarkTheme ? Colors.white30 : Colors.grey[200],
// ),
// ),
// );
// }

return Scaffold(
appBar: AppBar(
Expand Down Expand Up @@ -301,7 +296,7 @@ class BackupAlbumSelectionPage extends HookConsumerWidget {
),
),

buildSearchBar(),
// buildSearchBar(),
],
),
),
Expand Down

0 comments on commit 885eba2

Please sign in to comment.