mirror of
https://github.com/immich-app/immich.git
synced 2025-07-08 10:46:48 -04:00
album on collections page does not change
This commit is contained in:
parent
27d390a756
commit
c26baea530
@ -1,6 +1,5 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/extensions/asyncvalue_extensions.dart';
|
import 'package:immich_mobile/extensions/asyncvalue_extensions.dart';
|
||||||
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
||||||
@ -141,22 +140,12 @@ class AlbumsCollectionCard extends HookConsumerWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
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;
|
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(
|
return GestureDetector(
|
||||||
onTap: () => context.pushRoute(
|
onTap: () => context.pushRoute(
|
||||||
isLocal
|
isLocal
|
||||||
@ -179,7 +168,7 @@ class AlbumsCollectionCard extends HookConsumerWidget {
|
|||||||
crossAxisSpacing: 8,
|
crossAxisSpacing: 8,
|
||||||
mainAxisSpacing: 8,
|
mainAxisSpacing: 8,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
children: albums.value.take(4).map((album) {
|
children: albums.take(4).map((album) {
|
||||||
return AlbumThumbnailCard(
|
return AlbumThumbnailCard(
|
||||||
album: album,
|
album: album,
|
||||||
showTitle: false,
|
showTitle: false,
|
||||||
|
@ -82,18 +82,18 @@ class TabControllerPage extends HookConsumerWidget {
|
|||||||
selectedIcon: const Icon(Icons.search),
|
selectedIcon: const Icon(Icons.search),
|
||||||
label: const Text('tab_controller_nav_search').tr(),
|
label: const Text('tab_controller_nav_search').tr(),
|
||||||
),
|
),
|
||||||
NavigationRailDestination(
|
// NavigationRailDestination(
|
||||||
padding: const EdgeInsets.all(4),
|
// padding: const EdgeInsets.all(4),
|
||||||
icon: const Icon(Icons.share_rounded),
|
// icon: const Icon(Icons.share_rounded),
|
||||||
selectedIcon: const Icon(Icons.share),
|
// selectedIcon: const Icon(Icons.share),
|
||||||
label: const Text('tab_controller_nav_sharing').tr(),
|
// label: const Text('tab_controller_nav_sharing').tr(),
|
||||||
),
|
// ),
|
||||||
NavigationRailDestination(
|
// NavigationRailDestination(
|
||||||
padding: const EdgeInsets.all(4),
|
// padding: const EdgeInsets.all(4),
|
||||||
icon: const Icon(Icons.photo_album_outlined),
|
// icon: const Icon(Icons.photo_album_outlined),
|
||||||
selectedIcon: const Icon(Icons.photo_album),
|
// selectedIcon: const Icon(Icons.photo_album),
|
||||||
label: const Text('tab_controller_nav_library').tr(),
|
// label: const Text('tab_controller_nav_library').tr(),
|
||||||
),
|
// ),
|
||||||
NavigationRailDestination(
|
NavigationRailDestination(
|
||||||
padding: const EdgeInsets.all(4),
|
padding: const EdgeInsets.all(4),
|
||||||
icon: const Icon(Icons.photo_album_outlined),
|
icon: const Icon(Icons.photo_album_outlined),
|
||||||
@ -140,28 +140,28 @@ class TabControllerPage extends HookConsumerWidget {
|
|||||||
color: context.primaryColor,
|
color: context.primaryColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
NavigationDestination(
|
// NavigationDestination(
|
||||||
label: 'tab_controller_nav_sharing'.tr(),
|
// label: 'tab_controller_nav_sharing'.tr(),
|
||||||
icon: const Icon(
|
// icon: const Icon(
|
||||||
Icons.group_outlined,
|
// Icons.group_outlined,
|
||||||
),
|
// ),
|
||||||
selectedIcon: Icon(
|
// selectedIcon: Icon(
|
||||||
Icons.group,
|
// Icons.group,
|
||||||
color: context.primaryColor,
|
// color: context.primaryColor,
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
NavigationDestination(
|
// NavigationDestination(
|
||||||
label: 'tab_controller_nav_library'.tr(),
|
// label: 'tab_controller_nav_library'.tr(),
|
||||||
icon: const Icon(
|
// icon: const Icon(
|
||||||
Icons.photo_album_outlined,
|
// Icons.photo_album_outlined,
|
||||||
),
|
// ),
|
||||||
selectedIcon: buildIcon(
|
// selectedIcon: buildIcon(
|
||||||
Icon(
|
// Icon(
|
||||||
Icons.photo_album_rounded,
|
// Icons.photo_album_rounded,
|
||||||
color: context.primaryColor,
|
// color: context.primaryColor,
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
NavigationDestination(
|
NavigationDestination(
|
||||||
label: 'Collections'.tr(),
|
label: 'Collections'.tr(),
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
@ -183,8 +183,8 @@ class TabControllerPage extends HookConsumerWidget {
|
|||||||
routes: const [
|
routes: const [
|
||||||
PhotosRoute(),
|
PhotosRoute(),
|
||||||
SearchRoute(),
|
SearchRoute(),
|
||||||
SharingRoute(),
|
// SharingRoute(),
|
||||||
LibraryRoute(),
|
// LibraryRoute(),
|
||||||
CollectionsRoute(),
|
CollectionsRoute(),
|
||||||
],
|
],
|
||||||
duration: const Duration(milliseconds: 600),
|
duration: const Duration(milliseconds: 600),
|
||||||
|
@ -26,11 +26,10 @@ class AlbumNotifierV2 extends StateNotifier<List<Album>> {
|
|||||||
final Isar db;
|
final Isar db;
|
||||||
late final StreamSubscription<List<Album>> _streamSub;
|
late final StreamSubscription<List<Album>> _streamSub;
|
||||||
|
|
||||||
Future<void> refreshAlbums() {
|
Future<void> refreshAlbums() async {
|
||||||
return Future.wait([
|
await _albumService.refreshDeviceAlbums();
|
||||||
_albumService.refreshDeviceAlbums(),
|
await _albumService.refreshRemoteAlbums(isShared: false);
|
||||||
_albumService.refreshRemoteAlbums(isShared: true),
|
await _albumService.refreshRemoteAlbums(isShared: true);
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getDeviceAlbums() {
|
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
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_streamSub.cancel();
|
_streamSub.cancel();
|
||||||
@ -125,3 +116,59 @@ final albumProviderV2 =
|
|||||||
ref.watch(dbProvider),
|
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));
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user