mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-03 19:17:11 -05:00 
			
		
		
		
	* chore: bump dart sdk to 3.8 * chore: make build * make pigeon * chore: format files --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
		
			
				
	
	
		
			60 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
import 'package:hooks_riverpod/hooks_riverpod.dart';
 | 
						|
import 'package:immich_mobile/domain/models/album/local_album.model.dart';
 | 
						|
import 'package:immich_mobile/domain/services/local_album.service.dart';
 | 
						|
import 'package:immich_mobile/infrastructure/repositories/local_album.repository.dart';
 | 
						|
import 'package:immich_mobile/providers/infrastructure/album.provider.dart';
 | 
						|
 | 
						|
final backupAlbumProvider = StateNotifierProvider<BackupAlbumNotifier, List<LocalAlbum>>(
 | 
						|
  (ref) => BackupAlbumNotifier(ref.watch(localAlbumServiceProvider)),
 | 
						|
);
 | 
						|
 | 
						|
class BackupAlbumNotifier extends StateNotifier<List<LocalAlbum>> {
 | 
						|
  BackupAlbumNotifier(this._localAlbumService) : super([]) {
 | 
						|
    getAll();
 | 
						|
  }
 | 
						|
 | 
						|
  final LocalAlbumService _localAlbumService;
 | 
						|
 | 
						|
  Future<void> getAll() async {
 | 
						|
    state = await _localAlbumService.getAll(sortBy: {SortLocalAlbumsBy.assetCount});
 | 
						|
  }
 | 
						|
 | 
						|
  Future<void> selectAlbum(LocalAlbum album) async {
 | 
						|
    album = album.copyWith(backupSelection: BackupSelection.selected);
 | 
						|
    await _localAlbumService.update(album);
 | 
						|
 | 
						|
    state = state
 | 
						|
        .map(
 | 
						|
          (currentAlbum) => currentAlbum.id == album.id
 | 
						|
              ? currentAlbum.copyWith(backupSelection: BackupSelection.selected)
 | 
						|
              : currentAlbum,
 | 
						|
        )
 | 
						|
        .toList();
 | 
						|
  }
 | 
						|
 | 
						|
  Future<void> deselectAlbum(LocalAlbum album) async {
 | 
						|
    album = album.copyWith(backupSelection: BackupSelection.none);
 | 
						|
    await _localAlbumService.update(album);
 | 
						|
 | 
						|
    state = state
 | 
						|
        .map(
 | 
						|
          (currentAlbum) =>
 | 
						|
              currentAlbum.id == album.id ? currentAlbum.copyWith(backupSelection: BackupSelection.none) : currentAlbum,
 | 
						|
        )
 | 
						|
        .toList();
 | 
						|
  }
 | 
						|
 | 
						|
  Future<void> excludeAlbum(LocalAlbum album) async {
 | 
						|
    album = album.copyWith(backupSelection: BackupSelection.excluded);
 | 
						|
    await _localAlbumService.update(album);
 | 
						|
 | 
						|
    state = state
 | 
						|
        .map(
 | 
						|
          (currentAlbum) => currentAlbum.id == album.id
 | 
						|
              ? currentAlbum.copyWith(backupSelection: BackupSelection.excluded)
 | 
						|
              : currentAlbum,
 | 
						|
        )
 | 
						|
        .toList();
 | 
						|
  }
 | 
						|
}
 |