mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
Implemented multi select interaction (#13)
This commit is contained in:
parent
6ad77e9434
commit
328f382f86
7 changed files with 343 additions and 124 deletions
|
|
@ -0,0 +1,63 @@
|
|||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/modules/home/models/home_page_state.model.dart';
|
||||
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
||||
|
||||
class HomePageStateNotifier extends StateNotifier<HomePageState> {
|
||||
HomePageStateNotifier()
|
||||
: super(
|
||||
HomePageState(
|
||||
isMultiSelectEnable: false,
|
||||
selectedItems: {},
|
||||
selectedDateGroup: {},
|
||||
),
|
||||
);
|
||||
|
||||
void addSelectedDateGroup(String dateGroupTitle) {
|
||||
state = state.copyWith(selectedDateGroup: {...state.selectedDateGroup, dateGroupTitle});
|
||||
}
|
||||
|
||||
void removeSelectedDateGroup(String dateGroupTitle) {
|
||||
var currentDateGroup = state.selectedDateGroup;
|
||||
|
||||
currentDateGroup.removeWhere((e) => e == dateGroupTitle);
|
||||
|
||||
state = state.copyWith(selectedDateGroup: currentDateGroup);
|
||||
}
|
||||
|
||||
void enableMultiSelect(Set<ImmichAsset> selectedItems) {
|
||||
state = state.copyWith(isMultiSelectEnable: true, selectedItems: selectedItems);
|
||||
}
|
||||
|
||||
void disableMultiSelect() {
|
||||
state = state.copyWith(isMultiSelectEnable: false, selectedItems: {}, selectedDateGroup: {});
|
||||
}
|
||||
|
||||
void addSingleSelectedItem(ImmichAsset asset) {
|
||||
state = state.copyWith(selectedItems: {...state.selectedItems, asset});
|
||||
}
|
||||
|
||||
void addMultipleSelectedItems(List<ImmichAsset> assets) {
|
||||
state = state.copyWith(selectedItems: {...state.selectedItems, ...assets});
|
||||
}
|
||||
|
||||
void removeSingleSelectedItem(ImmichAsset asset) {
|
||||
Set<ImmichAsset> currentList = state.selectedItems;
|
||||
|
||||
currentList.removeWhere((e) => e.id == asset.id);
|
||||
|
||||
state = state.copyWith(selectedItems: currentList);
|
||||
}
|
||||
|
||||
void removeMultipleSelectedItem(List<ImmichAsset> assets) {
|
||||
Set<ImmichAsset> currentList = state.selectedItems;
|
||||
|
||||
for (ImmichAsset asset in assets) {
|
||||
currentList.removeWhere((e) => e.id == asset.id);
|
||||
}
|
||||
|
||||
state = state.copyWith(selectedItems: currentList);
|
||||
}
|
||||
}
|
||||
|
||||
final homePageStateProvider =
|
||||
StateNotifierProvider<HomePageStateNotifier, HomePageState>(((ref) => HomePageStateNotifier()));
|
||||
Loading…
Add table
Add a link
Reference in a new issue