Clear cache on edit dialog and fixed a selection issue

This commit is contained in:
Abdullah Alassaf
2025-02-26 02:59:17 +03:00
parent 553c77d1e3
commit 70cb12236b
5 changed files with 29 additions and 36 deletions

View File

@ -24,7 +24,7 @@ class _AddNewUserDialogState extends State<AddNewUserDialog> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider( return BlocProvider(
create: (BuildContext context) => UsersBloc() create: (BuildContext context) => UsersBloc()
..add(const LoadCommunityAndSpacesEvent()) // ..add(const LoadCommunityAndSpacesEvent())
..add(const RoleEvent()), ..add(const RoleEvent()),
child: BlocConsumer<UsersBloc, UsersState>( child: BlocConsumer<UsersBloc, UsersState>(
listener: (context, state) {}, listener: (context, state) {},

View File

@ -26,13 +26,12 @@ class _EditUserDialogState extends State<EditUserDialog> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider( return BlocProvider(
create: (BuildContext context) => UsersBloc() create: (BuildContext context) => UsersBloc()
..add(const LoadCommunityAndSpacesEvent()) // ..add(const LoadCommunityAndSpacesEvent())
..add(const RoleEvent()) ..add(const RoleEvent())
..add(GetUserByIdEvent(uuid: widget.userId)), ..add(GetUserByIdEvent(uuid: widget.userId)),
child: BlocConsumer<UsersBloc, UsersState>(listener: (context, state) { child: BlocConsumer<UsersBloc, UsersState>(listener: (context, state) {
if (state is SpacesLoadedState) { if (state is SpacesLoadedState) {
BlocProvider.of<UsersBloc>(context) BlocProvider.of<UsersBloc>(context).add(GetUserByIdEvent(uuid: widget.userId));
.add(GetUserByIdEvent(uuid: widget.userId));
} }
}, builder: (context, state) { }, builder: (context, state) {
final _blocRole = BlocProvider.of<UsersBloc>(context); final _blocRole = BlocProvider.of<UsersBloc>(context);
@ -40,8 +39,7 @@ class _EditUserDialogState extends State<EditUserDialog> {
return Dialog( return Dialog(
child: Container( child: Container(
decoration: const BoxDecoration( decoration: const BoxDecoration(
color: Colors.white, color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(20))),
borderRadius: BorderRadius.all(Radius.circular(20))),
width: 900, width: 900,
child: Column( child: Column(
children: [ children: [
@ -70,8 +68,7 @@ class _EditUserDialogState extends State<EditUserDialog> {
children: [ children: [
_buildStep1Indicator(1, "Basics", _blocRole), _buildStep1Indicator(1, "Basics", _blocRole),
_buildStep2Indicator(2, "Spaces", _blocRole), _buildStep2Indicator(2, "Spaces", _blocRole),
_buildStep3Indicator( _buildStep3Indicator(3, "Role & Permissions", _blocRole),
3, "Role & Permissions", _blocRole),
], ],
), ),
), ),
@ -119,15 +116,13 @@ class _EditUserDialogState extends State<EditUserDialog> {
if (currentStep < 3) { if (currentStep < 3) {
currentStep++; currentStep++;
if (currentStep == 2) { if (currentStep == 2) {
_blocRole _blocRole.add(CheckStepStatus(isEditUser: true));
.add(CheckStepStatus(isEditUser: true));
} else if (currentStep == 3) { } else if (currentStep == 3) {
_blocRole.add(const CheckSpacesStepStatus()); _blocRole.add(const CheckSpacesStepStatus());
} }
} else { } else {
_blocRole.add(EditInviteUsers( _blocRole
context: context, .add(EditInviteUsers(context: context, userId: widget.userId!));
userId: widget.userId!));
} }
}); });
}, },
@ -136,8 +131,7 @@ class _EditUserDialogState extends State<EditUserDialog> {
style: TextStyle( style: TextStyle(
color: (_blocRole.isCompleteSpaces == false || color: (_blocRole.isCompleteSpaces == false ||
_blocRole.isCompleteBasics == false || _blocRole.isCompleteBasics == false ||
_blocRole.isCompleteRolePermissions == _blocRole.isCompleteRolePermissions == false) &&
false) &&
currentStep == 3 currentStep == 3
? ColorsManager.grayColor ? ColorsManager.grayColor
: ColorsManager.secondaryColor), : ColorsManager.secondaryColor),
@ -210,12 +204,8 @@ class _EditUserDialogState extends State<EditUserDialog> {
label, label,
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
color: currentStep == step color: currentStep == step ? ColorsManager.blackColor : ColorsManager.greyColor,
? ColorsManager.blackColor fontWeight: currentStep == step ? FontWeight.bold : FontWeight.normal,
: ColorsManager.greyColor,
fontWeight: currentStep == step
? FontWeight.bold
: FontWeight.normal,
), ),
), ),
], ],
@ -273,12 +263,8 @@ class _EditUserDialogState extends State<EditUserDialog> {
label, label,
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
color: currentStep == step color: currentStep == step ? ColorsManager.blackColor : ColorsManager.greyColor,
? ColorsManager.blackColor fontWeight: currentStep == step ? FontWeight.bold : FontWeight.normal,
: ColorsManager.greyColor,
fontWeight: currentStep == step
? FontWeight.bold
: FontWeight.normal,
), ),
), ),
], ],
@ -335,12 +321,8 @@ class _EditUserDialogState extends State<EditUserDialog> {
label, label,
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
color: currentStep == step color: currentStep == step ? ColorsManager.blackColor : ColorsManager.greyColor,
? ColorsManager.blackColor fontWeight: currentStep == step ? FontWeight.bold : FontWeight.normal,
: ColorsManager.greyColor,
fontWeight: currentStep == step
? FontWeight.bold
: FontWeight.normal,
), ),
), ),
], ],

View File

@ -427,6 +427,7 @@ class UsersPage extends StatelessWidget {
isActive: true, isActive: true,
title: "Edit", title: "Edit",
onTap: () { onTap: () {
context.read<SpaceTreeBloc>().add(ClearCachedData());
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,

View File

@ -7,7 +7,6 @@ import 'package:syncrow_web/pages/routines/widgets/main_routine_view/routine_vie
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/view/space_tree_view.dart'; import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart';
import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/snack_bar.dart';
class RoutinesView extends StatefulWidget { class RoutinesView extends StatefulWidget {
const RoutinesView({super.key}); const RoutinesView({super.key});

View File

@ -91,6 +91,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList()); List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList());
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList()); List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
Map<String, List<String>> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces); Map<String, List<String>> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces);
List<String> selectedSpacesInCommunity = communityAndSpaces[event.communityId] ?? [];
List<String> childrenIds = _getAllChildIds(event.children); List<String> childrenIds = _getAllChildIds(event.children);
@ -98,14 +99,16 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
// Select the community and all its children // Select the community and all its children
updatedSelectedCommunities.add(event.communityId); updatedSelectedCommunities.add(event.communityId);
updatedSelectedSpaces.addAll(childrenIds); updatedSelectedSpaces.addAll(childrenIds);
selectedSpacesInCommunity.addAll(childrenIds);
} else { } else {
// Unselect the community and all its children // Unselect the community and all its children
updatedSelectedCommunities.remove(event.communityId); updatedSelectedCommunities.remove(event.communityId);
updatedSelectedSpaces.removeWhere(childrenIds.contains); updatedSelectedSpaces.removeWhere(childrenIds.contains);
updatedSoldChecks.removeWhere(childrenIds.contains); updatedSoldChecks.removeWhere(childrenIds.contains);
selectedSpacesInCommunity.removeWhere(childrenIds.contains);
} }
communityAndSpaces[event.communityId] = updatedSelectedSpaces; communityAndSpaces[event.communityId] = selectedSpacesInCommunity;
emit(state.copyWith( emit(state.copyWith(
selectedCommunities: updatedSelectedCommunities, selectedCommunities: updatedSelectedCommunities,
@ -125,6 +128,8 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList()); List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
Map<String, List<String>> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces); Map<String, List<String>> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces);
List<String> selectedSpacesInCommunity = communityAndSpaces[event.communityModel.uuid] ?? [];
List<String> childrenIds = _getAllChildIds(event.children); List<String> childrenIds = _getAllChildIds(event.children);
bool isChildSelected = false; bool isChildSelected = false;
@ -139,8 +144,11 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
// First click: Select the space and all its children // First click: Select the space and all its children
updatedSelectedSpaces.add(event.spaceId); updatedSelectedSpaces.add(event.spaceId);
updatedSelectedCommunities.add(event.communityModel.uuid); updatedSelectedCommunities.add(event.communityModel.uuid);
selectedSpacesInCommunity.add(event.spaceId);
if (childrenIds.isNotEmpty) { if (childrenIds.isNotEmpty) {
updatedSelectedSpaces.addAll(childrenIds); updatedSelectedSpaces.addAll(childrenIds);
selectedSpacesInCommunity.addAll(childrenIds);
} }
List<String> spaces = _getThePathToChild(event.communityModel.uuid, event.spaceId); List<String> spaces = _getThePathToChild(event.communityModel.uuid, event.spaceId);
@ -153,14 +161,17 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
childrenIds.isNotEmpty && childrenIds.isNotEmpty &&
isChildSelected) { isChildSelected) {
// Second click: Unselect space but keep children // Second click: Unselect space but keep children
selectedSpacesInCommunity.remove(event.spaceId);
updatedSelectedSpaces.remove(event.spaceId); updatedSelectedSpaces.remove(event.spaceId);
updatedSoldChecks.add(event.spaceId); updatedSoldChecks.add(event.spaceId);
} else { } else {
// Third click: Unselect space and all its children // Third click: Unselect space and all its children
selectedSpacesInCommunity.remove(event.spaceId);
updatedSelectedSpaces.remove(event.spaceId); updatedSelectedSpaces.remove(event.spaceId);
if (childrenIds.isNotEmpty) { if (childrenIds.isNotEmpty) {
updatedSelectedSpaces.removeWhere(childrenIds.contains); updatedSelectedSpaces.removeWhere(childrenIds.contains);
updatedSoldChecks.removeWhere(childrenIds.contains); updatedSoldChecks.removeWhere(childrenIds.contains);
selectedSpacesInCommunity.removeWhere(childrenIds.contains);
} }
updatedSoldChecks.remove(event.spaceId); updatedSoldChecks.remove(event.spaceId);
@ -185,7 +196,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
} }
} }
communityAndSpaces[event.communityModel.uuid] = updatedSelectedSpaces; communityAndSpaces[event.communityModel.uuid] = selectedSpacesInCommunity;
emit(state.copyWith( emit(state.copyWith(
selectedCommunities: updatedSelectedCommunities.toSet().toList(), selectedCommunities: updatedSelectedCommunities.toSet().toList(),