mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
updated flow for create community
This commit is contained in:
@ -25,6 +25,7 @@ class SpaceManagementBloc
|
|||||||
on<SaveSpacesEvent>(_onSaveSpaces);
|
on<SaveSpacesEvent>(_onSaveSpaces);
|
||||||
on<FetchProductsEvent>(_onFetchProducts);
|
on<FetchProductsEvent>(_onFetchProducts);
|
||||||
on<SelectSpaceEvent>(_onSelectSpace);
|
on<SelectSpaceEvent>(_onSelectSpace);
|
||||||
|
on<NewCommunityEvent>(_onNewCommunity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onUpdateCommunity(
|
void _onUpdateCommunity(
|
||||||
@ -83,6 +84,26 @@ class SpaceManagementBloc
|
|||||||
return await _api.getSpaceHierarchy(communityUuid);
|
return await _api.getSpaceHierarchy(communityUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onNewCommunity(
|
||||||
|
NewCommunityEvent event,
|
||||||
|
Emitter<SpaceManagementState> emit,
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
if (event.communities.isEmpty) {
|
||||||
|
emit(const SpaceManagementError('No communities provided.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(BlankState(
|
||||||
|
communities: event.communities,
|
||||||
|
products: _cachedProducts ?? [],
|
||||||
|
));
|
||||||
|
print('SpaceManagementLoaded state emitted with communities.');
|
||||||
|
} catch (error) {
|
||||||
|
emit(SpaceManagementError('Error loading communities: $error'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _onLoadCommunityAndSpaces(
|
void _onLoadCommunityAndSpaces(
|
||||||
LoadCommunityAndSpacesEvent event,
|
LoadCommunityAndSpacesEvent event,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
@ -151,14 +172,16 @@ class SpaceManagementBloc
|
|||||||
await _api.createCommunity(event.name, event.description);
|
await _api.createCommunity(event.name, event.description);
|
||||||
|
|
||||||
if (newCommunity != null) {
|
if (newCommunity != null) {
|
||||||
if (previousState is SpaceManagementLoaded) {
|
if (previousState is SpaceManagementLoaded ||
|
||||||
final updatedCommunities =
|
previousState is BlankState) {
|
||||||
List<CommunityModel>.from(previousState.communities)
|
final prevCommunities = List<CommunityModel>.from(
|
||||||
..add(newCommunity);
|
(previousState as dynamic).communities,
|
||||||
|
);
|
||||||
|
final updatedCommunities = prevCommunities..add(newCommunity);
|
||||||
emit(SpaceManagementLoaded(
|
emit(SpaceManagementLoaded(
|
||||||
communities: updatedCommunities,
|
communities: updatedCommunities,
|
||||||
products: _cachedProducts ?? [],
|
products: _cachedProducts ?? [],
|
||||||
selectedCommunity: null,
|
selectedCommunity: newCommunity,
|
||||||
selectedSpace: null));
|
selectedSpace: null));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -200,7 +223,8 @@ class SpaceManagementBloc
|
|||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (previousState is SpaceManagementLoaded) {
|
if (previousState is SpaceManagementLoaded ||
|
||||||
|
previousState is BlankState) {
|
||||||
final communities = List<CommunityModel>.from(
|
final communities = List<CommunityModel>.from(
|
||||||
(previousState as dynamic).communities,
|
(previousState as dynamic).communities,
|
||||||
);
|
);
|
||||||
|
@ -108,6 +108,15 @@ class SelectCommunityEvent extends SpaceManagementEvent {
|
|||||||
List<Object> get props => [];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NewCommunityEvent extends SpaceManagementEvent {
|
||||||
|
final List<CommunityModel> communities;
|
||||||
|
|
||||||
|
const NewCommunityEvent({required this.communities});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [communities];
|
||||||
|
}
|
||||||
|
|
||||||
class SelectSpaceEvent extends SpaceManagementEvent {
|
class SelectSpaceEvent extends SpaceManagementEvent {
|
||||||
final CommunityModel? selectedCommunity;
|
final CommunityModel? selectedCommunity;
|
||||||
final SpaceModel? selectedSpace;
|
final SpaceModel? selectedSpace;
|
||||||
|
@ -27,6 +27,16 @@ class SpaceManagementLoaded extends SpaceManagementState {
|
|||||||
this.selectedSpace});
|
this.selectedSpace});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BlankState extends SpaceManagementState {
|
||||||
|
final List<CommunityModel> communities;
|
||||||
|
final List<ProductModel> products;
|
||||||
|
|
||||||
|
BlankState({
|
||||||
|
required this.communities,
|
||||||
|
required this.products,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
class SpaceCreationSuccess extends SpaceManagementState {
|
class SpaceCreationSuccess extends SpaceManagementState {
|
||||||
final List<SpaceModel> spaces;
|
final List<SpaceModel> spaces;
|
||||||
|
|
||||||
|
@ -45,6 +45,13 @@ 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());
|
||||||
|
} else if (state is BlankState) {
|
||||||
|
return LoadedSpaceView(
|
||||||
|
communities: state.communities,
|
||||||
|
selectedCommunity: null,
|
||||||
|
selectedSpace: null,
|
||||||
|
products: state.products,
|
||||||
|
);
|
||||||
} else if (state is SpaceManagementLoaded) {
|
} else if (state is SpaceManagementLoaded) {
|
||||||
return LoadedSpaceView(
|
return LoadedSpaceView(
|
||||||
communities: state.communities,
|
communities: state.communities,
|
||||||
|
@ -34,7 +34,9 @@ class _LoadedStateViewState extends State<LoadedSpaceView> {
|
|||||||
children: [
|
children: [
|
||||||
SidebarWidget(
|
SidebarWidget(
|
||||||
communities: widget.communities,
|
communities: widget.communities,
|
||||||
selectedSpaceUuid: widget.selectedSpace?.uuid,
|
selectedSpaceUuid: widget.selectedSpace?.uuid ??
|
||||||
|
widget.selectedCommunity?.uuid ??
|
||||||
|
'',
|
||||||
),
|
),
|
||||||
CommunityStructureArea(
|
CommunityStructureArea(
|
||||||
selectedCommunity: widget.selectedCommunity,
|
selectedCommunity: widget.selectedCommunity,
|
||||||
|
@ -14,18 +14,11 @@ import 'package:syncrow_web/utils/constants/assets.dart';
|
|||||||
import 'package:syncrow_web/utils/style.dart';
|
import 'package:syncrow_web/utils/style.dart';
|
||||||
|
|
||||||
class SidebarWidget extends StatefulWidget {
|
class SidebarWidget extends StatefulWidget {
|
||||||
final Function(CommunityModel)? onCommunitySelected;
|
|
||||||
final Function(SpaceModel?)? onSpaceSelected;
|
|
||||||
final List<CommunityModel> communities;
|
final List<CommunityModel> communities;
|
||||||
final Function(String?)? onSelectedSpaceChanged; // New callback
|
|
||||||
|
|
||||||
final String? selectedSpaceUuid;
|
final String? selectedSpaceUuid;
|
||||||
|
|
||||||
const SidebarWidget({
|
const SidebarWidget({
|
||||||
super.key,
|
super.key,
|
||||||
this.onCommunitySelected,
|
|
||||||
this.onSpaceSelected,
|
|
||||||
this.onSelectedSpaceChanged,
|
|
||||||
required this.communities,
|
required this.communities,
|
||||||
this.selectedSpaceUuid,
|
this.selectedSpaceUuid,
|
||||||
});
|
});
|
||||||
@ -145,7 +138,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
)),
|
)),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () => _showCreateCommunityDialog(context),
|
onTap: () => _navigateToBlank(context),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 30,
|
width: 30,
|
||||||
height: 30,
|
height: 30,
|
||||||
@ -187,6 +180,15 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _navigateToBlank(BuildContext context) {
|
||||||
|
setState(() {
|
||||||
|
_selectedId = '';
|
||||||
|
});
|
||||||
|
context.read<SpaceManagementBloc>().add(
|
||||||
|
NewCommunityEvent(communities: widget.communities),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildCommunityTile(BuildContext context, CommunityModel community) {
|
Widget _buildCommunityTile(BuildContext context, CommunityModel community) {
|
||||||
bool hasChildren = community.spaces.isNotEmpty;
|
bool hasChildren = community.spaces.isNotEmpty;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user