album on collections page does not change

This commit is contained in:
Alex Tran 2024-09-08 00:23:20 -05:00
parent 27d390a756
commit c26baea530
No known key found for this signature in database
3 changed files with 100 additions and 64 deletions

View File

@ -1,6 +1,5 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/extensions/asyncvalue_extensions.dart';
import 'package:immich_mobile/extensions/build_context_extensions.dart';
@ -141,22 +140,12 @@ class AlbumsCollectionCard extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final albums = useState([]);
final albums = isLocal
? ref.watch(localAlbumsProvider)
: ref.watch(remoteAlbumsProvider);
final size = MediaQuery.of(context).size.width * 0.5 - 20;
useEffect(
() {
Future.microtask(() async {
albums.value = isLocal
? await ref.read(albumProviderV2.notifier).getLocalAlbums()
: await ref.read(albumProviderV2.notifier).getRemoteAlbums();
});
return null;
},
[],
);
return GestureDetector(
onTap: () => context.pushRoute(
isLocal
@ -179,7 +168,7 @@ class AlbumsCollectionCard extends HookConsumerWidget {
crossAxisSpacing: 8,
mainAxisSpacing: 8,
physics: const NeverScrollableScrollPhysics(),
children: albums.value.take(4).map((album) {
children: albums.take(4).map((album) {
return AlbumThumbnailCard(
album: album,
showTitle: false,

View File

@ -82,18 +82,18 @@ class TabControllerPage extends HookConsumerWidget {
selectedIcon: const Icon(Icons.search),
label: const Text('tab_controller_nav_search').tr(),
),
NavigationRailDestination(
padding: const EdgeInsets.all(4),
icon: const Icon(Icons.share_rounded),
selectedIcon: const Icon(Icons.share),
label: const Text('tab_controller_nav_sharing').tr(),
),
NavigationRailDestination(
padding: const EdgeInsets.all(4),
icon: const Icon(Icons.photo_album_outlined),
selectedIcon: const Icon(Icons.photo_album),
label: const Text('tab_controller_nav_library').tr(),
),
// NavigationRailDestination(
// padding: const EdgeInsets.all(4),
// icon: const Icon(Icons.share_rounded),
// selectedIcon: const Icon(Icons.share),
// label: const Text('tab_controller_nav_sharing').tr(),
// ),
// NavigationRailDestination(
// padding: const EdgeInsets.all(4),
// icon: const Icon(Icons.photo_album_outlined),
// selectedIcon: const Icon(Icons.photo_album),
// label: const Text('tab_controller_nav_library').tr(),
// ),
NavigationRailDestination(
padding: const EdgeInsets.all(4),
icon: const Icon(Icons.photo_album_outlined),
@ -140,28 +140,28 @@ class TabControllerPage extends HookConsumerWidget {
color: context.primaryColor,
),
),
NavigationDestination(
label: 'tab_controller_nav_sharing'.tr(),
icon: const Icon(
Icons.group_outlined,
),
selectedIcon: Icon(
Icons.group,
color: context.primaryColor,
),
),
NavigationDestination(
label: 'tab_controller_nav_library'.tr(),
icon: const Icon(
Icons.photo_album_outlined,
),
selectedIcon: buildIcon(
Icon(
Icons.photo_album_rounded,
color: context.primaryColor,
),
),
),
// NavigationDestination(
// label: 'tab_controller_nav_sharing'.tr(),
// icon: const Icon(
// Icons.group_outlined,
// ),
// selectedIcon: Icon(
// Icons.group,
// color: context.primaryColor,
// ),
// ),
// NavigationDestination(
// label: 'tab_controller_nav_library'.tr(),
// icon: const Icon(
// Icons.photo_album_outlined,
// ),
// selectedIcon: buildIcon(
// Icon(
// Icons.photo_album_rounded,
// color: context.primaryColor,
// ),
// ),
// ),
NavigationDestination(
label: 'Collections'.tr(),
icon: const Icon(
@ -183,8 +183,8 @@ class TabControllerPage extends HookConsumerWidget {
routes: const [
PhotosRoute(),
SearchRoute(),
SharingRoute(),
LibraryRoute(),
// SharingRoute(),
// LibraryRoute(),
CollectionsRoute(),
],
duration: const Duration(milliseconds: 600),

View File

@ -26,11 +26,10 @@ class AlbumNotifierV2 extends StateNotifier<List<Album>> {
final Isar db;
late final StreamSubscription<List<Album>> _streamSub;
Future<void> refreshAlbums() {
return Future.wait([
_albumService.refreshDeviceAlbums(),
_albumService.refreshRemoteAlbums(isShared: true),
]);
Future<void> refreshAlbums() async {
await _albumService.refreshDeviceAlbums();
await _albumService.refreshRemoteAlbums(isShared: false);
await _albumService.refreshRemoteAlbums(isShared: true);
}
Future<void> getDeviceAlbums() {
@ -103,14 +102,6 @@ class AlbumNotifierV2 extends StateNotifier<List<Album>> {
}
}
Future<List<Album>> getRemoteAlbums() {
return db.albums.filter().remoteIdIsNotNull().findAll();
}
Future<List<Album>> getLocalAlbums() {
return db.albums.filter().not().remoteIdIsNotNull().findAll();
}
@override
void dispose() {
_streamSub.cancel();
@ -125,3 +116,59 @@ final albumProviderV2 =
ref.watch(dbProvider),
);
});
class RemoteAlbumsNotifier extends StateNotifier<List<Album>> {
RemoteAlbumsNotifier(this.db) : super([]) {
final query = db.albums.filter().remoteIdIsNotNull();
query.findAll().then((value) {
if (mounted) {
state = value;
}
});
_streamSub = query.watch().listen((data) => state = data);
}
final Isar db;
late final StreamSubscription<List<Album>> _streamSub;
@override
void dispose() {
_streamSub.cancel();
super.dispose();
}
}
class LocalAlbumsNotifier extends StateNotifier<List<Album>> {
LocalAlbumsNotifier(this.db) : super([]) {
final query = db.albums.filter().not().remoteIdIsNotNull();
query.findAll().then((value) {
if (mounted) {
state = value;
}
});
_streamSub = query.watch().listen((data) => state = data);
}
final Isar db;
late final StreamSubscription<List<Album>> _streamSub;
@override
void dispose() {
_streamSub.cancel();
super.dispose();
}
}
final localAlbumsProvider =
StateNotifierProvider.autoDispose<LocalAlbumsNotifier, List<Album>>((ref) {
return LocalAlbumsNotifier(ref.watch(dbProvider));
});
final remoteAlbumsProvider =
StateNotifierProvider.autoDispose<RemoteAlbumsNotifier, List<Album>>((ref) {
return RemoteAlbumsNotifier(ref.watch(dbProvider));
});