added tags

This commit is contained in:
hannathkadher
2025-03-05 17:12:02 +04:00
parent a7995bb2b8
commit c9427b35be
4 changed files with 108 additions and 113 deletions

View File

@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:syncrow_web/firebase_options_dev.dart';
import 'package:syncrow_web/firebase_options_prod.dart'; import 'package:syncrow_web/firebase_options_prod.dart';
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart'; import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart'; import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';

View File

@ -1,5 +1,4 @@
import 'dart:async'; import 'dart:async';
import 'dart:developer';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/common/bloc/project_manager.dart'; import 'package:syncrow_web/pages/common/bloc/project_manager.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';
@ -20,8 +19,7 @@ import 'package:syncrow_web/services/space_mana_api.dart';
import 'package:syncrow_web/services/space_model_mang_api.dart'; import 'package:syncrow_web/services/space_model_mang_api.dart';
import 'package:syncrow_web/utils/constants/action_enum.dart' as custom_action; import 'package:syncrow_web/utils/constants/action_enum.dart' as custom_action;
class SpaceManagementBloc class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementState> {
extends Bloc<SpaceManagementEvent, SpaceManagementState> {
final CommunitySpaceManagementApi _api; final CommunitySpaceManagementApi _api;
final ProductApi _productApi; final ProductApi _productApi;
final SpaceModelManagementApi _spaceModelApi; final SpaceModelManagementApi _spaceModelApi;
@ -29,6 +27,7 @@ class SpaceManagementBloc
List<ProductModel>? _cachedProducts; List<ProductModel>? _cachedProducts;
List<SpaceTemplateModel>? _cachedSpaceModels; List<SpaceTemplateModel>? _cachedSpaceModels;
final SpaceTreeBloc _spaceTreeBloc; final SpaceTreeBloc _spaceTreeBloc;
List<Tag>? _cachedTags;
SpaceManagementBloc( SpaceManagementBloc(
this._api, this._api,
@ -55,44 +54,38 @@ class SpaceManagementBloc
UpdateSpaceModelCache event, Emitter<SpaceManagementState> emit) async { UpdateSpaceModelCache event, Emitter<SpaceManagementState> emit) async {
if (_cachedSpaceModels != null) { if (_cachedSpaceModels != null) {
_cachedSpaceModels = _cachedSpaceModels!.map((model) { _cachedSpaceModels = _cachedSpaceModels!.map((model) {
return model.uuid == event.updatedModel.uuid return model.uuid == event.updatedModel.uuid ? event.updatedModel : model;
? event.updatedModel
: model;
}).toList(); }).toList();
} else { } else {
_cachedSpaceModels = await fetchSpaceModels(); _cachedSpaceModels = await fetchSpaceModels();
} }
await fetchSpaceModels();
emit(SpaceModelLoaded( emit(SpaceModelLoaded(
communities: state is SpaceManagementLoaded communities:
? (state as SpaceManagementLoaded).communities state is SpaceManagementLoaded ? (state as SpaceManagementLoaded).communities : [],
: [],
products: _cachedProducts ?? [], products: _cachedProducts ?? [],
spaceModels: List.from(_cachedSpaceModels ?? []), spaceModels: List.from(_cachedSpaceModels ?? []),
)); allTags: _cachedTags ?? []));
} }
void _deleteSpaceModelFromCache(DeleteSpaceModelFromCache event, void _deleteSpaceModelFromCache(
Emitter<SpaceManagementState> emit) async { DeleteSpaceModelFromCache event, Emitter<SpaceManagementState> emit) async {
if (_cachedSpaceModels != null) { if (_cachedSpaceModels != null) {
_cachedSpaceModels = _cachedSpaceModels! _cachedSpaceModels =
.where((model) => model.uuid != event.deletedUuid) _cachedSpaceModels!.where((model) => model.uuid != event.deletedUuid).toList();
.toList();
} else { } else {
_cachedSpaceModels = await fetchSpaceModels(); _cachedSpaceModels = await fetchSpaceModels();
} }
await fetchSpaceModels();
emit(SpaceModelLoaded( emit(SpaceModelLoaded(
communities: state is SpaceManagementLoaded communities:
? (state as SpaceManagementLoaded).communities state is SpaceManagementLoaded ? (state as SpaceManagementLoaded).communities : [],
: [],
products: _cachedProducts ?? [], products: _cachedProducts ?? [],
spaceModels: List.from(_cachedSpaceModels ?? []), spaceModels: List.from(_cachedSpaceModels ?? []),
)); allTags: _cachedTags ?? []));
}
void _logEvent(String eventName) {
log('Event Triggered: $eventName');
} }
void updateCachedSpaceModels(List<SpaceTemplateModel> updatedModels) { void updateCachedSpaceModels(List<SpaceTemplateModel> updatedModels) {
@ -117,8 +110,8 @@ class SpaceManagementBloc
int page = 1; int page = 1;
while (hasNext) { while (hasNext) {
final spaceModels = await _spaceModelApi.listSpaceModels( final spaceModels =
page: page, projectId: projectUuid); await _spaceModelApi.listSpaceModels(page: page, projectId: projectUuid);
if (spaceModels.isNotEmpty) { if (spaceModels.isNotEmpty) {
allSpaceModels.addAll(spaceModels); allSpaceModels.addAll(spaceModels);
page++; page++;
@ -135,6 +128,20 @@ class SpaceManagementBloc
} }
} }
Future<List<Tag>> fetchTags() async {
try {
if (_cachedTags != null) {
return _cachedTags!;
}
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
final allTags = await _spaceModelApi.listTags(projectId: projectUuid);
_cachedTags = allTags;
return allTags;
} catch (e) {
return [];
}
}
void _onUpdateCommunity( void _onUpdateCommunity(
UpdateCommunityEvent event, UpdateCommunityEvent event,
Emitter<SpaceManagementState> emit, Emitter<SpaceManagementState> emit,
@ -142,14 +149,13 @@ class SpaceManagementBloc
final previousState = state; final previousState = state;
try { try {
final projectUuid = await ProjectManager.getProjectUUID() ?? ''; final projectUuid = await ProjectManager.getProjectUUID() ?? '';
await fetchTags();
emit(SpaceManagementLoading()); emit(SpaceManagementLoading());
final success = await _api.updateCommunity( final success = await _api.updateCommunity(event.communityUuid, event.name, projectUuid);
event.communityUuid, event.name, projectUuid);
if (success) { if (success) {
if (previousState is SpaceManagementLoaded) { if (previousState is SpaceManagementLoaded) {
final updatedCommunities = final updatedCommunities = List<CommunityModel>.from(previousState.communities);
List<CommunityModel>.from(previousState.communities);
for (var community in updatedCommunities) { for (var community in updatedCommunities) {
if (community.uuid == event.communityUuid) { if (community.uuid == event.communityUuid) {
community.name = event.name; community.name = event.name;
@ -166,7 +172,7 @@ class SpaceManagementBloc
products: previousState.products, products: previousState.products,
selectedCommunity: previousState.selectedCommunity, selectedCommunity: previousState.selectedCommunity,
spaceModels: prevSpaceModels, spaceModels: prevSpaceModels,
)); allTags: _cachedTags ?? []));
} }
} else { } else {
emit(const SpaceManagementError('Failed to update the community.')); emit(const SpaceManagementError('Failed to update the community.'));
@ -194,8 +200,7 @@ class SpaceManagementBloc
} }
} }
Future<List<SpaceModel>> _fetchSpacesForCommunity( Future<List<SpaceModel>> _fetchSpacesForCommunity(String communityUuid) async {
String communityUuid) async {
final projectUuid = await ProjectManager.getProjectUUID() ?? ''; final projectUuid = await ProjectManager.getProjectUUID() ?? '';
return await _api.getSpaceHierarchy(communityUuid, projectUuid); return await _api.getSpaceHierarchy(communityUuid, projectUuid);
@ -206,7 +211,7 @@ class SpaceManagementBloc
Emitter<SpaceManagementState> emit, Emitter<SpaceManagementState> emit,
) async { ) async {
try { try {
final previousState = state; await fetchTags();
if (event.communities.isEmpty) { if (event.communities.isEmpty) {
emit(const SpaceManagementError('No communities provided.')); emit(const SpaceManagementError('No communities provided.'));
@ -219,30 +224,30 @@ class SpaceManagementBloc
communities: event.communities, communities: event.communities,
products: _cachedProducts ?? [], products: _cachedProducts ?? [],
spaceModels: prevSpaceModels, spaceModels: prevSpaceModels,
)); allTags: _cachedTags ?? []));
} catch (error) { } catch (error) {
emit(SpaceManagementError('Error loading communities: $error')); emit(SpaceManagementError('Error loading communities: $error'));
} }
} }
Future<void> _onBlankState( Future<void> _onBlankState(BlankStateEvent event, Emitter<SpaceManagementState> emit) async {
BlankStateEvent event, Emitter<SpaceManagementState> emit) async {
try { try {
final previousState = state; final previousState = state;
final projectUuid = await ProjectManager.getProjectUUID() ?? ''; final projectUuid = await ProjectManager.getProjectUUID() ?? '';
var spaceBloc = event.context.read<SpaceTreeBloc>(); var spaceBloc = event.context.read<SpaceTreeBloc>();
List<CommunityModel> communities = await _waitForCommunityList(spaceBloc); List<CommunityModel> communities = await _waitForCommunityList(spaceBloc);
await fetchSpaceModels();
await fetchTags();
var prevSpaceModels = await fetchSpaceModels(); var prevSpaceModels = await fetchSpaceModels();
if (previousState is SpaceManagementLoaded || if (previousState is SpaceManagementLoaded || previousState is BlankState) {
previousState is BlankState) {
final prevCommunities = (previousState as dynamic).communities ?? []; final prevCommunities = (previousState as dynamic).communities ?? [];
emit(BlankState( emit(BlankState(
communities: List<CommunityModel>.from(prevCommunities), communities: List<CommunityModel>.from(prevCommunities),
products: _cachedProducts ?? [], products: _cachedProducts ?? [],
spaceModels: prevSpaceModels, spaceModels: prevSpaceModels,
)); allTags: _cachedTags));
return; return;
} }
@ -251,8 +256,7 @@ class SpaceManagementBloc
List<CommunityModel> updatedCommunities = await Future.wait( List<CommunityModel> updatedCommunities = await Future.wait(
communities.map((community) async { communities.map((community) async {
List<SpaceModel> spaces = List<SpaceModel> spaces = await _fetchSpacesForCommunity(community.uuid);
await _fetchSpacesForCommunity(community.uuid);
return CommunityModel( return CommunityModel(
uuid: community.uuid, uuid: community.uuid,
createdAt: community.createdAt, createdAt: community.createdAt,
@ -272,6 +276,7 @@ class SpaceManagementBloc
spaceModels: prevSpaceModels, spaceModels: prevSpaceModels,
communities: communities, communities: communities,
products: _cachedProducts ?? [], products: _cachedProducts ?? [],
allTags: _cachedTags ?? [],
)); ));
} catch (error) { } catch (error) {
emit(SpaceManagementError('Error loading communities: $error')); emit(SpaceManagementError('Error loading communities: $error'));
@ -282,11 +287,9 @@ class SpaceManagementBloc
LoadCommunityAndSpacesEvent event, LoadCommunityAndSpacesEvent event,
Emitter<SpaceManagementState> emit, Emitter<SpaceManagementState> emit,
) async { ) async {
_logEvent('LoadCommunityAndSpacesEvent');
var spaceBloc = event.context.read<SpaceTreeBloc>(); var spaceBloc = event.context.read<SpaceTreeBloc>();
_onloadProducts(); _onloadProducts();
await fetchTags();
// Wait until `communityList` is loaded // Wait until `communityList` is loaded
List<CommunityModel> communities = await _waitForCommunityList(spaceBloc); List<CommunityModel> communities = await _waitForCommunityList(spaceBloc);
@ -296,11 +299,11 @@ class SpaceManagementBloc
communities: communities, communities: communities,
products: _cachedProducts ?? [], products: _cachedProducts ?? [],
spaceModels: prevSpaceModels, spaceModels: prevSpaceModels,
allTags: _cachedTags ?? []
)); ));
} }
Future<List<CommunityModel>> _waitForCommunityList( Future<List<CommunityModel>> _waitForCommunityList(SpaceTreeBloc spaceBloc) async {
SpaceTreeBloc spaceBloc) async {
// Check if communityList is already populated // Check if communityList is already populated
if (spaceBloc.state.communityList.isNotEmpty) { if (spaceBloc.state.communityList.isNotEmpty) {
return spaceBloc.state.communityList; return spaceBloc.state.communityList;
@ -327,8 +330,7 @@ class SpaceManagementBloc
emit(SpaceManagementLoading()); emit(SpaceManagementLoading());
final projectUuid = await ProjectManager.getProjectUUID() ?? ''; final projectUuid = await ProjectManager.getProjectUUID() ?? '';
final success = final success = await _api.deleteCommunity(event.communityUuid, projectUuid);
await _api.deleteCommunity(event.communityUuid, projectUuid);
if (success) { if (success) {
// add(LoadCommunityAndSpacesEvent()); // add(LoadCommunityAndSpacesEvent());
} else { } else {
@ -349,14 +351,13 @@ class SpaceManagementBloc
try { try {
final projectUuid = await ProjectManager.getProjectUUID() ?? ''; final projectUuid = await ProjectManager.getProjectUUID() ?? '';
await fetchTags();
CommunityModel? newCommunity = await _api.createCommunity( CommunityModel? newCommunity =
event.name, event.description, projectUuid); await _api.createCommunity(event.name, event.description, projectUuid);
var prevSpaceModels = await fetchSpaceModels(); var prevSpaceModels = await fetchSpaceModels();
if (newCommunity != null) { if (newCommunity != null) {
if (previousState is SpaceManagementLoaded || if (previousState is SpaceManagementLoaded || previousState is BlankState) {
previousState is BlankState) {
final prevCommunities = List<CommunityModel>.from( final prevCommunities = List<CommunityModel>.from(
(previousState as dynamic).communities, (previousState as dynamic).communities,
); );
@ -368,7 +369,9 @@ class SpaceManagementBloc
communities: updatedCommunities, communities: updatedCommunities,
products: _cachedProducts ?? [], products: _cachedProducts ?? [],
selectedCommunity: newCommunity, selectedCommunity: newCommunity,
selectedSpace: null)); selectedSpace: null,
allTags: _cachedTags ?? [],
));
} }
} else { } else {
emit(const SpaceManagementError('Error creating community')); emit(const SpaceManagementError('Error creating community'));
@ -408,11 +411,12 @@ class SpaceManagementBloc
required Emitter<SpaceManagementState> emit, required Emitter<SpaceManagementState> emit,
CommunityModel? selectedCommunity, CommunityModel? selectedCommunity,
SpaceModel? selectedSpace, SpaceModel? selectedSpace,
}) { }) async {
final previousState = state; final previousState = state;
emit(SpaceManagementLoading()); emit(SpaceManagementLoading());
try { try {
await fetchTags();
if (previousState is SpaceManagementLoaded || if (previousState is SpaceManagementLoaded ||
previousState is BlankState || previousState is BlankState ||
previousState is SpaceModelLoaded) { previousState is SpaceModelLoaded) {
@ -428,7 +432,8 @@ class SpaceManagementBloc
products: _cachedProducts ?? [], products: _cachedProducts ?? [],
selectedCommunity: selectedCommunity, selectedCommunity: selectedCommunity,
selectedSpace: selectedSpace, selectedSpace: selectedSpace,
spaceModels: spaceModels)); spaceModels: spaceModels,
allTags: _cachedTags ?? []));
} }
} catch (e) { } catch (e) {
emit(SpaceManagementError('Error updating state: $e')); emit(SpaceManagementError('Error updating state: $e'));
@ -443,8 +448,7 @@ class SpaceManagementBloc
emit(SpaceManagementLoading()); emit(SpaceManagementLoading());
try { try {
final updatedSpaces = final updatedSpaces = await saveSpacesHierarchically(event.spaces, event.communityUuid);
await saveSpacesHierarchically(event.spaces, event.communityUuid);
final allSpaces = await _fetchSpacesForCommunity(event.communityUuid); final allSpaces = await _fetchSpacesForCommunity(event.communityUuid);
@ -474,7 +478,7 @@ class SpaceManagementBloc
Emitter<SpaceManagementState> emit, Emitter<SpaceManagementState> emit,
) async { ) async {
var prevSpaceModels = await fetchSpaceModels(); var prevSpaceModels = await fetchSpaceModels();
await fetchTags();
final communities = List<CommunityModel>.from(previousState.communities); final communities = List<CommunityModel>.from(previousState.communities);
for (var community in communities) { for (var community in communities) {
@ -487,7 +491,8 @@ class SpaceManagementBloc
products: _cachedProducts ?? [], products: _cachedProducts ?? [],
selectedCommunity: community, selectedCommunity: community,
selectedSpace: null, selectedSpace: null,
spaceModels: prevSpaceModels)); spaceModels: prevSpaceModels,
allTags: _cachedTags ??[]));
return; return;
} }
} }
@ -518,8 +523,7 @@ class SpaceManagementBloc
if (space.uuid != null && space.uuid!.isNotEmpty) { if (space.uuid != null && space.uuid!.isNotEmpty) {
List<TagModelUpdate> tagUpdates = []; List<TagModelUpdate> tagUpdates = [];
final prevSpace = final prevSpace = await _api.getSpace(communityUuid, space.uuid!, projectUuid);
await _api.getSpace(communityUuid, space.uuid!, projectUuid);
final List<UpdateSubspaceTemplateModel> subspaceUpdates = []; final List<UpdateSubspaceTemplateModel> subspaceUpdates = [];
final List<SubspaceModel>? prevSubspaces = prevSpace?.subspaces; final List<SubspaceModel>? prevSubspaces = prevSpace?.subspaces;
final List<SubspaceModel>? newSubspaces = space.subspaces; final List<SubspaceModel>? newSubspaces = space.subspaces;
@ -529,19 +533,17 @@ class SpaceManagementBloc
if (prevSubspaces != null || newSubspaces != null) { if (prevSubspaces != null || newSubspaces != null) {
if (prevSubspaces != null && newSubspaces != null) { if (prevSubspaces != null && newSubspaces != null) {
for (var prevSubspace in prevSubspaces) { for (var prevSubspace in prevSubspaces) {
final existsInNew = newSubspaces final existsInNew =
.any((subspace) => subspace.uuid == prevSubspace.uuid); newSubspaces.any((subspace) => subspace.uuid == prevSubspace.uuid);
if (!existsInNew) { if (!existsInNew) {
subspaceUpdates.add(UpdateSubspaceTemplateModel( subspaceUpdates.add(UpdateSubspaceTemplateModel(
action: custom_action.Action.delete, action: custom_action.Action.delete, uuid: prevSubspace.uuid));
uuid: prevSubspace.uuid));
} }
} }
} else if (prevSubspaces != null && newSubspaces == null) { } else if (prevSubspaces != null && newSubspaces == null) {
for (var prevSubspace in prevSubspaces) { for (var prevSubspace in prevSubspaces) {
subspaceUpdates.add(UpdateSubspaceTemplateModel( subspaceUpdates.add(UpdateSubspaceTemplateModel(
action: custom_action.Action.delete, action: custom_action.Action.delete, uuid: prevSubspace.uuid));
uuid: prevSubspace.uuid));
} }
} }
@ -569,9 +571,7 @@ class SpaceManagementBloc
} }
if (prevSubspaces != null && newSubspaces != null) { if (prevSubspaces != null && newSubspaces != null) {
final newSubspaceMap = { final newSubspaceMap = {for (var subspace in newSubspaces) subspace.uuid: subspace};
for (var subspace in newSubspaces) subspace.uuid: subspace
};
for (var prevSubspace in prevSubspaces) { for (var prevSubspace in prevSubspaces) {
final newSubspace = newSubspaceMap[prevSubspace.uuid]; final newSubspace = newSubspaceMap[prevSubspace.uuid];
@ -608,10 +608,8 @@ class SpaceManagementBloc
: []; : [];
final createSubspaceBodyModels = space.subspaces?.map((subspace) { final createSubspaceBodyModels = space.subspaces?.map((subspace) {
final tagBodyModels = subspace.tags final tagBodyModels =
?.map((tag) => tag.toCreateTagBodyModel()) subspace.tags?.map((tag) => tag.toCreateTagBodyModel()).toList() ?? [];
.toList() ??
[];
return CreateSubspaceModel() return CreateSubspaceModel()
..subspaceName = subspace.subspaceName ..subspaceName = subspace.subspaceName
..tags = tagBodyModels; ..tags = tagBodyModels;
@ -664,12 +662,11 @@ class SpaceManagementBloc
return result.toList(); // Convert back to a list return result.toList(); // Convert back to a list
} }
void _onLoadSpaceModel( void _onLoadSpaceModel(SpaceModelLoadEvent event, Emitter<SpaceManagementState> emit) async {
SpaceModelLoadEvent event, Emitter<SpaceManagementState> emit) async {
emit(SpaceManagementLoading()); emit(SpaceManagementLoading());
try { try {
var prevState = state; await fetchTags();
final projectUuid = await ProjectManager.getProjectUUID() ?? ''; final projectUuid = await ProjectManager.getProjectUUID() ?? '';
var spaceBloc = event.context.read<SpaceTreeBloc>(); var spaceBloc = event.context.read<SpaceTreeBloc>();
List<CommunityModel> communities = spaceBloc.state.communityList; List<CommunityModel> communities = spaceBloc.state.communityList;
@ -681,8 +678,7 @@ class SpaceManagementBloc
List<CommunityModel> updatedCommunities = await Future.wait( List<CommunityModel> updatedCommunities = await Future.wait(
communities.map((community) async { communities.map((community) async {
List<SpaceModel> spaces = List<SpaceModel> spaces = await _fetchSpacesForCommunity(community.uuid);
await _fetchSpacesForCommunity(community.uuid);
return CommunityModel( return CommunityModel(
uuid: community.uuid, uuid: community.uuid,
createdAt: community.createdAt, createdAt: community.createdAt,
@ -702,6 +698,7 @@ class SpaceManagementBloc
communities: communities, communities: communities,
products: _cachedProducts ?? [], products: _cachedProducts ?? [],
spaceModels: prevSpaceModels, spaceModels: prevSpaceModels,
allTags: _cachedTags ?? []
)); ));
} catch (e) { } catch (e) {
emit(SpaceManagementError('Error loading communities and spaces: $e')); emit(SpaceManagementError('Error loading communities and spaces: $e'));
@ -731,17 +728,14 @@ class SpaceManagementBloc
// Case 1: Tags deleted // Case 1: Tags deleted
if (prevTags != null && newTags != null) { if (prevTags != null && newTags != null) {
for (var prevTag in prevTags) { for (var prevTag in prevTags) {
final existsInNew = final existsInNew = newTags.any((newTag) => newTag.uuid == prevTag.uuid);
newTags.any((newTag) => newTag.uuid == prevTag.uuid);
if (!existsInNew) { if (!existsInNew) {
tagUpdates.add(TagModelUpdate( tagUpdates.add(TagModelUpdate(action: custom_action.Action.delete, uuid: prevTag.uuid));
action: custom_action.Action.delete, uuid: prevTag.uuid));
} }
} }
} else if (prevTags != null && newTags == null) { } else if (prevTags != null && newTags == null) {
for (var prevTag in prevTags) { for (var prevTag in prevTags) {
tagUpdates.add(TagModelUpdate( tagUpdates.add(TagModelUpdate(action: custom_action.Action.delete, uuid: prevTag.uuid));
action: custom_action.Action.delete, uuid: prevTag.uuid));
} }
} }

View File

@ -2,6 +2,7 @@ import 'package:equatable/equatable.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';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
abstract class SpaceManagementState extends Equatable { abstract class SpaceManagementState extends Equatable {
@ -21,22 +22,25 @@ class SpaceManagementLoaded extends SpaceManagementState {
CommunityModel? selectedCommunity; CommunityModel? selectedCommunity;
SpaceModel? selectedSpace; SpaceModel? selectedSpace;
List<SpaceTemplateModel>? spaceModels; List<SpaceTemplateModel>? spaceModels;
List<Tag> allTags;
SpaceManagementLoaded( SpaceManagementLoaded(
{required this.communities, {required this.communities,
required this.products, required this.products,
this.selectedCommunity, this.selectedCommunity,
this.selectedSpace, this.selectedSpace,
this.spaceModels}); this.spaceModels,
required this.allTags});
} }
class BlankState extends SpaceManagementState { class BlankState extends SpaceManagementState {
final List<CommunityModel> communities; final List<CommunityModel> communities;
final List<ProductModel> products; final List<ProductModel> products;
List<SpaceTemplateModel>? spaceModels; List<SpaceTemplateModel>? spaceModels;
final List<Tag>? allTags;
BlankState( BlankState(
{required this.communities, required this.products, this.spaceModels}); {required this.communities, required this.products, this.spaceModels, required this.allTags});
} }
class SpaceCreationSuccess extends SpaceManagementState { class SpaceCreationSuccess extends SpaceManagementState {
@ -61,14 +65,14 @@ class SpaceModelLoaded extends SpaceManagementState {
List<SpaceTemplateModel> spaceModels; List<SpaceTemplateModel> spaceModels;
final List<ProductModel> products; final List<ProductModel> products;
final List<CommunityModel> communities; final List<CommunityModel> communities;
final List<Tag> allTags;
SpaceModelLoaded({ SpaceModelLoaded(
required this.communities, {required this.communities,
required this.products, required this.products,
required this.spaceModels, required this.spaceModels,
}); required this.allTags});
@override @override
List<Object> get props => [communities, products, spaceModels]; List<Object> get props => [communities, products, spaceModels, allTags];
} }

View File

@ -1,5 +1,3 @@
import 'dart:developer';
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/device_managment/shared/navigate_home_grid_view.dart'; import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
@ -62,9 +60,9 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
selectedSpace: null, selectedSpace: null,
products: state.products, products: state.products,
shouldNavigateToSpaceModelPage: false, shouldNavigateToSpaceModelPage: false,
); );
} else if (state is SpaceManagementLoaded) { } else if (state is SpaceManagementLoaded) {
return LoadedSpaceView( return LoadedSpaceView(
communities: state.communities, communities: state.communities,
selectedCommunity: state.selectedCommunity, selectedCommunity: state.selectedCommunity,