2022-03-16 17:19:31 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2023-08-10 04:01:16 +02:00
|
|
|
import 'package:flutter/foundation.dart';
|
2022-03-16 17:19:31 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/album.provider.dart';
|
2023-06-27 23:00:20 +02:00
|
|
|
import 'package:immich_mobile/modules/memories/providers/memory.provider.dart';
|
2023-06-23 17:44:02 +02:00
|
|
|
import 'package:immich_mobile/modules/search/providers/people.provider.dart';
|
2022-03-16 17:19:31 +02:00
|
|
|
|
|
|
|
import 'package:immich_mobile/modules/search/providers/search_page_state.provider.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/modules/album/providers/shared_album.provider.dart';
|
2023-08-10 04:01:16 +02:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
|
|
|
import 'package:immich_mobile/shared/models/user.dart';
|
|
|
|
import 'package:immich_mobile/shared/providers/api.provider.dart';
|
2023-09-10 14:51:18 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
2022-03-22 08:22:04 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
2022-03-16 17:19:31 +02:00
|
|
|
|
|
|
|
class TabNavigationObserver extends AutoRouterObserver {
|
|
|
|
/// Riverpod Instance
|
|
|
|
final WidgetRef ref;
|
|
|
|
|
|
|
|
TabNavigationObserver({
|
|
|
|
required this.ref,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didInitTabRoute(TabPageRoute route, TabPageRoute? previousRoute) {
|
|
|
|
// Perform tasks on first navigation to SearchRoute
|
|
|
|
if (route.name == 'SearchRoute') {
|
|
|
|
// ref.refresh(getCuratedLocationProvider);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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 {
|
2022-03-16 17:19:31 +02:00
|
|
|
// Perform tasks on re-visit to SearchRoute
|
|
|
|
if (route.name == 'SearchRoute') {
|
|
|
|
// Refresh Location State
|
2023-01-26 16:40:19 +02:00
|
|
|
ref.invalidate(getCuratedLocationProvider);
|
2024-04-01 16:45:11 +02:00
|
|
|
ref.invalidate(getAllPeopleProvider);
|
2022-03-16 17:19:31 +02:00
|
|
|
}
|
2022-03-22 08:22:04 +02:00
|
|
|
|
2022-04-24 04:08:45 +02:00
|
|
|
if (route.name == 'SharingRoute') {
|
|
|
|
ref.read(sharedAlbumProvider.notifier).getAllSharedAlbums();
|
2023-09-10 14:51:18 +02:00
|
|
|
ref.read(assetProvider.notifier).getPartnerAssets();
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
|
2022-08-03 07:04:34 +02:00
|
|
|
if (route.name == 'LibraryRoute') {
|
|
|
|
ref.read(albumProvider.notifier).getAllAlbums();
|
|
|
|
}
|
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 =
|
|
|
|
await ref.read(apiServiceProvider).userApi.getMyUserInfo();
|
|
|
|
|
|
|
|
if (userResponseDto == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-11 23:06:19 +02:00
|
|
|
Store.put(
|
|
|
|
StoreKey.currentUser,
|
|
|
|
User.fromUserDto(userResponseDto),
|
|
|
|
);
|
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 17:19:31 +02:00
|
|
|
}
|
|
|
|
}
|