Skip to content

Commit

Permalink
refactor: commitmentoptions to commitments
Browse files Browse the repository at this point in the history
  • Loading branch information
Xazin committed Feb 28, 2023
1 parent 7fa9ecc commit 6cdb5b8
Show file tree
Hide file tree
Showing 35 changed files with 243 additions and 313 deletions.
4 changes: 2 additions & 2 deletions lib/application/participation/participation_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class ParticipationBloc extends Bloc<ParticipationEvent, ParticipationState> {
checkIn: () {
// TODO: Implement once the backend has implemented it
},
toggleParticipation: (crowdActionId, commitmentOptions) async {
toggleParticipation: (crowdActionId, commitments) async {
emit(const ParticipationState.loading());

await participationRepository.toggleParticipation(
crowdActionId: crowdActionId,
commitmentOptions: commitmentOptions,
commitments: commitments,
);

add(
Expand Down
2 changes: 1 addition & 1 deletion lib/application/participation/participation_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class ParticipationEvent with _$ParticipationEvent {
const factory ParticipationEvent.checkIn() = _CheckIn;
const factory ParticipationEvent.toggleParticipation({
required String crowdActionId,
List<String>? commitmentOptions,
List<String>? commitments,
}) = _ToggleParticipation;
}
12 changes: 5 additions & 7 deletions lib/domain/crowdaction/crowdaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ class CrowdAction with _$CrowdAction {

const factory CrowdAction({
required String id,
required String type,
required String title,
required String description,
required String category,
required Location location,
required List<CommitmentOption> commitmentOptions,
required List<Commitment> commitments,
required Images images,
required int participantCount,
required Status status,
Expand Down Expand Up @@ -93,18 +92,17 @@ enum JoinStatus {
}

@freezed
class CommitmentOption with _$CommitmentOption {
const CommitmentOption._();
class Commitment with _$Commitment {
const Commitment._();

factory CommitmentOption({
factory Commitment({
required String id,
required String type,
required String label,
required int points,
required List<String> blocks,
String? description,
String? iconId,
}) = _CommitmentOption;
}) = _Commitment;

IconData get icon => iconId != null
? IconUtil.fromString(iconId!)
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/participation/i_participation_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class IParticipationRepository {

Future<Either<ParticipationFailure, Unit>> toggleParticipation({
required String crowdActionId,
List<String>? commitmentOptions,
List<String>? commitments,
});

Future<Either<ParticipationFailure, PaginatedParticipations>>
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/participation/participation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Participation with _$Participation {
required String fullName,
required String avatar,
required String userId,
required List<String> commitmentOptions,
required List<String> commitments,
required DateTime joinDate,
required int dailyCheckIns,
}) = _Participation;
Expand Down
28 changes: 12 additions & 16 deletions lib/infrastructure/crowdaction/crowdaction_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ class CrowdActionDto with _$CrowdActionDto {

const factory CrowdActionDto({
required String id,
required String type,
required String title,
required String description,
required String category,
required LocationDto location,
required List<CommitmentOptionDto> commitmentOptions,
required List<CommitmentDto> commitments,
required ImagesDto images,
required int participantCount,
required Status status,
Expand All @@ -32,13 +31,11 @@ class CrowdActionDto with _$CrowdActionDto {
CrowdAction toDomain() {
return CrowdAction(
id: id,
type: type,
title: title,
description: description,
category: category,
location: location.toDomain(),
commitmentOptions:
commitmentOptions.map((option) => option.toDomain()).toList(),
commitments: commitments.map((c) => c.toDomain()).toList(),
images: images.toDomain(),
participantCount: participantCount,
status: status,
Expand Down Expand Up @@ -94,23 +91,22 @@ class LocationDto with _$LocationDto {
}

@freezed
class CommitmentOptionDto with _$CommitmentOptionDto {
const CommitmentOptionDto._();
class CommitmentDto with _$CommitmentDto {
const CommitmentDto._();

factory CommitmentOptionDto({
required String id,
required String type,
factory CommitmentDto({
// ignore: invalid_annotation_target
@JsonKey(name: '_id') required String id,
required String label,
required int points,
required List<String> blocks,
String? description,
String? icon,
}) = _CommitmentOptionDto;
}) = _CommitmentDto;

CommitmentOption toDomain() {
return CommitmentOption(
Commitment toDomain() {
return Commitment(
id: id,
type: type,
label: label,
points: points,
blocks: blocks,
Expand All @@ -119,6 +115,6 @@ class CommitmentOptionDto with _$CommitmentOptionDto {
);
}

factory CommitmentOptionDto.fromJson(Map<String, dynamic> json) =>
_$CommitmentOptionDtoFromJson(json);
factory CommitmentDto.fromJson(Map<String, dynamic> json) =>
_$CommitmentDtoFromJson(json);
}
4 changes: 2 additions & 2 deletions lib/infrastructure/participation/participation_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ParticipationDto with _$ParticipationDto {
required String userId,
required String fullName,
required String avatar,
required List<String> commitmentOptions,
required List<String> commitments,
required String joinDate,
required int dailyCheckIns,
}) = _ParticipationDto;
Expand All @@ -27,7 +27,7 @@ class ParticipationDto with _$ParticipationDto {
userId: userId,
fullName: fullName,
avatar: avatar,
commitmentOptions: commitmentOptions,
commitments: commitments,
joinDate: DateTime.parse(joinDate),
dailyCheckIns: dailyCheckIns,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ParticipationRepository implements IParticipationRepository {
@override
Future<Either<ParticipationFailure, Unit>> toggleParticipation({
required String crowdActionId,
List<String>? commitmentOptions,
List<String>? commitments,
}) async {
try {
final user = (await authRepository.getSignedInUser())
Expand All @@ -82,7 +82,7 @@ class ParticipationRepository implements IParticipationRepository {
uri,
body: json.encode({
'crowdActionId': crowdActionId,
'commitmentOptions': commitmentOptions,
'commitments': commitments,
}),
headers: {
'Content-Type': 'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CrowdActionDetailsPage extends StatefulWidget {
}

class CrowdActionDetailsPageState extends State<CrowdActionDetailsPage> {
final List<CommitmentOption> selectedCommitments = [];
final List<Commitment> selectedCommitments = [];
CrowdAction? crowdAction;
late final ParticipationBloc participationBloc;
late Function(BuildContext) participate;
Expand Down Expand Up @@ -86,10 +86,9 @@ class CrowdActionDetailsPageState extends State<CrowdActionDetailsPage> {
participating: (p) {
setState(() {
selectedCommitments.clear();
for (final id in p.commitmentOptions) {
for (final id in p.commitments) {
selectedCommitments.add(
crowdAction!.commitmentOptions
.firstWhere((c) => c.id == id),
crowdAction!.commitments.firstWhere((c) => c.id == id),
);
}
});
Expand Down Expand Up @@ -231,7 +230,7 @@ class CrowdActionDetailsPageState extends State<CrowdActionDetailsPage> {
),
CommitmentCardList(
isEnded: crowdAction?.isClosed ?? true,
commitmentOptions: crowdAction?.commitmentOptions,
commitments: crowdAction?.commitments,
selectedCommitments: selectedCommitments,
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '../../../themes/constants.dart';

class ConfirmParticipation extends StatelessWidget {
final CrowdAction crowdAction;
final List<CommitmentOption> selectedCommitments;
final List<Commitment> selectedCommitments;

const ConfirmParticipation({
super.key,
Expand Down Expand Up @@ -116,7 +116,7 @@ class ParticipationSuccess extends StatelessWidget {

class ParticipationDialog extends StatelessWidget {
final CrowdAction crowdAction;
final List<CommitmentOption> selectedCommitments;
final List<Commitment> selectedCommitments;
final bool isLoading;

const ParticipationDialog({
Expand Down Expand Up @@ -213,8 +213,7 @@ class ParticipationDialog extends StatelessWidget {
BlocProvider.of<ParticipationBloc>(context).add(
ParticipationEvent.toggleParticipation(
crowdActionId: crowdAction.id,
commitmentOptions:
selectedCommitments.map((c) => c.id).toList(),
commitments: selectedCommitments.map((c) => c.id).toList(),
),
);
},
Expand Down
18 changes: 6 additions & 12 deletions lib/presentation/demo/components_demo/components_demo_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class ComponentsDemoPageState extends State<ComponentsDemoPage> {
CrowdActionCard(
crowdAction: CrowdAction(
id: "",
type: "",
title:
"This is the headline for a crowdaction with three lines",
images: const Images(
Expand All @@ -59,18 +58,16 @@ class ComponentsDemoPageState extends State<ComponentsDemoPage> {
),
category: "Sustainability",
subcategory: "Community",
commitmentOptions: [
CommitmentOption(
commitments: [
Commitment(
id: "",
type: "food",
label: "no-beef",
description: "Don't eat beef for 30 days!",
points: 0,
blocks: [],
),
CommitmentOption(
Commitment(
id: "",
type: "food",
label: "vegetarian",
description: "Don't eat meat for 30 days!",
points: 0,
Expand All @@ -92,7 +89,6 @@ class ComponentsDemoPageState extends State<ComponentsDemoPage> {
CrowdActionCard(
crowdAction: CrowdAction(
id: "",
type: "",
title:
"This is the headline for a crowdaction with three lines",
images: const Images(
Expand All @@ -101,18 +97,16 @@ class ComponentsDemoPageState extends State<ComponentsDemoPage> {
),
category: "Sustainability",
subcategory: "Community",
commitmentOptions: [
CommitmentOption(
commitments: [
Commitment(
id: "",
type: "food",
label: "no-beef",
description: "Don't eat beef for 30 days!",
points: 0,
blocks: [],
),
CommitmentOption(
Commitment(
id: "",
type: "food",
label: "vegetarian",
description: "Don't eat meat for 30 days!",
points: 0,
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/profile/widget/commitments_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CommitmentsTab extends StatelessWidget {
fontWeight: FontWeight.w500,
),
),
...crowdAction.commitmentOptions.map(
...crowdAction.commitments.map(
(co) => CommitmentCard(
commitment: co,
viewOnly: true,
Expand Down
3 changes: 0 additions & 3 deletions lib/presentation/shared_widgets/commitment_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ class _CommitmentCardState extends State<_CommitmentCard> {

@override
Widget build(BuildContext context) {
print(
'Commitment: ${widget.commitment.title} - Icon: ${widget.commitment.icon}');

final textTheme = Theme.of(context).textTheme;
return GestureDetector(
onTap: () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import '../../themes/constants.dart';
/// [onSelected] Callback function for when the card is selected,
/// returns the id of the selected commitment
class CommitmentCard extends StatelessWidget {
final CommitmentOption commitment;
final Function(CommitmentOption)? onSelected;
final Function(CommitmentOption)? onDeSelected;
final Commitment commitment;
final Function(Commitment)? onSelected;
final Function(Commitment)? onDeSelected;
final bool active;
final bool deactivated;
final bool viewOnly;
Expand Down
Loading

0 comments on commit 6cdb5b8

Please sign in to comment.