mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix(mobile): memory lane rebuild (#21350)
* avoid unnecessary timeline rebuild * add key * handle disabled memories * avoid rebuild if no memories
This commit is contained in:
parent
dc6ac3aaec
commit
a5841a8bf4
4 changed files with 24 additions and 28 deletions
|
|
@ -30,6 +30,9 @@ class DriftMemoryRepository extends DriftDatabaseRepository {
|
||||||
..orderBy([OrderingTerm.desc(_db.memoryEntity.memoryAt), OrderingTerm.asc(_db.remoteAssetEntity.createdAt)]);
|
..orderBy([OrderingTerm.desc(_db.memoryEntity.memoryAt), OrderingTerm.asc(_db.remoteAssetEntity.createdAt)]);
|
||||||
|
|
||||||
final rows = await query.get();
|
final rows = await query.get();
|
||||||
|
if (rows.isEmpty) {
|
||||||
|
return const [];
|
||||||
|
}
|
||||||
|
|
||||||
final Map<String, DriftMemory> memoriesMap = {};
|
final Map<String, DriftMemory> memoriesMap = {};
|
||||||
|
|
||||||
|
|
@ -46,7 +49,7 @@ class DriftMemoryRepository extends DriftDatabaseRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return memoriesMap.values.toList();
|
return memoriesMap.values.toList(growable: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<DriftMemory?> get(String memoryId) async {
|
Future<DriftMemory?> get(String memoryId) async {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/memory/memory_lane.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/memory/memory_lane.widget.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/timeline/timeline.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/timeline/timeline.widget.dart';
|
||||||
import 'package:immich_mobile/providers/infrastructure/memory.provider.dart';
|
import 'package:immich_mobile/providers/infrastructure/memory.provider.dart';
|
||||||
import 'package:immich_mobile/providers/user.provider.dart';
|
|
||||||
|
|
||||||
@RoutePage()
|
@RoutePage()
|
||||||
class MainTimelinePage extends ConsumerWidget {
|
class MainTimelinePage extends ConsumerWidget {
|
||||||
|
|
@ -12,22 +11,10 @@ class MainTimelinePage extends ConsumerWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final memoryLaneProvider = ref.watch(driftMemoryFutureProvider);
|
final hasMemories = ref.watch(driftMemoryFutureProvider.select((state) => state.value?.isNotEmpty ?? false));
|
||||||
final memoriesEnabled = ref.watch(currentUserProvider.select((user) => user?.memoryEnabled ?? true));
|
return Timeline(
|
||||||
|
topSliverWidget: const SliverToBoxAdapter(child: DriftMemoryLane()),
|
||||||
return memoryLaneProvider.maybeWhen(
|
topSliverWidgetHeight: hasMemories ? 200 : 0,
|
||||||
data: (memories) {
|
|
||||||
return memories.isEmpty || !memoriesEnabled
|
|
||||||
? const Timeline()
|
|
||||||
: Timeline(
|
|
||||||
topSliverWidget: SliverToBoxAdapter(
|
|
||||||
key: Key('memory-lane-${memories.first.assets.first.id}'),
|
|
||||||
child: DriftMemoryLane(memories: memories),
|
|
||||||
),
|
|
||||||
topSliverWidgetHeight: 200,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
orElse: () => const Timeline(),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,20 @@ import 'package:immich_mobile/presentation/widgets/images/thumbnail.widget.dart'
|
||||||
import 'package:immich_mobile/providers/asset_viewer/video_player_value_provider.dart';
|
import 'package:immich_mobile/providers/asset_viewer/video_player_value_provider.dart';
|
||||||
import 'package:immich_mobile/providers/haptic_feedback.provider.dart';
|
import 'package:immich_mobile/providers/haptic_feedback.provider.dart';
|
||||||
import 'package:immich_mobile/providers/infrastructure/asset_viewer/current_asset.provider.dart';
|
import 'package:immich_mobile/providers/infrastructure/asset_viewer/current_asset.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/infrastructure/memory.provider.dart';
|
||||||
import 'package:immich_mobile/routing/router.dart';
|
import 'package:immich_mobile/routing/router.dart';
|
||||||
|
|
||||||
class DriftMemoryLane extends ConsumerWidget {
|
class DriftMemoryLane extends ConsumerWidget {
|
||||||
final List<DriftMemory> memories;
|
const DriftMemoryLane({super.key});
|
||||||
|
|
||||||
const DriftMemoryLane({super.key, required this.memories});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final memoryLaneProvider = ref.watch(driftMemoryFutureProvider);
|
||||||
|
final memories = memoryLaneProvider.value ?? const [];
|
||||||
|
if (memories.isEmpty) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
return ConstrainedBox(
|
return ConstrainedBox(
|
||||||
constraints: const BoxConstraints(maxHeight: 200),
|
constraints: const BoxConstraints(maxHeight: 200),
|
||||||
child: CarouselView(
|
child: CarouselView(
|
||||||
|
|
@ -38,7 +43,9 @@ class DriftMemoryLane extends ConsumerWidget {
|
||||||
|
|
||||||
context.pushRoute(DriftMemoryRoute(memories: memories, memoryIndex: index));
|
context.pushRoute(DriftMemoryRoute(memories: memories, memoryIndex: index));
|
||||||
},
|
},
|
||||||
children: memories.map((memory) => DriftMemoryCard(memory: memory)).toList(),
|
children: memories
|
||||||
|
.map((memory) => DriftMemoryCard(key: Key(memory.id), memory: memory))
|
||||||
|
.toList(growable: false),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,12 @@ final driftMemoryServiceProvider = Provider<DriftMemoryService>(
|
||||||
(ref) => DriftMemoryService(ref.watch(driftMemoryRepositoryProvider)),
|
(ref) => DriftMemoryService(ref.watch(driftMemoryRepositoryProvider)),
|
||||||
);
|
);
|
||||||
|
|
||||||
final driftMemoryFutureProvider = FutureProvider.autoDispose<List<DriftMemory>>((ref) async {
|
final driftMemoryFutureProvider = FutureProvider.autoDispose<List<DriftMemory>>((ref) {
|
||||||
final user = ref.watch(currentUserProvider);
|
final (userId, enabled) = ref.watch(currentUserProvider.select((user) => (user?.id, user?.memoryEnabled ?? true)));
|
||||||
if (user == null) {
|
if (userId == null || !enabled) {
|
||||||
return [];
|
return const [];
|
||||||
}
|
}
|
||||||
|
|
||||||
final service = ref.watch(driftMemoryServiceProvider);
|
final service = ref.watch(driftMemoryServiceProvider);
|
||||||
|
return service.getMemoryLane(userId);
|
||||||
return service.getMemoryLane(user.id);
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue