mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
Adds todayProvider to memory lane
This commit is contained in:
parent
8db008ef0b
commit
67ae58b513
3 changed files with 24 additions and 3 deletions
|
@ -14,6 +14,7 @@ import 'package:immich_mobile/modules/backup/models/duplicated_asset.model.dart'
|
|||
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
|
||||
import 'package:immich_mobile/modules/backup/providers/ios_background_settings.provider.dart';
|
||||
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
||||
import 'package:immich_mobile/modules/memories/providers/memory.provider.dart';
|
||||
import 'package:immich_mobile/modules/onboarding/providers/gallery_permission.provider.dart';
|
||||
import 'package:immich_mobile/modules/settings/providers/notification_permission.provider.dart';
|
||||
import 'package:immich_mobile/routing/router.dart';
|
||||
|
@ -156,6 +157,8 @@ class ImmichAppState extends ConsumerState<ImmichApp>
|
|||
|
||||
ref.read(iOSBackgroundSettingsProvider.notifier).refresh();
|
||||
|
||||
ref.read(todayProvider.notifier).update();
|
||||
|
||||
break;
|
||||
|
||||
case AppLifecycleState.inactive:
|
||||
|
|
|
@ -2,9 +2,26 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||
import 'package:immich_mobile/modules/memories/models/memory.dart';
|
||||
import 'package:immich_mobile/modules/memories/services/memory.service.dart';
|
||||
|
||||
/// A notifier to be used with the Memory Lane service. Sets the date, and
|
||||
/// will update the date to now on app resume so that the memory provider
|
||||
/// can update accordingly
|
||||
class TodayNotifier extends StateNotifier<DateTime> {
|
||||
TodayNotifier() : super(DateTime.now());
|
||||
|
||||
/// Sets the time to now to refresh today
|
||||
void update() {
|
||||
state = DateTime.now();
|
||||
}
|
||||
}
|
||||
|
||||
final todayProvider = StateNotifierProvider<TodayNotifier, DateTime>((ref) {
|
||||
return TodayNotifier();
|
||||
});
|
||||
|
||||
final memoryFutureProvider =
|
||||
FutureProvider.autoDispose<List<Memory>?>((ref) async {
|
||||
final service = ref.watch(memoryServiceProvider);
|
||||
final today = ref.watch(todayProvider);
|
||||
|
||||
return await service.getMemoryLane();
|
||||
return await service.getMemoryLane(now: today);
|
||||
});
|
||||
|
|
|
@ -19,9 +19,10 @@ class MemoryService {
|
|||
|
||||
MemoryService(this._apiService);
|
||||
|
||||
Future<List<Memory>?> getMemoryLane() async {
|
||||
Future<List<Memory>?> getMemoryLane({DateTime? now}) async {
|
||||
try {
|
||||
final now = DateTime.now();
|
||||
// Use the provided DateTime or default to now
|
||||
now = now ?? DateTime.now();
|
||||
final beginningOfDate = DateTime(now.year, now.month, now.day);
|
||||
final data = await _apiService.assetApi.getMemoryLane(
|
||||
beginningOfDate,
|
||||
|
|
Loading…
Reference in a new issue