Skip to content

Commit

Permalink
feat: save draft functionality upto details
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanRns committed May 20, 2024
1 parent 758d428 commit 928763b
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 13 deletions.
35 changes: 34 additions & 1 deletion evently/lib/evently_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ class EventlyProvider extends ChangeNotifier {
String get location => _location;
String get description => _description;

int? _id;
set setId(int id) {
_id = id;
}

get id => _id;

set setStartDate(String value) {
_startDate = value;
notifyListeners();
Expand Down Expand Up @@ -358,7 +365,33 @@ class EventlyProvider extends ChangeNotifier {
required VoidCallback onCompleted,
required UploadStep uploadStep,
}) async {
await repository.saveEvents(Events(step: uploadStep.toString(), eventName: eventName, hostName: hostName, thumbnail: thumbnail!));
switch (uploadStep) {
case UploadStep.overView:
await repository.saveEvents(Events(step: uploadStep.toString(), eventName: eventName, hostName: hostName, thumbnail: thumbnail!));
break;
case UploadStep.detail:
await repository.saveFromDetail(Events(
id: 1,
step: uploadStep.toString(),
eventName: eventName,
hostName: hostName,
thumbnail: thumbnail!,
startDate: startDate,
endDate: endDate,
startTime: startTime,
endTime: endTime,
location: location,
description: description,
));
break;
case UploadStep.perks:
// TODO: Handle this case.
case UploadStep.price:
// TODO: Handle this case.
case UploadStep.none:
// TODO: Handle this case.
}

onCompleted();
}
}
15 changes: 15 additions & 0 deletions evently/lib/repository/repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ abstract class Repository {
/// Input: [key] the key of the value
/// Output: [String] the value of the key
dynamic getCacheDynamicType({required String key});

Future<Either<Failure, bool>> saveFromDetail(Events events);
}

@LazySingleton(as: Repository)
Expand Down Expand Up @@ -221,4 +223,17 @@ class RepositoryImp implements Repository {
dynamic getCacheDynamicType({required String key}) {
return localDataSource.getCacheDynamicType(key: key);
}

@override
Future<Either<Failure, bool>> saveFromDetail(Events events) async {
try {
final bool result = await localDataSource.saveEventFromDetail(events: events);
if (!result) {
return Left(CacheFailure(LocaleKeys.get_error.tr()));
}
return Right(result);
} on Exception catch (_) {
return Left(CacheFailure(LocaleKeys.get_error.tr()));
}
}
}
6 changes: 6 additions & 0 deletions evently/lib/screens/create_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class _CreateEventState extends State<CreateEvent> {
eventlyProvider.setEventName = createEventViewModel.events!.eventName;
eventlyProvider.setHostName = createEventViewModel.events!.hostName;
eventlyProvider.setThumbnail = createEventViewModel.events!.thumbnail;
eventlyProvider.setStartDate = createEventViewModel.events!.startDate;
eventlyProvider.setEndDate = createEventViewModel.events!.endDate;
eventlyProvider.setStartTime = createEventViewModel.events!.startTime;
eventlyProvider.setEndTime = createEventViewModel.events!.endTime;
eventlyProvider.setLocation = createEventViewModel.events!.location;
eventlyProvider.setDescription = createEventViewModel.events!.description;
});
}

Expand Down
10 changes: 9 additions & 1 deletion evently/lib/screens/detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:evently/screens/custom_widgets/bottom_buttons.dart';
import 'package:evently/screens/custom_widgets/page_app_bar.dart';
import 'package:evently/screens/custom_widgets/step_labels.dart';
import 'package:evently/screens/custom_widgets/steps_indicator.dart';
import 'package:evently/utils/enums.dart';
import 'package:evently/utils/route_util.dart';
import 'package:evently/utils/space_utils.dart';
import 'package:evently/viewmodels/create_event_viewmodel.dart';
import 'package:evently/widgets/evently_text_field.dart';
Expand Down Expand Up @@ -162,7 +164,13 @@ class _DetailsScreenState extends State<DetailsScreen> {
onPressContinue: () {
createEventViewModel.nextPage();
},
onPressSaveDraft: () {},
onPressSaveDraft: () {
final navigator = Navigator.of(context);
provider.saveAsDraft(
onCompleted: () => navigator.popUntil((route) => route.settings.name == RouteUtil.kRouteEventHub),
uploadStep: UploadStep.detail,
);
},
isContinueEnable: provider.startDate.isNotEmpty &&
provider.endDate.isNotEmpty &&
provider.startTime.isNotEmpty &&
Expand Down
22 changes: 22 additions & 0 deletions evently/lib/services/datasources/local_datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ abstract class LocalDataSource {
/// Input: [key] the key of the value
/// Output: [String] the value of the key
String getCacheString({required String key});

/// this method is used to save draft from
Future<bool> saveEventFromDetail({required Events events});
}

@LazySingleton(as: LocalDataSource)
Expand Down Expand Up @@ -214,4 +217,23 @@ class LocalDataSourceImpl extends LocalDataSource {
void deleteCacheDynamic({required String key}) {
cacheManager.deleteCacheDynamic(key: key);
}

@override
Future<bool> saveEventFromDetail({required Events events}) async {
try {
await database.eventsDao.updateNFTFromDetail(
events.startDate,
events.endDate,
events.startTime,
events.endTime,
events.location,
events.description,
events.id!,
events.step,
);
return true;
} catch (e) {
throw CacheFailure(LocaleKeys.get_error.tr());
}
}
}
42 changes: 32 additions & 10 deletions evently/lib/services/third_party_services/database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion evently/lib/services/third_party_services/event_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class EventsDao {
@Query('DELETE FROM events WHERE id = :id')
Future<void> delete(int id);

@Query('UPDATE events SET startDate = :startDate, endDate= :endDate, startTime = :startTime, endTime = :endTime,location = :location, description = :description WHERE id = :id')
@Query('UPDATE events SET startDate = :startDate, endDate= :endDate, startTime = :startTime, endTime = :endTime,location = :location, description = :description, step = :step WHERE id = :id')
Future<void> updateNFTFromDetail(
String startDate,
String endDate,
Expand All @@ -24,6 +24,7 @@ abstract class EventsDao {
String location,
String description,
int id,
String step,
);

@Query('UPDATE events SET listOfPerks = :listOfPerks WHERE id = :id')
Expand Down

0 comments on commit 928763b

Please sign in to comment.