mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
@ -30,7 +30,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
Timer _timer = Timer(const Duration(microseconds: 0), () {});
|
||||
|
||||
Future<void> _onCommunityUpdate(
|
||||
void _onCommunityUpdate(
|
||||
OnCommunityUpdated event,
|
||||
Emitter<SpaceTreeState> emit,
|
||||
) async {
|
||||
@ -54,13 +54,12 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _fetchSpaces(
|
||||
InitialEvent event, Emitter<SpaceTreeState> emit) async {
|
||||
_fetchSpaces(InitialEvent event, Emitter<SpaceTreeState> emit) async {
|
||||
emit(SpaceTreeLoadingState());
|
||||
try {
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
|
||||
final paginationModel = await CommunitySpaceManagementApi()
|
||||
PaginationModel paginationModel = await CommunitySpaceManagementApi()
|
||||
.fetchCommunitiesAndSpaces(projectId: projectUuid, page: 1);
|
||||
|
||||
// List<CommunityModel> updatedCommunities = await Future.wait(
|
||||
@ -90,11 +89,10 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _fetchPaginationSpaces(
|
||||
PaginationEvent event, Emitter<SpaceTreeState> emit) async {
|
||||
_fetchPaginationSpaces(PaginationEvent event, Emitter<SpaceTreeState> emit) async {
|
||||
emit(state.copyWith(paginationIsLoading: true));
|
||||
var paginationModel = event.paginationModel;
|
||||
final communities = List<CommunityModel>.from(event.communities);
|
||||
PaginationModel paginationModel = event.paginationModel;
|
||||
List<CommunityModel> communities = List<CommunityModel>.from(event.communities);
|
||||
try {
|
||||
if (paginationModel.hasNext && state.searchQuery.isEmpty) {
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
@ -116,7 +114,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
paginationIsLoading: false));
|
||||
}
|
||||
|
||||
Future<void> _onCommunityAdded(
|
||||
void _onCommunityAdded(
|
||||
OnCommunityAdded event, Emitter<SpaceTreeState> emit) async {
|
||||
final updatedCommunities = List<CommunityModel>.from(state.communityList);
|
||||
updatedCommunities.add(event.newCommunity);
|
||||
@ -124,11 +122,11 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
emit(state.copyWith(communitiesList: updatedCommunities));
|
||||
}
|
||||
|
||||
Future<void> _onCommunityExpanded(
|
||||
_onCommunityExpanded(
|
||||
OnCommunityExpanded event, Emitter<SpaceTreeState> emit) async {
|
||||
try {
|
||||
final updatedExpandedCommunityList =
|
||||
List<String>.from(state.expandedCommunities);
|
||||
List<String> updatedExpandedCommunityList =
|
||||
List.from(state.expandedCommunities);
|
||||
|
||||
if (updatedExpandedCommunityList.contains(event.communityId)) {
|
||||
updatedExpandedCommunityList.remove(event.communityId);
|
||||
@ -144,10 +142,9 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onSpaceExpanded(
|
||||
OnSpaceExpanded event, Emitter<SpaceTreeState> emit) async {
|
||||
_onSpaceExpanded(OnSpaceExpanded event, Emitter<SpaceTreeState> emit) async {
|
||||
try {
|
||||
final updatedExpandedSpacesList = List<String>.from(state.expandedSpaces);
|
||||
List<String> updatedExpandedSpacesList = List.from(state.expandedSpaces);
|
||||
|
||||
if (updatedExpandedSpacesList.contains(event.spaceId)) {
|
||||
updatedExpandedSpacesList.remove(event.spaceId);
|
||||
@ -161,21 +158,20 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onCommunitySelected(
|
||||
_onCommunitySelected(
|
||||
OnCommunitySelected event, Emitter<SpaceTreeState> emit) async {
|
||||
try {
|
||||
final updatedSelectedCommunities =
|
||||
List<String>.from(state.selectedCommunities.toSet().toList());
|
||||
final updatedSelectedSpaces =
|
||||
List<String>.from(state.selectedSpaces.toSet().toList());
|
||||
final updatedSoldChecks =
|
||||
List<String>.from(state.soldCheck.toSet().toList());
|
||||
final communityAndSpaces =
|
||||
Map<String, List<String>>.from(state.selectedCommunityAndSpaces);
|
||||
final selectedSpacesInCommunity =
|
||||
List<String> updatedSelectedCommunities =
|
||||
List.from(state.selectedCommunities.toSet().toList());
|
||||
List<String> updatedSelectedSpaces =
|
||||
List.from(state.selectedSpaces.toSet().toList());
|
||||
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
|
||||
Map<String, List<String>> communityAndSpaces =
|
||||
Map.from(state.selectedCommunityAndSpaces);
|
||||
List<String> selectedSpacesInCommunity =
|
||||
communityAndSpaces[event.communityId] ?? [];
|
||||
|
||||
final childrenIds = _getAllChildIds(event.children);
|
||||
List<String> childrenIds = _getAllChildIds(event.children);
|
||||
|
||||
if (!updatedSelectedCommunities.contains(event.communityId)) {
|
||||
// Select the community and all its children
|
||||
@ -202,25 +198,23 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onSpaceSelected(
|
||||
OnSpaceSelected event, Emitter<SpaceTreeState> emit) async {
|
||||
_onSpaceSelected(OnSpaceSelected event, Emitter<SpaceTreeState> emit) async {
|
||||
try {
|
||||
final updatedSelectedCommunities =
|
||||
List<String>.from(state.selectedCommunities.toSet().toList());
|
||||
final updatedSelectedSpaces =
|
||||
List<String>.from(state.selectedSpaces.toSet().toList());
|
||||
final updatedSoldChecks =
|
||||
List<String>.from(state.soldCheck.toSet().toList());
|
||||
final communityAndSpaces =
|
||||
Map<String, List<String>>.from(state.selectedCommunityAndSpaces);
|
||||
List<String> updatedSelectedCommunities =
|
||||
List.from(state.selectedCommunities.toSet().toList());
|
||||
List<String> updatedSelectedSpaces =
|
||||
List.from(state.selectedSpaces.toSet().toList());
|
||||
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
|
||||
Map<String, List<String>> communityAndSpaces =
|
||||
Map.from(state.selectedCommunityAndSpaces);
|
||||
|
||||
final selectedSpacesInCommunity =
|
||||
List<String> selectedSpacesInCommunity =
|
||||
communityAndSpaces[event.communityModel.uuid] ?? [];
|
||||
|
||||
final childrenIds = _getAllChildIds(event.children);
|
||||
var isChildSelected = false;
|
||||
List<String> childrenIds = _getAllChildIds(event.children);
|
||||
bool isChildSelected = false;
|
||||
|
||||
for (final id in childrenIds) {
|
||||
for (String id in childrenIds) {
|
||||
if (updatedSelectedSpaces.contains(id)) {
|
||||
isChildSelected = true;
|
||||
}
|
||||
@ -238,9 +232,9 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
selectedSpacesInCommunity.addAll(childrenIds);
|
||||
}
|
||||
|
||||
final spaces =
|
||||
List<String> spaces =
|
||||
_getThePathToChild(event.communityModel.uuid, event.spaceId);
|
||||
for (final space in spaces) {
|
||||
for (String space in spaces) {
|
||||
if (!updatedSelectedSpaces.contains(space) &&
|
||||
!updatedSoldChecks.contains(space)) {
|
||||
updatedSoldChecks.add(space);
|
||||
@ -264,7 +258,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
updatedSoldChecks.remove(event.spaceId);
|
||||
|
||||
final parents =
|
||||
List<String> parents =
|
||||
_getThePathToChild(event.communityModel.uuid, event.spaceId)
|
||||
.toSet()
|
||||
.toList();
|
||||
@ -274,7 +268,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
updatedSelectedCommunities.remove(event.communityModel.uuid);
|
||||
} else {
|
||||
// Check if any parent has selected children
|
||||
for (final space in parents) {
|
||||
for (String space in parents) {
|
||||
if (!_noChildrenSelected(
|
||||
event.communityModel, space, updatedSelectedSpaces, parents)) {
|
||||
updatedSoldChecks.remove(space);
|
||||
@ -301,17 +295,17 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
}
|
||||
|
||||
bool _noChildrenSelected(CommunityModel community, String spaceId,
|
||||
_noChildrenSelected(CommunityModel community, String spaceId,
|
||||
List<String> selectedSpaces, List<String> parents) {
|
||||
if (selectedSpaces.contains(spaceId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final children = _getAllChildSpaces(community.spaces);
|
||||
for (final child in children) {
|
||||
List<SpaceModel> children = _getAllChildSpaces(community.spaces);
|
||||
for (var child in children) {
|
||||
if (spaceId == child.uuid) {
|
||||
final ids = _getAllChildIds(child.children);
|
||||
for (final id in ids) {
|
||||
List<String> ids = _getAllChildIds(child.children);
|
||||
for (var id in ids) {
|
||||
if (selectedSpaces.contains(id)) {
|
||||
return true;
|
||||
}
|
||||
@ -322,15 +316,14 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> _onSearch(
|
||||
SearchQueryEvent event, Emitter<SpaceTreeState> emit) async {
|
||||
_onSearch(SearchQueryEvent event, Emitter<SpaceTreeState> emit) async {
|
||||
try {
|
||||
const duration = Duration(seconds: 1);
|
||||
if (_timer.isActive) {
|
||||
_timer.cancel(); // clear timer
|
||||
}
|
||||
_timer = Timer(
|
||||
duration, () async => add(DebouncedSearchEvent(event.searchQuery)));
|
||||
_timer =
|
||||
Timer(duration, () async => add(DebouncedSearchEvent(event.searchQuery)));
|
||||
|
||||
// List<CommunityModel> communities = List.from(state.communityList);
|
||||
// List<CommunityModel> filteredCommunity = [];
|
||||
@ -354,12 +347,12 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onDebouncedSearch(
|
||||
_onDebouncedSearch(
|
||||
DebouncedSearchEvent event, Emitter<SpaceTreeState> emit) async {
|
||||
emit(state.copyWith(
|
||||
isSearching: true,
|
||||
));
|
||||
var paginationModel = const PaginationModel.emptyConstructor();
|
||||
PaginationModel paginationModel = const PaginationModel.emptyConstructor();
|
||||
try {
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
|
||||
@ -374,8 +367,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
searchQuery: event.searchQuery));
|
||||
}
|
||||
|
||||
Future<void> _clearAllData(
|
||||
ClearAllData event, Emitter<SpaceTreeState> emit) async {
|
||||
_clearAllData(ClearAllData event, Emitter<SpaceTreeState> emit) async {
|
||||
try {
|
||||
emit(state.copyWith(
|
||||
communitiesList: [],
|
||||
@ -393,8 +385,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _clearCachedData(
|
||||
ClearCachedData event, Emitter<SpaceTreeState> emit) async {
|
||||
_clearCachedData(ClearCachedData event, Emitter<SpaceTreeState> emit) async {
|
||||
try {
|
||||
emit(state.copyWith(
|
||||
communitiesList: state.communityList,
|
||||
@ -422,8 +413,8 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
// }
|
||||
|
||||
List<String> _getAllChildIds(List<SpaceModel> spaces) {
|
||||
final ids = <String>[];
|
||||
for (final child in spaces) {
|
||||
List<String> ids = [];
|
||||
for (var child in spaces) {
|
||||
ids.add(child.uuid!);
|
||||
ids.addAll(_getAllChildIds(child.children));
|
||||
}
|
||||
@ -431,8 +422,8 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
|
||||
List<SpaceModel> _getAllChildSpaces(List<SpaceModel> spaces) {
|
||||
final children = <SpaceModel>[];
|
||||
for (final child in spaces) {
|
||||
List<SpaceModel> children = [];
|
||||
for (var child in spaces) {
|
||||
children.add(child);
|
||||
children.addAll(_getAllChildSpaces(child.children));
|
||||
}
|
||||
@ -441,9 +432,9 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
|
||||
bool _anySpacesSelectedInCommunity(CommunityModel community,
|
||||
List<String> selectedSpaces, List<String> partialCheckedList) {
|
||||
var result = false;
|
||||
final ids = _getAllChildIds(community.spaces);
|
||||
for (final id in ids) {
|
||||
bool result = false;
|
||||
List<String> ids = _getAllChildIds(community.spaces);
|
||||
for (var id in ids) {
|
||||
result = selectedSpaces.contains(id) || partialCheckedList.contains(id);
|
||||
if (result) {
|
||||
return result;
|
||||
@ -453,11 +444,11 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
|
||||
List<String> _getThePathToChild(String communityId, String selectedSpaceId) {
|
||||
var ids = <String>[];
|
||||
for (final community in state.communityList) {
|
||||
List<String> ids = [];
|
||||
for (var community in state.communityList) {
|
||||
if (community.uuid == communityId) {
|
||||
for (final space in community.spaces) {
|
||||
final list = <String>[];
|
||||
for (var space in community.spaces) {
|
||||
List<String> list = [];
|
||||
list.add(space.uuid!);
|
||||
ids = _getAllParentsIds(space, selectedSpaceId, List.from(list));
|
||||
if (ids.isNotEmpty) {
|
||||
@ -471,7 +462,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
|
||||
List<String> _getAllParentsIds(
|
||||
SpaceModel child, String spaceId, List<String> listIds) {
|
||||
final ids = listIds;
|
||||
List<String> ids = listIds;
|
||||
|
||||
ids.add(child.uuid ?? '');
|
||||
|
||||
@ -480,8 +471,8 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
|
||||
if (child.children.isNotEmpty) {
|
||||
for (final space in child.children) {
|
||||
final result = _getAllParentsIds(space, spaceId, List.from(ids));
|
||||
for (var space in child.children) {
|
||||
var result = _getAllParentsIds(space, spaceId, List.from(ids));
|
||||
if (result.isNotEmpty) {
|
||||
return result;
|
||||
}
|
||||
@ -492,7 +483,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
return [];
|
||||
}
|
||||
|
||||
Future<void> _onSpaceTreeClearSelectionEvent(
|
||||
void _onSpaceTreeClearSelectionEvent(
|
||||
SpaceTreeClearSelectionEvent event,
|
||||
Emitter<SpaceTreeState> emit,
|
||||
) async {
|
||||
@ -505,7 +496,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onAnalyticsClearAllSpaceTreeSelectionsEvent(
|
||||
void _onAnalyticsClearAllSpaceTreeSelectionsEvent(
|
||||
AnalyticsClearAllSpaceTreeSelectionsEvent event,
|
||||
Emitter<SpaceTreeState> emit,
|
||||
) async {
|
||||
|
@ -44,16 +44,15 @@ class SpaceTreeState extends Equatable {
|
||||
PaginationModel? paginationModel,
|
||||
bool? paginationIsLoading}) {
|
||||
return SpaceTreeState(
|
||||
communityList: communitiesList ?? communityList,
|
||||
communityList: communitiesList ?? this.communityList,
|
||||
filteredCommunity: filteredCommunity ?? this.filteredCommunity,
|
||||
expandedSpaces: expandedSpaces ?? this.expandedSpaces,
|
||||
expandedCommunities: expandedCommunity ?? expandedCommunities,
|
||||
expandedCommunities: expandedCommunity ?? this.expandedCommunities,
|
||||
selectedCommunities: selectedCommunities ?? this.selectedCommunities,
|
||||
selectedSpaces: selectedSpaces ?? this.selectedSpaces,
|
||||
soldCheck: soldCheck ?? this.soldCheck,
|
||||
isSearching: isSearching ?? this.isSearching,
|
||||
selectedCommunityAndSpaces:
|
||||
selectedCommunityAndSpaces ?? this.selectedCommunityAndSpaces,
|
||||
selectedCommunityAndSpaces: selectedCommunityAndSpaces ?? this.selectedCommunityAndSpaces,
|
||||
searchQuery: searchQuery ?? this.searchQuery,
|
||||
paginationModel: paginationModel ?? this.paginationModel,
|
||||
paginationIsLoading: paginationIsLoading ?? this.paginationIsLoading);
|
||||
|
Reference in New Issue
Block a user