diff --git a/mobile/lib/pages/collections/collections.page.dart b/mobile/lib/pages/collections/collections.page.dart index 20d9f8fa47d1b..317a93e5b3bce 100644 --- a/mobile/lib/pages/collections/collections.page.dart +++ b/mobile/lib/pages/collections/collections.page.dart @@ -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, diff --git a/mobile/lib/pages/common/tab_controller.page.dart b/mobile/lib/pages/common/tab_controller.page.dart index f862213040e89..ca3274bd6bcda 100644 --- a/mobile/lib/pages/common/tab_controller.page.dart +++ b/mobile/lib/pages/common/tab_controller.page.dart @@ -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), diff --git a/mobile/lib/providers/album/albumv2.provider.dart b/mobile/lib/providers/album/albumv2.provider.dart index 85caeb4e0e6a7..3683a7d24f10b 100644 --- a/mobile/lib/providers/album/albumv2.provider.dart +++ b/mobile/lib/providers/album/albumv2.provider.dart @@ -26,11 +26,10 @@ class AlbumNotifierV2 extends StateNotifier> { final Isar db; late final StreamSubscription> _streamSub; - Future refreshAlbums() { - return Future.wait([ - _albumService.refreshDeviceAlbums(), - _albumService.refreshRemoteAlbums(isShared: true), - ]); + Future refreshAlbums() async { + await _albumService.refreshDeviceAlbums(); + await _albumService.refreshRemoteAlbums(isShared: false); + await _albumService.refreshRemoteAlbums(isShared: true); } Future getDeviceAlbums() { @@ -103,14 +102,6 @@ class AlbumNotifierV2 extends StateNotifier> { } } - Future> getRemoteAlbums() { - return db.albums.filter().remoteIdIsNotNull().findAll(); - } - - Future> 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> { + 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> _streamSub; + + @override + void dispose() { + _streamSub.cancel(); + super.dispose(); + } +} + +class LocalAlbumsNotifier extends StateNotifier> { + 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> _streamSub; + + @override + void dispose() { + _streamSub.cancel(); + super.dispose(); + } +} + +final localAlbumsProvider = + StateNotifierProvider.autoDispose>((ref) { + return LocalAlbumsNotifier(ref.watch(dbProvider)); +}); + +final remoteAlbumsProvider = + StateNotifierProvider.autoDispose>((ref) { + return RemoteAlbumsNotifier(ref.watch(dbProvider)); +});