mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(mobile): Library page rework (album sorting, favorites) (#1501)
* Add album sorting * Change AppBar to match photos page behaviour * Add buttons * First crude implementation of the favorites page * Clean up * Add favorite button * i18n * Add star indicator to thumbnail * Add favorite logic to separate provider and fix favorite behavior in album * Review feedback (Add isFavorite variable) * dev: style buttons * dev: styled drop down button --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
0048662182
commit
bb0b2a1f53
16 changed files with 478 additions and 56 deletions
52
mobile/lib/modules/favorite/providers/favorite_provider.dart
Normal file
52
mobile/lib/modules/favorite/providers/favorite_provider.dart
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/shared/models/asset.dart';
|
||||
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
||||
|
||||
class FavoriteSelectionNotifier extends StateNotifier<Set<String>> {
|
||||
FavoriteSelectionNotifier(this.ref) : super({}) {
|
||||
state = ref.watch(assetProvider).allAssets
|
||||
.where((asset) => asset.isFavorite)
|
||||
.map((asset) => asset.id)
|
||||
.toSet();
|
||||
}
|
||||
|
||||
final Ref ref;
|
||||
|
||||
void _setFavoriteForAssetId(String id, bool favorite) {
|
||||
if (!favorite) {
|
||||
state = state.difference({id});
|
||||
} else {
|
||||
state = state.union({id});
|
||||
}
|
||||
}
|
||||
|
||||
bool _isFavorite(String id) {
|
||||
return state.contains(id);
|
||||
}
|
||||
|
||||
Future<void> toggleFavorite(Asset asset) async {
|
||||
if (!asset.isRemote) return; // TODO support local favorite assets
|
||||
|
||||
_setFavoriteForAssetId(asset.id, !_isFavorite(asset.id));
|
||||
|
||||
await ref.watch(assetProvider.notifier).toggleFavorite(
|
||||
asset,
|
||||
state.contains(asset.id),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final favoriteProvider =
|
||||
StateNotifierProvider<FavoriteSelectionNotifier, Set<String>>((ref) {
|
||||
return FavoriteSelectionNotifier(ref);
|
||||
});
|
||||
|
||||
final favoriteAssetProvider = StateProvider((ref) {
|
||||
final favorites = ref.watch(favoriteProvider);
|
||||
|
||||
return ref
|
||||
.watch(assetProvider)
|
||||
.allAssets
|
||||
.where((element) => favorites.contains(element.id))
|
||||
.toList();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue