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