mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
cached space model
This commit is contained in:
@ -75,7 +75,8 @@ class SpaceManagementBloc
|
||||
}
|
||||
}
|
||||
|
||||
_cachedSpaceModels = allSpaceModels;
|
||||
_cachedSpaceModels = allSpaceModels;
|
||||
|
||||
return allSpaceModels;
|
||||
} catch (e) {
|
||||
return [];
|
||||
@ -123,7 +124,6 @@ class SpaceManagementBloc
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _onloadProducts() async {
|
||||
if (_cachedProducts == null) {
|
||||
final products = await _productApi.fetchProducts();
|
||||
@ -313,13 +313,10 @@ class SpaceManagementBloc
|
||||
final updatedCommunities = prevCommunities..add(newCommunity);
|
||||
|
||||
if (safeContext.mounted) {
|
||||
print("added");
|
||||
final spaceTreeBloc = safeContext.read<
|
||||
SpaceTreeBloc>(); // ✅ Read bloc only when context is mounted
|
||||
spaceTreeBloc.add(OnCommunityAdded(newCommunity));
|
||||
} else {
|
||||
print("not mounted");
|
||||
}
|
||||
}
|
||||
|
||||
emit(SpaceManagementLoaded(
|
||||
spaceModels: prevSpaceModels,
|
||||
|
@ -30,10 +30,6 @@ class SpaceManagementLoaded extends SpaceManagementState {
|
||||
this.spaceModels});
|
||||
}
|
||||
|
||||
class SpaceModelManagenetLoaded extends SpaceManagementState {
|
||||
SpaceModelManagenetLoaded();
|
||||
}
|
||||
|
||||
class BlankState extends SpaceManagementState {
|
||||
final List<CommunityModel> communities;
|
||||
final List<ProductModel> products;
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
|
||||
@ -57,6 +59,7 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
||||
shouldNavigateToSpaceModelPage: false,
|
||||
);
|
||||
} else if (state is SpaceManagementLoaded) {
|
||||
|
||||
return LoadedSpaceView(
|
||||
communities: state.communities,
|
||||
selectedCommunity: state.selectedCommunity,
|
||||
|
@ -40,6 +40,7 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_spaceModels = List.from(widget.spaceModels ?? []);
|
||||
}
|
||||
|
||||
@ -47,6 +48,7 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
||||
@override
|
||||
void didUpdateWidget(covariant LoadedSpaceView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
|
||||
if (widget.spaceModels != oldWidget.spaceModels) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
@ -76,29 +78,33 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
widget.shouldNavigateToSpaceModelPage
|
||||
? Row(
|
||||
children: [
|
||||
SizedBox(width: 300, child: SpaceTreeView(onSelect: () {})),
|
||||
Expanded(
|
||||
child: BlocProvider(
|
||||
create: (context) => SpaceModelBloc(
|
||||
api: SpaceModelManagementApi(),
|
||||
initialSpaceModels: _spaceModels,
|
||||
? _spaceModels.isNotEmpty
|
||||
? Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 300, child: SpaceTreeView(onSelect: () {})),
|
||||
Expanded(
|
||||
child: BlocProvider(
|
||||
create: (context) => SpaceModelBloc(
|
||||
api: SpaceModelManagementApi(),
|
||||
initialSpaceModels: _spaceModels,
|
||||
),
|
||||
child: SpaceModelPage(
|
||||
products: widget.products,
|
||||
onSpaceModelsUpdated: _onSpaceModelsUpdated,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: SpaceModelPage(
|
||||
products: widget.products,
|
||||
onSpaceModelsUpdated: _onSpaceModelsUpdated,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
)
|
||||
: const Center(child: CircularProgressIndicator())
|
||||
: Row(
|
||||
children: [
|
||||
SidebarWidget(
|
||||
communities: widget.communities,
|
||||
selectedSpaceUuid:
|
||||
widget.selectedSpace?.uuid ?? widget.selectedCommunity?.uuid ?? '',
|
||||
selectedSpaceUuid: widget.selectedSpace?.uuid ??
|
||||
widget.selectedCommunity?.uuid ??
|
||||
'',
|
||||
),
|
||||
CommunityStructureArea(
|
||||
selectedCommunity: widget.selectedCommunity,
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_event.dart';
|
||||
@ -12,6 +14,8 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
|
||||
required this.api,
|
||||
required List<SpaceTemplateModel> initialSpaceModels,
|
||||
}) : super(SpaceModelLoaded(spaceModels: initialSpaceModels)) {
|
||||
log('Initial Space Models in: ${initialSpaceModels.map((e) => e.toJson()).toList()}');
|
||||
|
||||
on<CreateSpaceModel>(_onCreateSpaceModel);
|
||||
on<UpdateSpaceModel>(_onUpdateSpaceModel);
|
||||
on<DeleteSpaceModel>(_onDeleteSpaceModel);
|
||||
|
Reference in New Issue
Block a user