|
@@ -1,12 +1,18 @@
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/modules/album/services/album.service.dart';
|
|
import 'package:immich_mobile/modules/album/services/album.service.dart';
|
|
|
|
+import 'package:immich_mobile/modules/album/services/album_cache.service.dart';
|
|
import 'package:openapi/api.dart';
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
|
class SharedAlbumNotifier extends StateNotifier<List<AlbumResponseDto>> {
|
|
class SharedAlbumNotifier extends StateNotifier<List<AlbumResponseDto>> {
|
|
- SharedAlbumNotifier(this._sharedAlbumService) : super([]);
|
|
|
|
|
|
+ SharedAlbumNotifier(this._sharedAlbumService, this._sharedAlbumCacheService) : super([]);
|
|
|
|
|
|
final AlbumService _sharedAlbumService;
|
|
final AlbumService _sharedAlbumService;
|
|
|
|
+ final SharedAlbumCacheService _sharedAlbumCacheService;
|
|
|
|
+
|
|
|
|
+ _cacheState() {
|
|
|
|
+ _sharedAlbumCacheService.put(state);
|
|
|
|
+ }
|
|
|
|
|
|
Future<AlbumResponseDto?> createSharedAlbum(
|
|
Future<AlbumResponseDto?> createSharedAlbum(
|
|
String albumName,
|
|
String albumName,
|
|
@@ -22,6 +28,7 @@ class SharedAlbumNotifier extends StateNotifier<List<AlbumResponseDto>> {
|
|
|
|
|
|
if (newAlbum != null) {
|
|
if (newAlbum != null) {
|
|
state = [...state, newAlbum];
|
|
state = [...state, newAlbum];
|
|
|
|
+ _cacheState();
|
|
}
|
|
}
|
|
|
|
|
|
return newAlbum;
|
|
return newAlbum;
|
|
@@ -33,16 +40,22 @@ class SharedAlbumNotifier extends StateNotifier<List<AlbumResponseDto>> {
|
|
}
|
|
}
|
|
|
|
|
|
getAllSharedAlbums() async {
|
|
getAllSharedAlbums() async {
|
|
|
|
+ if (await _sharedAlbumCacheService.isValid() && state.isEmpty) {
|
|
|
|
+ state = await _sharedAlbumCacheService.get();
|
|
|
|
+ }
|
|
|
|
+
|
|
List<AlbumResponseDto>? sharedAlbums =
|
|
List<AlbumResponseDto>? sharedAlbums =
|
|
await _sharedAlbumService.getAlbums(isShared: true);
|
|
await _sharedAlbumService.getAlbums(isShared: true);
|
|
|
|
|
|
if (sharedAlbums != null) {
|
|
if (sharedAlbums != null) {
|
|
state = sharedAlbums;
|
|
state = sharedAlbums;
|
|
|
|
+ _cacheState();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
deleteAlbum(String albumId) async {
|
|
deleteAlbum(String albumId) async {
|
|
state = state.where((album) => album.id != albumId).toList();
|
|
state = state.where((album) => album.id != albumId).toList();
|
|
|
|
+ _cacheState();
|
|
}
|
|
}
|
|
|
|
|
|
Future<bool> leaveAlbum(String albumId) async {
|
|
Future<bool> leaveAlbum(String albumId) async {
|
|
@@ -50,6 +63,7 @@ class SharedAlbumNotifier extends StateNotifier<List<AlbumResponseDto>> {
|
|
|
|
|
|
if (res) {
|
|
if (res) {
|
|
state = state.where((album) => album.id != albumId).toList();
|
|
state = state.where((album) => album.id != albumId).toList();
|
|
|
|
+ _cacheState();
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
return false;
|
|
return false;
|
|
@@ -72,7 +86,10 @@ class SharedAlbumNotifier extends StateNotifier<List<AlbumResponseDto>> {
|
|
|
|
|
|
final sharedAlbumProvider =
|
|
final sharedAlbumProvider =
|
|
StateNotifierProvider<SharedAlbumNotifier, List<AlbumResponseDto>>((ref) {
|
|
StateNotifierProvider<SharedAlbumNotifier, List<AlbumResponseDto>>((ref) {
|
|
- return SharedAlbumNotifier(ref.watch(albumServiceProvider));
|
|
|
|
|
|
+ return SharedAlbumNotifier(
|
|
|
|
+ ref.watch(albumServiceProvider),
|
|
|
|
+ ref.watch(sharedAlbumCacheServiceProvider),
|
|
|
|
+ );
|
|
});
|
|
});
|
|
|
|
|
|
final sharedAlbumDetailProvider = FutureProvider.autoDispose
|
|
final sharedAlbumDetailProvider = FutureProvider.autoDispose
|