mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
refactor: update global states to ValueNotifiers
This commit is contained in:
parent
c91a2878dc
commit
e8bb9a3934
@ -73,7 +73,7 @@ class LoginPageCubit extends Cubit<LoginPageState> with LogMixin {
|
||||
ServiceLocator.registerPostGlobalStates();
|
||||
|
||||
// Fetch server features
|
||||
await di<ServerFeatureConfigCubit>().getFeatures();
|
||||
await di<ServerFeatureConfigProvider>().getFeatures();
|
||||
|
||||
emit(state.copyWith(isServerValidated: true));
|
||||
} finally {
|
||||
@ -141,7 +141,7 @@ class LoginPageCubit extends Cubit<LoginPageState> with LogMixin {
|
||||
await di<IUserRepository>().upsert(user);
|
||||
// Remove and Sync assets in background
|
||||
await di<IAssetRepository>().deleteAll();
|
||||
await di<GalleryPermissionNotifier>().requestPermission();
|
||||
await di<GalleryPermissionProvider>().requestPermission();
|
||||
unawaited(di<AssetSyncService>().performFullRemoteSyncIsolate(user));
|
||||
unawaited(di<AlbumSyncService>().performFullDeviceSyncIsolate());
|
||||
|
||||
|
@ -2,7 +2,6 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:immich_mobile/domain/models/server-info/server_feature_config.model.dart';
|
||||
import 'package:immich_mobile/i18n/strings.g.dart';
|
||||
import 'package:immich_mobile/presentation/components/common/gap.widget.dart';
|
||||
import 'package:immich_mobile/presentation/components/common/loading_indicator.widget.dart';
|
||||
@ -132,9 +131,9 @@ class _CredentialsFormState extends State<_CredentialsForm> {
|
||||
selector: (model) => model.isValidationInProgress,
|
||||
builder: (_, isValidationInProgress) => isValidationInProgress
|
||||
? const ImLoadingIndicator()
|
||||
: BlocBuilder<ServerFeatureConfigCubit, ServerFeatureConfig>(
|
||||
bloc: di(),
|
||||
builder: (_, state) => Column(
|
||||
: ValueListenableBuilder(
|
||||
valueListenable: di<ServerFeatureConfigProvider>(),
|
||||
builder: (_, state, __) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
|
@ -54,7 +54,7 @@ class _SplashScreenState extends State<SplashScreenPage>
|
||||
Future<void> _tryLogin() async {
|
||||
if (await di<LoginService>().tryAutoLogin() && mounted) {
|
||||
unawaited(di<AssetSyncService>()
|
||||
.performFullRemoteSyncIsolate(di<CurrentUserCubit>().state));
|
||||
.performFullRemoteSyncIsolate(di<CurrentUserProvider>().value));
|
||||
unawaited(di<AlbumSyncService>().performFullDeviceSyncIsolate());
|
||||
unawaited(context.replaceRoute(const TabControllerRoute()));
|
||||
} else {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:immich_mobile/domain/models/user.model.dart';
|
||||
|
||||
class CurrentUserCubit extends Cubit<User> {
|
||||
CurrentUserCubit(super.initialState);
|
||||
class CurrentUserProvider extends ValueNotifier<User> {
|
||||
CurrentUserProvider(super.initialState);
|
||||
|
||||
void updateUser(User user) => emit(user);
|
||||
void updateUser(User user) => value = user;
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ enum GalleryPermissionStatus {
|
||||
bool get isLimited => this == GalleryPermissionStatus.limited;
|
||||
}
|
||||
|
||||
class GalleryPermissionNotifier extends ValueNotifier<GalleryPermissionStatus> {
|
||||
GalleryPermissionNotifier() : super(GalleryPermissionStatus.yetToRequest) {
|
||||
class GalleryPermissionProvider extends ValueNotifier<GalleryPermissionStatus> {
|
||||
GalleryPermissionProvider() : super(GalleryPermissionStatus.yetToRequest) {
|
||||
checkPermission();
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:immich_mobile/domain/models/server-info/server_feature_config.model.dart';
|
||||
import 'package:immich_mobile/domain/services/server_info.service.dart';
|
||||
|
||||
class ServerFeatureConfigCubit extends Cubit<ServerFeatureConfig> {
|
||||
class ServerFeatureConfigProvider extends ValueNotifier<ServerFeatureConfig> {
|
||||
final ServerInfoService _serverInfoService;
|
||||
|
||||
ServerFeatureConfigCubit(this._serverInfoService)
|
||||
ServerFeatureConfigProvider(this._serverInfoService)
|
||||
: super(const ServerFeatureConfig.reset());
|
||||
|
||||
Future<void> getFeatures() async =>
|
||||
@ -14,14 +14,14 @@ class ServerFeatureConfigCubit extends Cubit<ServerFeatureConfig> {
|
||||
Future<void> _getFeatures() async {
|
||||
final features = await _serverInfoService.getServerFeatures();
|
||||
if (features != null) {
|
||||
emit(state.copyWith(features: features));
|
||||
value = value.copyWith(features: features);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _getConfig() async {
|
||||
final config = await _serverInfoService.getServerConfig();
|
||||
if (config != null) {
|
||||
emit(state.copyWith(config: config));
|
||||
value = value.copyWith(config: config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ class ServiceLocator {
|
||||
static void _registerPreGlobalStates() {
|
||||
_registerSingleton(AppRouter());
|
||||
_registerLazySingleton<AppThemeCubit>(() => AppThemeCubit(di()));
|
||||
_registerSingleton(GalleryPermissionNotifier());
|
||||
_registerSingleton(GalleryPermissionProvider());
|
||||
}
|
||||
|
||||
static void registerApiClient(String endpoint) {
|
||||
@ -138,12 +138,12 @@ class ServiceLocator {
|
||||
}
|
||||
|
||||
static void registerPostGlobalStates() {
|
||||
_registerLazySingleton<ServerFeatureConfigCubit>(
|
||||
() => ServerFeatureConfigCubit(di()),
|
||||
_registerLazySingleton<ServerFeatureConfigProvider>(
|
||||
() => ServerFeatureConfigProvider(di()),
|
||||
);
|
||||
}
|
||||
|
||||
static void registerCurrentUser(User user) {
|
||||
_registerSingleton(CurrentUserCubit(user));
|
||||
_registerSingleton(CurrentUserProvider(user));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user