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