refactor repositories

This commit is contained in:
shenlong-tanwen
2024-09-21 20:04:05 +05:30
parent d6495f014d
commit e810512285
23 changed files with 142 additions and 127 deletions
@@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:immich_mobile/domain/interfaces/asset.interface.dart';
import 'package:immich_mobile/domain/interfaces/renderlist.interface.dart';
import 'package:immich_mobile/presentation/components/grid/immich_asset_grid.state.dart';
import 'package:immich_mobile/presentation/components/grid/immich_asset_grid.widget.dart';
import 'package:immich_mobile/service_locator.dart';
@@ -15,8 +16,8 @@ class HomePage extends StatelessWidget {
return Scaffold(
body: BlocProvider(
create: (_) => ImmichAssetGridCubit(
renderStream: di<IAssetRepository>().watchRenderList(),
assetProvider: di<IAssetRepository>().fetchAssets,
renderStream: di<IRenderListRepository>().watchAll(),
assetProvider: di<IAssetRepository>().getAll,
),
child: const ImAssetGrid(),
),
@@ -65,7 +65,7 @@ class LoginPageCubit extends Cubit<LoginPageState> with LogMixin {
// Check for /.well-known/immich
url = await loginService.resolveEndpoint(uri);
di<IStoreRepository>().set(StoreKey.serverEndpoint, url);
di<IStoreRepository>().upsert(StoreKey.serverEndpoint, url);
ServiceLocator.registerApiClient(url);
ServiceLocator.registerPostValidationServices();
ServiceLocator.registerPostGlobalStates();
@@ -123,7 +123,7 @@ class LoginPageCubit extends Cubit<LoginPageState> with LogMixin {
}
Future<void> _postLogin(String accessToken) async {
await di<IStoreRepository>().set(StoreKey.accessToken, accessToken);
await di<IStoreRepository>().upsert(StoreKey.accessToken, accessToken);
/// Set token to interceptor
await di<ImmichApiClient>().init(accessToken: accessToken);
@@ -136,10 +136,10 @@ class LoginPageCubit extends Cubit<LoginPageState> with LogMixin {
// Register user
ServiceLocator.registerCurrentUser(user);
await di<IUserRepository>().add(user);
await di<IUserRepository>().upsert(user);
// Remove and Sync assets in background
await di<IAssetRepository>().clearAll();
unawaited(di<AssetSyncService>().doFullRemoteSyncForUserDrift(user));
await di<IAssetRepository>().deleteAll();
unawaited(di<AssetSyncService>().performFullRemoteSyncForUser(user));
emit(state.copyWith(
isValidationInProgress: false,
@@ -10,9 +10,8 @@ class AppThemeCubit extends Cubit<AppTheme> {
late final StreamSubscription _appSettingSubscription;
AppThemeCubit(this._appSettings) : super(AppTheme.blue) {
_appSettingSubscription = _appSettings
.watchSetting(AppSetting.appTheme)
.listen((theme) => emit(theme));
_appSettingSubscription =
_appSettings.watch(AppSetting.appTheme).listen((theme) => emit(theme));
}
@override