refactor(mobile): split store into repo and service (#16199)

* refactor(mobile): migrate store

* refactor(mobile): expand abbreviations

* chore(mobile): fix lint

---------

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
shenlong
2025-02-20 00:35:24 +05:30
committed by GitHub
parent 8634c59850
commit aeb3e0a84f
33 changed files with 582 additions and 287 deletions
+11 -11
View File
@@ -2,9 +2,9 @@ import 'package:flutter/foundation.dart';
import 'package:flutter_udid/flutter_udid.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/entities/store.entity.dart';
import 'package:immich_mobile/models/auth/login_response.model.dart';
import 'package:immich_mobile/models/auth/auth_state.model.dart';
import 'package:immich_mobile/entities/user.entity.dart';
import 'package:immich_mobile/models/auth/auth_state.model.dart';
import 'package:immich_mobile/models/auth/login_response.model.dart';
import 'package:immich_mobile/providers/api.provider.dart';
import 'package:immich_mobile/services/api.service.dart';
import 'package:immich_mobile/services/auth.service.dart';
@@ -98,7 +98,7 @@ class AuthNotifier extends StateNotifier<AuthState> {
Future<bool> saveAuthInfo({
required String accessToken,
}) async {
_apiService.setAccessToken(accessToken);
await _apiService.setAccessToken(accessToken);
// Get the deviceid from the store if it exists, otherwise generate a new one
String deviceId =
@@ -141,13 +141,13 @@ class AuthNotifier extends StateNotifier<AuthState> {
// If the user information is successfully retrieved, update the store
// Due to the flow of the code, this will always happen on first login
if (userResponse != null) {
Store.put(StoreKey.deviceId, deviceId);
Store.put(StoreKey.deviceIdHash, fastHash(deviceId));
Store.put(
await Store.put(StoreKey.deviceId, deviceId);
await Store.put(StoreKey.deviceIdHash, fastHash(deviceId));
await Store.put(
StoreKey.currentUser,
User.fromUserDto(userResponse, userPreferences),
);
Store.put(StoreKey.accessToken, accessToken);
await Store.put(StoreKey.accessToken, accessToken);
user = User.fromUserDto(userResponse, userPreferences);
} else {
@@ -173,12 +173,12 @@ class AuthNotifier extends StateNotifier<AuthState> {
return true;
}
Future<void> saveWifiName(String wifiName) {
return Store.put(StoreKey.preferredWifiName, wifiName);
Future<void> saveWifiName(String wifiName) async {
await Store.put(StoreKey.preferredWifiName, wifiName);
}
Future<void> saveLocalEndpoint(String url) {
return Store.put(StoreKey.localEndpoint, url);
Future<void> saveLocalEndpoint(String url) async {
await Store.put(StoreKey.localEndpoint, url);
}
String? getSavedWifiName() {
@@ -0,0 +1,7 @@
import 'package:isar/isar.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'db.provider.g.dart';
@Riverpod(keepAlive: true)
Isar isar(IsarRef ref) => throw UnimplementedError('isar');
+24
View File
@@ -0,0 +1,24 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'db.provider.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
String _$isarHash() => r'69d3a06aa7e69a4381478e03f7956eb07d7f7feb';
/// See also [isar].
@ProviderFor(isar)
final isarProvider = Provider<Isar>.internal(
isar,
name: r'isarProvider',
debugGetCreateSourceHash:
const bool.fromEnvironment('dart.vm.product') ? null : _$isarHash,
dependencies: null,
allTransitiveDependencies: null,
);
typedef IsarRef = ProviderRef<Isar>;
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
@@ -0,0 +1,10 @@
import 'package:immich_mobile/domain/interfaces/store.interface.dart';
import 'package:immich_mobile/infrastructure/repositories/store.repository.dart';
import 'package:immich_mobile/providers/infrastructure/db.provider.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'store.provider.g.dart';
@riverpod
IStoreRepository storeRepository(StoreRepositoryRef ref) =>
IsarStoreRepository(ref.watch(isarProvider));
@@ -0,0 +1,25 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'store.provider.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
String _$storeRepositoryHash() => r'9f378b96e552151fa14a8c8ce2c30a5f38f436ed';
/// See also [storeRepository].
@ProviderFor(storeRepository)
final storeRepositoryProvider = AutoDisposeProvider<IStoreRepository>.internal(
storeRepository,
name: r'storeRepositoryProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$storeRepositoryHash,
dependencies: null,
allTransitiveDependencies: null,
);
typedef StoreRepositoryRef = AutoDisposeProviderRef<IStoreRepository>;
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
+1 -1
View File
@@ -23,7 +23,7 @@ class CurrentUserProvider extends StateNotifier<User?> {
final user = await _apiService.usersApi.getMyUser();
final userPreferences = await _apiService.usersApi.getMyPreferences();
if (user != null) {
Store.put(
await Store.put(
StoreKey.currentUser,
User.fromUserDto(user, userPreferences),
);