mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
moved pagination to bloc
This commit is contained in:
@ -6,7 +6,6 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model
|
|||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_state.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_state.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/create_space_template_body_model.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';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_body_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_body_model.dart';
|
||||||
import 'package:syncrow_web/services/product_api.dart';
|
import 'package:syncrow_web/services/product_api.dart';
|
||||||
@ -77,6 +76,7 @@ class SpaceManagementBloc
|
|||||||
Future<List<SpaceTemplateModel>> fetchSpaceModels(
|
Future<List<SpaceTemplateModel>> fetchSpaceModels(
|
||||||
SpaceManagementState previousState) async {
|
SpaceManagementState previousState) async {
|
||||||
try {
|
try {
|
||||||
|
List<SpaceTemplateModel> allSpaces = [];
|
||||||
List<SpaceTemplateModel> prevSpaceModels = [];
|
List<SpaceTemplateModel> prevSpaceModels = [];
|
||||||
|
|
||||||
if (previousState is SpaceManagementLoaded ||
|
if (previousState is SpaceManagementLoaded ||
|
||||||
@ -87,10 +87,22 @@ class SpaceManagementBloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (prevSpaceModels.isEmpty) {
|
if (prevSpaceModels.isEmpty) {
|
||||||
|
bool hasNext = true;
|
||||||
|
int page = 1;
|
||||||
|
|
||||||
|
while (hasNext) {
|
||||||
|
final spaces = await _spaceModelApi.listSpaceModels(page: page);
|
||||||
|
if (spaces.isNotEmpty) {
|
||||||
|
allSpaces.addAll(spaces);
|
||||||
|
page++;
|
||||||
|
} else {
|
||||||
|
hasNext = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
prevSpaceModels = await _spaceModelApi.listSpaceModels(page: 1);
|
prevSpaceModels = await _spaceModelApi.listSpaceModels(page: 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return prevSpaceModels;
|
return allSpaces;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
|||||||
class AssignTagModelsDialog extends StatelessWidget {
|
class AssignTagModelsDialog extends StatelessWidget {
|
||||||
final List<ProductModel>? products;
|
final List<ProductModel>? products;
|
||||||
final List<SubspaceTemplateModel>? subspaces;
|
final List<SubspaceTemplateModel>? subspaces;
|
||||||
final List<TagModel>? initialTags;
|
final List<TagModel> initialTags;
|
||||||
final ValueChanged<List<TagModel>>? onTagsAssigned;
|
final ValueChanged<List<TagModel>>? onTagsAssigned;
|
||||||
final List<SelectedProduct> addedProducts;
|
final List<SelectedProduct> addedProducts;
|
||||||
final List<String>? allTags;
|
final List<String>? allTags;
|
||||||
@ -28,7 +28,7 @@ class AssignTagModelsDialog extends StatelessWidget {
|
|||||||
required this.products,
|
required this.products,
|
||||||
required this.subspaces,
|
required this.subspaces,
|
||||||
required this.addedProducts,
|
required this.addedProducts,
|
||||||
this.initialTags,
|
required this.initialTags,
|
||||||
this.onTagsAssigned,
|
this.onTagsAssigned,
|
||||||
this.allTags,
|
this.allTags,
|
||||||
required this.spaceName,
|
required this.spaceName,
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/create_space_template_body_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/create_space_template_body_model.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';
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
@ -7,28 +6,18 @@ import 'package:syncrow_web/utils/constants/temp_const.dart';
|
|||||||
|
|
||||||
class SpaceModelManagementApi {
|
class SpaceModelManagementApi {
|
||||||
Future<List<SpaceTemplateModel>> listSpaceModels({int page = 1}) async {
|
Future<List<SpaceTemplateModel>> listSpaceModels({int page = 1}) async {
|
||||||
List<SpaceTemplateModel> spaceModels = [];
|
final response = await HTTPService().get(
|
||||||
bool hasNext = true;
|
|
||||||
while (hasNext) {
|
|
||||||
await HTTPService().get(
|
|
||||||
path: ApiEndpoints.listSpaceModels
|
path: ApiEndpoints.listSpaceModels
|
||||||
.replaceAll('{projectId}', TempConst.projectId),
|
.replaceAll('{projectId}', TempConst.projectId),
|
||||||
queryParameters: {'page': page},
|
queryParameters: {'page': page},
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
List<dynamic> jsonData = json['data'];
|
List<dynamic> jsonData = json['data'];
|
||||||
hasNext = json['hasNext'] ?? false;
|
return jsonData.map((jsonItem) {
|
||||||
int currentPage = json['page'] ?? 1;
|
|
||||||
List<SpaceTemplateModel> spaceModelList = jsonData.map((jsonItem) {
|
|
||||||
return SpaceTemplateModel.fromJson(jsonItem);
|
return SpaceTemplateModel.fromJson(jsonItem);
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
spaceModels.addAll(spaceModelList);
|
|
||||||
page = currentPage + 1;
|
|
||||||
return spaceModelList;
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
return response;
|
||||||
return spaceModels;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<SpaceTemplateModel?> createSpaceModel(
|
Future<SpaceTemplateModel?> createSpaceModel(
|
||||||
|
Reference in New Issue
Block a user