Skip to content

Commit

Permalink
HLM-3560::Black Screen fixes on App launch (#211)
Browse files Browse the repository at this point in the history
* HLM-3560::Black Screen fixes on App launch

* HLM-3560::Black Screen and Offline data fetch on App launch

* HLM-3560:: added Code commenting for Blank screen fixes

* Blank screen localizations changed to English
  • Loading branch information
Ramkrishna-egov authored Sep 28, 2023
1 parent 30ef4bf commit add74d4
Show file tree
Hide file tree
Showing 5 changed files with 293 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import '../../models/data_model.dart';
import '../../utils/environment_config.dart';
import '../../widgets/network_manager_provider_wrapper.dart';

/* part 'file_name.freezed.dart'
need to be added to auto generate the files for freezed model */
part 'app_initialization.freezed.dart';

typedef AppInitializationEmitter = Emitter<AppInitializationState>;
Expand Down Expand Up @@ -43,7 +41,8 @@ class AppInitializationBloc
if (event.retriesLeft == 0) {
throw const AppInitializationException('Unable to fetch MDMS Config');
}
final config = await _loadOfflineData();

final config = await _loadOfflineData(emit);
emit(AppInitialized(
appConfiguration: config.appConfigs.first,
serviceRegistryList: config.serviceRegistryList,
Expand All @@ -52,81 +51,88 @@ class AppInitializationBloc
emit(const AppUninitialized());
rethrow;
} catch (error) {
final result = await mdmsRepository.searchServiceRegistry(
envConfig.variables.mdmsApiPath,
MdmsRequestModel(
mdmsCriteria: MdmsCriteriaModel(
tenantId: envConfig.variables.tenantId,
moduleDetails: [
const MdmsModuleDetailModel(
moduleName: 'HCM-SERVICE-REGISTRY',
masterDetails: [
MdmsMasterDetailModel('serviceRegistry'),
],
),
],
),
).toJson(),
);
await mdmsRepository.writeToRegistryDB(result, isar);

final configResult = await mdmsRepository.searchAppConfig(
envConfig.variables.mdmsApiPath,
MdmsRequestModel(
mdmsCriteria: MdmsCriteriaModel(
tenantId: envConfig.variables.tenantId,
moduleDetails: [
const MdmsModuleDetailModel(
moduleName: 'HCM-FIELD-APP-CONFIG',
masterDetails: [
MdmsMasterDetailModel('appConfig'),
],
),
const MdmsModuleDetailModel(
moduleName: 'module-version',
masterDetails: [
MdmsMasterDetailModel('ROW_VERSIONS'),
],
),
],
),
).toJson(),
);

final pgrServiceDefinitions =
await mdmsRepository.searchPGRServiceDefinitions(
envConfig.variables.mdmsApiPath,
MdmsRequestModel(
mdmsCriteria: MdmsCriteriaModel(
tenantId: envConfig.variables.tenantId,
moduleDetails: [
const MdmsModuleDetailModel(
moduleName: 'RAINMAKER-PGR',
masterDetails: [
MdmsMasterDetailModel('ServiceDefs'),
],
),
],
try {
final result = await mdmsRepository.searchServiceRegistry(
envConfig.variables.mdmsApiPath,
MdmsRequestModel(
mdmsCriteria: MdmsCriteriaModel(
tenantId: envConfig.variables.tenantId,
moduleDetails: [
const MdmsModuleDetailModel(
moduleName: 'HCM-SERVICE-REGISTRY',
masterDetails: [
MdmsMasterDetailModel('serviceRegistry'),
],
),
],
),
).toJson(),
);
await mdmsRepository.writeToRegistryDB(result, isar);

final configResult = await mdmsRepository.searchAppConfig(
envConfig.variables.mdmsApiPath,
MdmsRequestModel(
mdmsCriteria: MdmsCriteriaModel(
tenantId: envConfig.variables.tenantId,
moduleDetails: [
const MdmsModuleDetailModel(
moduleName: 'HCM-FIELD-APP-CONFIG',
masterDetails: [
MdmsMasterDetailModel('appConfig'),
],
),
const MdmsModuleDetailModel(
moduleName: 'module-version',
masterDetails: [
MdmsMasterDetailModel('ROW_VERSIONS'),
],
),
],
),
).toJson(),
);

final pgrServiceDefinitions =
await mdmsRepository.searchPGRServiceDefinitions(
envConfig.variables.mdmsApiPath,
MdmsRequestModel(
mdmsCriteria: MdmsCriteriaModel(
tenantId: envConfig.variables.tenantId,
moduleDetails: [
const MdmsModuleDetailModel(
moduleName: 'RAINMAKER-PGR',
masterDetails: [
MdmsMasterDetailModel('ServiceDefs'),
],
),
],
),
).toJson(),
);

await mdmsRepository.writeToAppConfigDB(
configResult,
pgrServiceDefinitions,
isar,
);

add(
AppInitializationSetupEvent(
retriesLeft: event.retriesLeft - 1,
),
).toJson(),
);

await mdmsRepository.writeToAppConfigDB(
configResult,
pgrServiceDefinitions,
isar,
);

add(
AppInitializationSetupEvent(
retriesLeft: event.retriesLeft - 1,
),
);
emit(const AppUninitialized());
);
emit(const AppUninitialized());
} catch (e) {
/*Checks for if app initialization failed due to no internet or no retries left */
emit(const AppInitializationState.failed());
}
}
}

Future<MdmsConfig> _loadOfflineData() async {
Future<MdmsConfig> _loadOfflineData(
Emitter<AppInitializationState> emit,
) async {
final serviceRegistryList = await isar.serviceRegistrys.where().findAll();
final configs = await isar.appConfigurations.where().findAll();

Expand Down Expand Up @@ -158,6 +164,7 @@ class AppInitializationState with _$AppInitializationState {
const factory AppInitializationState.uninitialized() = AppUninitialized;

const factory AppInitializationState.loading() = AppInitializing;
const factory AppInitializationState.failed() = AppInitializationFailed;

const factory AppInitializationState.initialized({
required AppConfiguration appConfiguration,
Expand All @@ -168,6 +175,7 @@ class AppInitializationState with _$AppInitializationState {
return when(
uninitialized: () => {},
loading: () => {},
failed: () => {},
initialized: (appConfiguration, serviceRegistryList) =>
serviceRegistryList
.map((e) => e.actions.map((e) {
Expand Down Expand Up @@ -213,6 +221,7 @@ class AppInitializationState with _$AppInitializationState {
return when<String>(
uninitialized: () => 'Uninitialized',
loading: () => 'Loading',
failed: () => 'Failed',
initialized: (appConfiguration, serviceRegistryList) =>
'tenantId: ${appConfiguration.tenantId}\n'
'serviceCount: ${serviceRegistryList.length}',
Expand Down
Loading

0 comments on commit add74d4

Please sign in to comment.