From cd077b467979f24a67e1c9b046a2c413dd2fba15 Mon Sep 17 00:00:00 2001 From: AhsanAli13503 Date: Thu, 16 May 2024 16:58:26 +0500 Subject: [PATCH] feat: draft list --- evently/i18n/de.json | 3 +- evently/i18n/en-US.json | 3 +- evently/i18n/es.json | 3 +- evently/i18n/ru-RU.json | 3 +- evently/lib/generated/locale_keys.g.dart | 1 + .../event_hub/event_hub_view_model.dart | 13 ++--- .../datasources/local_datasource.dart | 19 +++++-- evently/lib/utils/di/di.config.dart | 53 ++++++++++--------- 8 files changed, 59 insertions(+), 39 deletions(-) diff --git a/evently/i18n/de.json b/evently/i18n/de.json index 55697d6cdf..f97e482361 100644 --- a/evently/i18n/de.json +++ b/evently/i18n/de.json @@ -64,5 +64,6 @@ "something_wrong_while_uploading": "Beim Hochladen ist etwas schief gelaufen. Bitte versuche es erneut.", "cookbook_not_found": "Cookbook nicht gefunden", "loading": "Wird geladen ...", - "something_wrong": "Etwas ist schief gelaufen. Bitte versuchen Sie, die Anwendung neu zu starten." + "something_wrong": "Etwas ist schief gelaufen. Bitte versuchen Sie, die Anwendung neu zu starten.", + "get_error": "Entwurf konnte nicht abgerufen werden" } \ No newline at end of file diff --git a/evently/i18n/en-US.json b/evently/i18n/en-US.json index 1452511178..973207bd10 100644 --- a/evently/i18n/en-US.json +++ b/evently/i18n/en-US.json @@ -64,5 +64,6 @@ "something_wrong_while_uploading": "Something went wrong while uploading. Please try again.", "cookbook_not_found": "Cookbook not found", "loading": "loading ...", - "something_wrong": "Something went wrong. Please try restarting the application." + "something_wrong": "Something went wrong. Please try restarting the application.", + "get_error": "Failed to get draft" } \ No newline at end of file diff --git a/evently/i18n/es.json b/evently/i18n/es.json index 09c9039b18..0a9e319a8c 100644 --- a/evently/i18n/es.json +++ b/evently/i18n/es.json @@ -64,5 +64,6 @@ "something_wrong_while_uploading": "Algo salió mal durante la carga. Inténtalo de nuevo.", "cookbook_not_found": "Cookbook extraviado", "loading": "cargando ...", - "something_wrong": "Algo salió mal. Intenta reiniciar la aplicación." + "something_wrong": "Algo salió mal. Intenta reiniciar la aplicación.", + "get_error": "No se pudo obtener el Plan Preliminar" } \ No newline at end of file diff --git a/evently/i18n/ru-RU.json b/evently/i18n/ru-RU.json index dc5f3b742d..24d581e1bc 100644 --- a/evently/i18n/ru-RU.json +++ b/evently/i18n/ru-RU.json @@ -64,5 +64,6 @@ "something_wrong_while_uploading": "Что-то пошло не так во время загрузки. Пожалуйста, попробуйте еще раз.", "cookbook_not_found": "Cookbook не найден", "loading": "cargando ...", - "something_wrong": "Что-то пошло не так. Попробуйте перезапустить приложение." + "something_wrong": "Что-то пошло не так. Попробуйте перезапустить приложение.", + "get_error": "Не удалось получить черновик" } \ No newline at end of file diff --git a/evently/lib/generated/locale_keys.g.dart b/evently/lib/generated/locale_keys.g.dart index e405267b99..51700b00fe 100644 --- a/evently/lib/generated/locale_keys.g.dart +++ b/evently/lib/generated/locale_keys.g.dart @@ -65,5 +65,6 @@ abstract class LocaleKeys { static const cookbook_not_found = 'cookbook_not_found'; static const loading = 'loading'; static const something_wrong = 'something_wrong'; + static const get_error = 'get_error'; } diff --git a/evently/lib/screens/event_hub/event_hub_view_model.dart b/evently/lib/screens/event_hub/event_hub_view_model.dart index 627b48aa34..b35b17d1ee 100644 --- a/evently/lib/screens/event_hub/event_hub_view_model.dart +++ b/evently/lib/screens/event_hub/event_hub_view_model.dart @@ -20,12 +20,12 @@ class EventHubViewModel extends ChangeNotifier { List get eventPublishedList => _eventPublishedList; - List _eventForSaleList = []; + List _eventForDraftList = []; - List get eventForSaleList => _eventForSaleList; + List get eventForSaleList => _eventForDraftList; - set setEventForSaleList(List nftForSale) { - _eventForSaleList = nftForSale; + set setEventForDraftList(List nftForSale) { + _eventForDraftList = nftForSale; notifyListeners(); } @@ -36,7 +36,7 @@ class EventHubViewModel extends ChangeNotifier { void updatePublishedEventList({required Events events}) { _eventPublishedList.add(events); - _eventForSaleList.add(events); + _eventForDraftList.add(events); notifyListeners(); } @@ -105,7 +105,8 @@ class EventHubViewModel extends ChangeNotifier { return; } - // nftDraftList = getNftResponse.getOrElse(() => []); + List draftEvent = getEventResponse.getOrElse(() => []); + setEventForDraftList = draftEvent; loading.dismiss(); diff --git a/evently/lib/services/datasources/local_datasource.dart b/evently/lib/services/datasources/local_datasource.dart index 88dc782fae..0ba1334087 100644 --- a/evently/lib/services/datasources/local_datasource.dart +++ b/evently/lib/services/datasources/local_datasource.dart @@ -1,6 +1,10 @@ +import 'package:easy_localization/easy_localization.dart'; +import 'package:evently/generated/locale_keys.g.dart'; import 'package:evently/models/events.dart'; +import 'package:evently/services/third_party_services/database.dart'; import 'package:evently/utils/constants.dart'; import 'package:evently/utils/date_utils.dart'; +import 'package:evently/utils/failure/failure.dart'; import 'package:injectable/injectable.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -42,9 +46,13 @@ abstract class LocalDataSource { @LazySingleton(as: LocalDataSource) class LocalDataSourceImpl extends LocalDataSource { - LocalDataSourceImpl({required this.sharedPreferences}); + LocalDataSourceImpl({ + required this.sharedPreferences, + required this.database, + }); final SharedPreferences sharedPreferences; + final AppDatabase database; /// auto generates cookbookID string and saves into local storage /// returns cookbookId @@ -93,8 +101,11 @@ class LocalDataSourceImpl extends LocalDataSource { } @override - Future> getEvents() { - // TODO: implement getEvents - throw UnimplementedError(); + Future> getEvents() async { + try { + return await database.eventsDao.findAllEvents(); + } catch (e) { + throw CacheFailure(LocaleKeys.get_error.tr()); + } } } diff --git a/evently/lib/utils/di/di.config.dart b/evently/lib/utils/di/di.config.dart index d702697c9d..c987c79dd8 100644 --- a/evently/lib/utils/di/di.config.dart +++ b/evently/lib/utils/di/di.config.dart @@ -9,20 +9,21 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:dio/dio.dart' as _i6; -import 'package:evently/evently_provider.dart' as _i13; -import 'package:evently/repository/repository.dart' as _i12; -import 'package:evently/screens/event_hub/event_hub_view_model.dart' as _i14; -import 'package:evently/services/datasources/local_datasource.dart' as _i7; -import 'package:evently/services/datasources/remote_datasource.dart' as _i11; -import 'package:evently/services/third_party_services/quick_node.dart' as _i10; -import 'package:evently/utils/di/register_modules.dart' as _i15; -import 'package:evently/utils/file_utils_helper.dart' as _i9; +import 'package:evently/evently_provider.dart' as _i14; +import 'package:evently/repository/repository.dart' as _i13; +import 'package:evently/screens/event_hub/event_hub_view_model.dart' as _i15; +import 'package:evently/services/datasources/local_datasource.dart' as _i9; +import 'package:evently/services/datasources/remote_datasource.dart' as _i12; +import 'package:evently/services/third_party_services/database.dart' as _i11; +import 'package:evently/services/third_party_services/quick_node.dart' as _i8; +import 'package:evently/utils/di/register_modules.dart' as _i16; +import 'package:evently/utils/file_utils_helper.dart' as _i7; import 'package:evently/viewmodels/create_event_viewmodel.dart' as _i3; import 'package:file_picker/file_picker.dart' as _i5; import 'package:get_it/get_it.dart' as _i1; import 'package:image_cropper/image_cropper.dart' as _i4; import 'package:injectable/injectable.dart' as _i2; -import 'package:shared_preferences/shared_preferences.dart' as _i8; +import 'package:shared_preferences/shared_preferences.dart' as _i10; extension GetItInjectableX on _i1.GetIt { // initializes the registration of main-scope dependencies inside of GetIt @@ -41,27 +42,29 @@ extension GetItInjectableX on _i1.GetIt { gh.lazySingleton<_i4.ImageCropper>(() => registerModule.imageCropper); gh.lazySingleton<_i5.FilePicker>(() => registerModule.filePicker); gh.lazySingleton<_i6.Dio>(() => registerModule.dio); - gh.lazySingleton<_i7.LocalDataSource>(() => _i7.LocalDataSourceImpl( - sharedPreferences: gh<_i8.SharedPreferences>())); - gh.lazySingleton<_i9.FileUtilsHelper>(() => _i9.FileUtilsHelperImpl( + gh.lazySingleton<_i7.FileUtilsHelper>(() => _i7.FileUtilsHelperImpl( imageCropper: gh<_i4.ImageCropper>(), filePicker: gh<_i5.FilePicker>(), )); - gh.lazySingleton<_i10.QuickNode>( - () => _i10.QuickNodeImpl(httpClient: gh<_i6.Dio>())); - gh.lazySingleton<_i11.RemoteDataSource>( - () => _i11.RemoteDataSourceImpl(quickNode: gh<_i10.QuickNode>())); - gh.lazySingleton<_i12.Repository>(() => _i12.RepositoryImp( - fileUtilsHelper: gh<_i9.FileUtilsHelper>(), - localDataSource: gh<_i7.LocalDataSource>(), - remoteDataSource: gh<_i11.RemoteDataSource>(), + gh.lazySingleton<_i8.QuickNode>( + () => _i8.QuickNodeImpl(httpClient: gh<_i6.Dio>())); + gh.lazySingleton<_i9.LocalDataSource>(() => _i9.LocalDataSourceImpl( + sharedPreferences: gh<_i10.SharedPreferences>(), + database: gh<_i11.AppDatabase>(), )); - gh.lazySingleton<_i13.EventlyProvider>( - () => _i13.EventlyProvider(repository: gh<_i12.Repository>())); - gh.lazySingleton<_i14.EventHubViewModel>( - () => _i14.EventHubViewModel(gh<_i12.Repository>())); + gh.lazySingleton<_i12.RemoteDataSource>( + () => _i12.RemoteDataSourceImpl(quickNode: gh<_i8.QuickNode>())); + gh.lazySingleton<_i13.Repository>(() => _i13.RepositoryImp( + fileUtilsHelper: gh<_i7.FileUtilsHelper>(), + localDataSource: gh<_i9.LocalDataSource>(), + remoteDataSource: gh<_i12.RemoteDataSource>(), + )); + gh.lazySingleton<_i14.EventlyProvider>( + () => _i14.EventlyProvider(repository: gh<_i13.Repository>())); + gh.lazySingleton<_i15.EventHubViewModel>( + () => _i15.EventHubViewModel(gh<_i13.Repository>())); return this; } } -class _$RegisterModule extends _i15.RegisterModule {} +class _$RegisterModule extends _i16.RegisterModule {}