updated blank structure

This commit is contained in:
hannathkadher
2024-11-24 02:28:28 +04:00
parent 7806d3de7d
commit 5ac7eb0301
5 changed files with 30 additions and 8 deletions

View File

@ -27,10 +27,25 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
UpdateCommunityEvent event, UpdateCommunityEvent event,
Emitter<SpaceManagementState> emit, Emitter<SpaceManagementState> emit,
) async { ) async {
final previousState = state;
try { try {
emit(SpaceManagementLoading()); emit(SpaceManagementLoading());
final success = await _api.updateCommunity(event.communityUuid, event.name); final success = await _api.updateCommunity(event.communityUuid, event.name);
if (success) { if (success) {
if (previousState is SpaceManagementLoaded) {
final updatedCommunities = List<CommunityModel>.from(previousState.communities);
for(var community in updatedCommunities){
if(community.uuid == event.communityUuid){
community.name = event.name;
break;
}
}
emit(SpaceManagementLoaded(
communities: updatedCommunities,
products: previousState.products,
selectedCommunity: previousState.selectedCommunity,
));
}
add(LoadCommunityAndSpacesEvent()); add(LoadCommunityAndSpacesEvent());
} else { } else {
emit(const SpaceManagementError('Failed to update the community.')); emit(const SpaceManagementError('Failed to update the community.'));
@ -125,17 +140,16 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
emit(SpaceManagementLoading()); emit(SpaceManagementLoading());
try { try {
CommunityModel? newCommunity = await _api.createCommunity( CommunityModel? newCommunity = await _api.createCommunity(event.name, event.description);
event.name,
event.description
);
if (newCommunity != null) { if (newCommunity != null) {
if (previousState is SpaceManagementLoaded) { if (previousState is SpaceManagementLoaded) {
final updatedCommunities = List<CommunityModel>.from(previousState.communities) final updatedCommunities = List<CommunityModel>.from(previousState.communities)
..add(newCommunity); ..add(newCommunity);
emit(SpaceManagementLoaded( emit(SpaceManagementLoaded(
communities: updatedCommunities, products: _cachedProducts ?? [])); communities: updatedCommunities,
products: _cachedProducts ?? [],
selectedCommunity: newCommunity));
} }
} else { } else {
emit(const SpaceManagementError('Error creating community')); emit(const SpaceManagementError('Error creating community'));

View File

@ -16,9 +16,11 @@ class SpaceManagementLoading extends SpaceManagementState {}
class SpaceManagementLoaded extends SpaceManagementState { class SpaceManagementLoaded extends SpaceManagementState {
final List<CommunityModel> communities; final List<CommunityModel> communities;
final List<ProductModel> products; // Include products in the state final List<ProductModel> products;
CommunityModel? selectedCommunity; // Include products in the state
SpaceManagementLoaded({required this.communities, required this.products}); SpaceManagementLoaded(
{required this.communities, required this.products, this.selectedCommunity});
} }
class SpaceCreationSuccess extends SpaceManagementState { class SpaceCreationSuccess extends SpaceManagementState {

View File

@ -56,6 +56,8 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
); );
if (selectedIndex != -1) { if (selectedIndex != -1) {
selectedCommunity = state.communities[selectedIndex]; selectedCommunity = state.communities[selectedIndex];
} else if (state.selectedCommunity != null) {
selectedCommunity = state.selectedCommunity;
} else { } else {
selectedCommunity = null; selectedCommunity = null;
selectedSpace = null; selectedSpace = null;

View File

@ -109,7 +109,9 @@ class CommunityStructureHeader extends StatelessWidget {
onPressed: onSave, onPressed: onSave,
), ),
if (isSave) const SizedBox(width: 10), if (isSave) const SizedBox(width: 10),
if (communityName != null && communityName != '') /*
Commenting till finalize delete
if (communityName != null && communityName != '')
_buildButton( _buildButton(
label: "Delete", label: "Delete",
icon: SvgPicture.asset( icon: SvgPicture.asset(
@ -119,6 +121,7 @@ class CommunityStructureHeader extends StatelessWidget {
), ),
onPressed: onDelete, onPressed: onDelete,
), ),
*/
], ],
); );
} }

View File

@ -52,6 +52,7 @@ abstract class ColorsManager {
static const Color counterBackgroundColor = Color(0xCCF4F4F4); static const Color counterBackgroundColor = Color(0xCCF4F4F4);
static const Color neutralGray = Color(0xFFE5E5E5); static const Color neutralGray = Color(0xFFE5E5E5);
static const Color warningRed = Color(0xFFFF6465); static const Color warningRed = Color(0xFFFF6465);
static const Color borderColor = Color(0xFFE5E5E5);
} }
//background: #background: #5D5D5D; //background: #background: #5D5D5D;