2022-03-16 10:19:31 -05:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2023-08-09 21:01:16 -05: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/album/album.provider.dart';
|
|
|
|
import 'package:immich_mobile/providers/memory.provider.dart';
|
|
|
|
import 'package:immich_mobile/providers/search/people.provider.dart';
|
2022-03-16 10:19:31 -05:00
|
|
|
|
2024-05-02 15:59:14 -05:00
|
|
|
import 'package:immich_mobile/providers/search/search_page_state.provider.dart';
|
|
|
|
import 'package:immich_mobile/providers/album/shared_album.provider.dart';
|
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
|
|
|
|
void didInitTabRoute(TabPageRoute route, TabPageRoute? previousRoute) {
|
|
|
|
// Perform tasks on first navigation to SearchRoute
|
|
|
|
if (route.name == 'SearchRoute') {
|
|
|
|
// ref.refresh(getCuratedLocationProvider);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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 {
|
2022-03-16 10:19:31 -05:00
|
|
|
// Perform tasks on re-visit to SearchRoute
|
|
|
|
if (route.name == 'SearchRoute') {
|
|
|
|
// Refresh Location State
|
2024-04-30 22:14:33 -05:00
|
|
|
ref.invalidate(getPreviewPlacesProvider);
|
2024-04-01 09:45:11 -05:00
|
|
|
ref.invalidate(getAllPeopleProvider);
|
2022-03-16 10:19:31 -05:00
|
|
|
}
|
2022-03-22 01:22:04 -05:00
|
|
|
|
2022-04-23 21:08:45 -05:00
|
|
|
if (route.name == 'SharingRoute') {
|
|
|
|
ref.read(sharedAlbumProvider.notifier).getAllSharedAlbums();
|
2024-05-14 10:35:37 -05:00
|
|
|
Future(() => ref.read(assetProvider.notifier).getAllAsset());
|
2022-04-23 21:08:45 -05:00
|
|
|
}
|
|
|
|
|
2022-08-03 00:04:34 -05:00
|
|
|
if (route.name == 'LibraryRoute') {
|
|
|
|
ref.read(albumProvider.notifier).getAllAlbums();
|
|
|
|
}
|
2023-06-27 16:00:20 -05:00
|
|
|
|
|
|
|
if (route.name == 'HomeRoute') {
|
|
|
|
ref.invalidate(memoryFutureProvider);
|
2023-09-10 07:51:18 -05:00
|
|
|
Future(() => ref.read(assetProvider.notifier).getAllAsset());
|
2023-08-09 21:01:16 -05:00
|
|
|
|
|
|
|
// Update user info
|
|
|
|
try {
|
|
|
|
final userResponseDto =
|
|
|
|
await ref.read(apiServiceProvider).userApi.getMyUserInfo();
|
|
|
|
|
|
|
|
if (userResponseDto == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-11 16:06:19 -05:00
|
|
|
Store.put(
|
|
|
|
StoreKey.currentUser,
|
|
|
|
User.fromUserDto(userResponseDto),
|
|
|
|
);
|
2023-09-29 09:51:54 -05:00
|
|
|
ref.read(serverInfoProvider.notifier).getServerVersion();
|
2023-08-09 21:01:16 -05: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
|
|
|
}
|
|
|
|
}
|