2022-03-16 16:19:31 +01:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2023-08-10 04:01:16 +02:00
|
|
|
import 'package:flutter/foundation.dart';
|
2022-03-16 16:19:31 +01:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2024-05-02 22:59:14 +02:00
|
|
|
import 'package:immich_mobile/providers/memory.provider.dart';
|
2022-03-16 16:19:31 +01:00
|
|
|
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/entities/store.entity.dart';
|
|
|
|
import 'package:immich_mobile/entities/user.entity.dart';
|
2024-05-02 22:59:14 +02:00
|
|
|
import 'package:immich_mobile/providers/api.provider.dart';
|
|
|
|
import 'package:immich_mobile/providers/asset.provider.dart';
|
|
|
|
import 'package:immich_mobile/providers/server_info.provider.dart';
|
2022-03-16 16:19:31 +01:00
|
|
|
|
|
|
|
class TabNavigationObserver extends AutoRouterObserver {
|
|
|
|
/// Riverpod Instance
|
|
|
|
final WidgetRef ref;
|
|
|
|
|
|
|
|
TabNavigationObserver({
|
|
|
|
required this.ref,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
2022-04-24 04:08:45 +02:00
|
|
|
Future<void> didChangeTabRoute(
|
2022-07-13 14:23:48 +02:00
|
|
|
TabPageRoute route,
|
|
|
|
TabPageRoute previousRoute,
|
|
|
|
) async {
|
2023-06-27 23:00:20 +02:00
|
|
|
if (route.name == 'HomeRoute') {
|
|
|
|
ref.invalidate(memoryFutureProvider);
|
2023-09-10 14:51:18 +02:00
|
|
|
Future(() => ref.read(assetProvider.notifier).getAllAsset());
|
2023-08-10 04:01:16 +02:00
|
|
|
|
|
|
|
// Update user info
|
|
|
|
try {
|
|
|
|
final userResponseDto =
|
2024-05-30 00:26:57 +02:00
|
|
|
await ref.read(apiServiceProvider).usersApi.getMyUser();
|
2024-05-28 04:16:53 +02:00
|
|
|
final userPreferences =
|
2024-05-30 00:26:57 +02:00
|
|
|
await ref.read(apiServiceProvider).usersApi.getMyPreferences();
|
2023-08-10 04:01:16 +02:00
|
|
|
|
|
|
|
if (userResponseDto == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-11 22:06:19 +01:00
|
|
|
Store.put(
|
|
|
|
StoreKey.currentUser,
|
2024-05-28 04:16:53 +02:00
|
|
|
User.fromUserDto(userResponseDto, userPreferences),
|
2023-11-11 22:06:19 +01:00
|
|
|
);
|
2023-09-29 16:51:54 +02:00
|
|
|
ref.read(serverInfoProvider.notifier).getServerVersion();
|
2023-08-10 04:01:16 +02:00
|
|
|
} catch (e) {
|
|
|
|
debugPrint("Error refreshing user info $e");
|
|
|
|
}
|
2023-06-27 23:00:20 +02:00
|
|
|
}
|
2022-03-16 16:19:31 +01:00
|
|
|
}
|
|
|
|
}
|