Compare commits

...
5 changed files with 70 additions and 54 deletions
@@ -457,16 +457,17 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
emit(SpaceManagementLoading()); emit(SpaceManagementLoading());
try { try {
final spaceTreeState = event.context.read<SpaceTreeBloc>().state;
final updatedSpaces = final updatedSpaces =
await saveSpacesHierarchically(event.context, event.spaces, event.communityUuid); await saveSpacesHierarchically(event.context, event.spaces, event.communityUuid);
final allSpaces = await _fetchSpacesForCommunity(event.communityUuid); final allSpaces = await _fetchSpacesForCommunity(event.communityUuid);
emit(SpaceCreationSuccess(spaces: updatedSpaces)); emit(SpaceCreationSuccess(spaces: updatedSpaces));
if (previousState is SpaceManagementLoaded) { if (previousState is SpaceManagementLoaded) {
await _updateLoadedState( await _updateLoadedState(
event.context, spaceTreeState,
previousState, previousState,
allSpaces, allSpaces,
event.communityUuid, event.communityUuid,
@@ -483,15 +484,17 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
} }
Future<void> _updateLoadedState( Future<void> _updateLoadedState(
BuildContext context, SpaceTreeState spaceTreeState,
SpaceManagementLoaded previousState, SpaceManagementLoaded previousState,
List<SpaceModel> allSpaces, List<SpaceModel> allSpaces,
String communityUuid, String communityUuid,
Emitter<SpaceManagementState> emit, Emitter<SpaceManagementState> emit,
) async { ) async {
try {
var prevSpaceModels = await fetchSpaceModels(); var prevSpaceModels = await fetchSpaceModels();
await fetchTags(); await fetchTags();
final spaceTreeState = context.read<SpaceTreeBloc>().state;
final communities = spaceTreeState.searchQuery.isNotEmpty final communities = spaceTreeState.searchQuery.isNotEmpty
? spaceTreeState.filteredCommunity ? spaceTreeState.filteredCommunity
: spaceTreeState.communityList; : spaceTreeState.communityList;
@@ -507,12 +510,14 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
selectedCommunity: community, selectedCommunity: community,
selectedSpace: null, selectedSpace: null,
spaceModels: prevSpaceModels, spaceModels: prevSpaceModels,
allTags: _cachedTags ?? [])); allTags: _cachedTags ?? [],
));
return; return;
} else {
print("Community not found");
} }
} }
} catch (e, stackTrace) {
rethrow;
}
} }
Future<List<SpaceModel>> saveSpacesHierarchically( Future<List<SpaceModel>> saveSpacesHierarchically(
@@ -53,6 +53,9 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
builder: (context, state) { builder: (context, state) {
if (state is SpaceManagementLoading) { if (state is SpaceManagementLoading) {
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());
}
if (state is SpaceManagementInitial) {
return const Center(child: CircularProgressIndicator());
} else if (state is BlankState) { } else if (state is BlankState) {
return LoadedSpaceView( return LoadedSpaceView(
communities: state.communities, communities: state.communities,
@@ -526,6 +526,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
isNameFieldInvalid = true; isNameFieldInvalid = true;
}); });
return; return;
} else if (isNameFieldExist) {
return;
} else { } else {
String newName = enteredName.isNotEmpty ? enteredName : (widget.name ?? ''); String newName = enteredName.isNotEmpty ? enteredName : (widget.name ?? '');
if (newName.isNotEmpty) { if (newName.isNotEmpty) {
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart'; import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart'; import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
@@ -2,10 +2,10 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/common/widgets/empty_search_result_widget.dart';
import 'package:syncrow_web/common/widgets/search_bar.dart'; import 'package:syncrow_web/common/widgets/search_bar.dart';
import 'package:syncrow_web/common/widgets/sidebar_communities_list.dart'; import 'package:syncrow_web/common/widgets/sidebar_communities_list.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart'; import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_state.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
@@ -114,7 +114,9 @@ class _SidebarWidgetState extends State<SidebarWidget> {
return Container( return Container(
width: _width, width: _width,
decoration: subSectionContainerDecoration, decoration: subSectionContainerDecoration,
child: Column( child: spaceTreeState is SpaceTreeLoadingState
? const Center(child: CircularProgressIndicator())
: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@@ -124,10 +126,9 @@ class _SidebarWidgetState extends State<SidebarWidget> {
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Expanded( Expanded(
child: Visibility( child: Builder(
visible: filteredCommunities.isNotEmpty, builder: (_) {
replacement: const EmptySearchResultWidget(), return SidebarCommunitiesList(
child: SidebarCommunitiesList(
scrollController: _scrollController, scrollController: _scrollController,
onScrollToEnd: () {}, onScrollToEnd: () {},
communities: filteredCommunities, communities: filteredCommunities,
@@ -144,9 +145,15 @@ class _SidebarWidgetState extends State<SidebarWidget> {
} }
} }
return _buildCommunityTile(context, filteredCommunities[index]); return _buildCommunityTile(context, filteredCommunities[index]);
}), },
);
},
), ),
), ),
if (spaceTreeState.paginationIsLoading || spaceTreeState.isSearching)
Center(
child: CircularProgressIndicator(),
)
], ],
), ),
); );