-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4485e8
commit 335a2d1
Showing
73 changed files
with
2,523 additions
and
970 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import 'dart:ui'; | ||
|
||
const purple = Color(0XFF8452DA); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export "./query.dart"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import '../../../core/core.dart'; | ||
import '../../../core/external_dependencies.dart'; | ||
import '../../../shared/dtos/dtos.dart'; | ||
|
||
class GetPraisesSentByUserQueryInput extends QueryInput { | ||
const GetPraisesSentByUserQueryInput({ | ||
required this.userId, | ||
required this.praised, | ||
required this.communityId, | ||
}); | ||
|
||
final String userId; | ||
final UserDto praised; | ||
final String communityId; | ||
} | ||
|
||
class GetPraisesSentByUserQueryOutput extends QueryOutput<List<PraiseDto>> { | ||
GetPraisesSentByUserQueryOutput(super.value); | ||
} | ||
|
||
class GetPraisesSentByUserQuery | ||
extends DataQuery<GetPraisesSentByUserQueryInput> { | ||
GetPraisesSentByUserQuery({ | ||
required DatabaseDatasource databaseDatasource, | ||
}) : _datasource = databaseDatasource; | ||
|
||
final DatabaseDatasource _datasource; | ||
@override | ||
Future<Either<QueryError, GetPraisesSentByUserQueryOutput>> call( | ||
GetPraisesSentByUserQueryInput input, | ||
) async { | ||
final result = await _datasource.get( | ||
GetQuery( | ||
sourceName: praisesCollection, | ||
operator: FilterOperator.equalsTo, | ||
value: input.praised.id, | ||
fieldName: "praised_id", | ||
orderBy: const OrderFilter(field: "created_at"), | ||
select: | ||
"*, $communitiesCollection(title), $profilesCollection!praise_praiser_id_fkey(name, tag, id, email), $reactionsCollection(id, reaction, user_id)", | ||
filters: [ | ||
AndFilter( | ||
fieldName: "praiser_id", | ||
operator: FilterOperator.equalsTo, | ||
value: input.userId, | ||
), | ||
AndFilter( | ||
fieldName: "community_id", | ||
operator: FilterOperator.equalsTo, | ||
value: input.communityId, | ||
), | ||
], | ||
), | ||
); | ||
|
||
if (result.failure) { | ||
return Left(QueryError(result.errorMessage!)); | ||
} | ||
|
||
return Right( | ||
GetPraisesSentByUserQueryOutput( | ||
result.multiData! | ||
.map( | ||
(e) => PraiseDto( | ||
id: e["id"], | ||
message: e["message"], | ||
topic: e["topic"], | ||
communityName: e[communitiesCollection]["title"], | ||
communityId: input.communityId, | ||
private: e["private"], | ||
praiser: UserDto( | ||
tag: e[profilesCollection]["tag"], | ||
name: e[profilesCollection]["name"], | ||
email: e[profilesCollection]["email"], | ||
id: e[profilesCollection]["id"], | ||
), | ||
praised: input.praised, | ||
reactions: e[reactionsCollection] != null | ||
? (e[reactionsCollection] as List) | ||
.cast<Map<String, dynamic>>() | ||
.map( | ||
(reaction) => PraiseReactionDto( | ||
userId: reaction["user_id"], | ||
id: reaction["id"], | ||
praiseId: e["id"], | ||
reaction: reaction["reaction"], | ||
), | ||
) | ||
.toList() | ||
: [], | ||
), | ||
) | ||
.toList(), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
lib/contexts/community/presentation/controllers/praises_sent.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import 'dart:async'; | ||
|
||
import '../../../../core/core.dart'; | ||
import '../../../../core/external_dependencies.dart'; | ||
import '../../../../shared/dtos/dtos.dart'; | ||
import '../../infra/infra.dart'; | ||
|
||
abstract interface class PraisesSentController { | ||
AtomNotifier<DefaultState<Exception, List<PraiseDto>>> get state; | ||
|
||
Future<void> get({ | ||
required String communityId, | ||
required String userId, | ||
required String praisedId, | ||
}); | ||
|
||
void addReaction(PraiseReactionDto reaction); | ||
void removeReaction(PraiseReactionDto reaction); | ||
} | ||
|
||
class DefaultPraisesSentController implements PraisesSentController { | ||
DefaultPraisesSentController({ | ||
required GetPraisesSentByUserQuery getPraisesSentByUserQuery, | ||
}) : _query = getPraisesSentByUserQuery; | ||
final GetPraisesSentByUserQuery _query; | ||
|
||
@override | ||
final AtomNotifier<DefaultState<Exception, List<PraiseDto>>> state = | ||
AtomNotifier(InitialState()); | ||
|
||
@override | ||
Future<void> get({ | ||
required String communityId, | ||
required String userId, | ||
required String praisedId, | ||
}) async { | ||
state.set(LoadingState()); | ||
final praisesOrError = await _query.call( | ||
GetPraisesSentByUserQueryInput( | ||
userId: userId, | ||
praised: UserDto( | ||
tag: "", | ||
name: "", | ||
email: "", | ||
id: praisedId, | ||
), | ||
communityId: communityId, | ||
), | ||
); | ||
state.set( | ||
praisesOrError.fold( | ||
(left) => ErrorState(left), | ||
(right) => SuccessState(right.value), | ||
), | ||
); | ||
} | ||
|
||
@override | ||
void addReaction(PraiseReactionDto input) { | ||
final data = (state.value as SuccessState<Exception, List<PraiseDto>>).data; | ||
|
||
final index = data.indexWhere((element) => element.id == input.praiseId); | ||
|
||
data[index] = data[index].copyWith( | ||
reactions: [ | ||
...data[index].reactions, | ||
input, | ||
], | ||
); | ||
state.set(SuccessState(data)); | ||
} | ||
|
||
@override | ||
void removeReaction(PraiseReactionDto input) { | ||
final data = (state.value as SuccessState<Exception, List<PraiseDto>>).data; | ||
final index = data.indexWhere((element) => element.id == input.praiseId); | ||
data[index].reactions.removeWhere( | ||
(element) => element.id == input.id, | ||
); | ||
state.set(SuccessState(data)); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
lib/contexts/community/presentation/organisms/member_options_sheet.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import 'package:blurple/widgets/buttons/buttons.dart'; | ||
import 'package:boxy/flex.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../../../core/core.dart'; | ||
import '../../../../core/external_dependencies.dart'; | ||
import '../../../../shared/shared.dart'; | ||
import '../presentation.dart'; | ||
|
||
class MemberOptionsSheet extends StatelessWidget { | ||
const MemberOptionsSheet({ | ||
super.key, | ||
required this.canRemove, | ||
required this.member, | ||
required this.community, | ||
}); | ||
|
||
final bool canRemove; | ||
final FindCommunityMemberOutput member; | ||
final CommunityOutput community; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BottomSheetMolecule( | ||
child: SizedBox( | ||
width: 80.w, | ||
child: BoxyColumn( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
if (canRemove) | ||
BaseButton.icon( | ||
label: "Remover", | ||
backgroundColor: Colors.black45, | ||
foregroundColor: Colors.white, | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
showCustomModalBottomSheet( | ||
context: context, | ||
child: RemoveMemberSheet( | ||
member: member, | ||
community: community, | ||
), | ||
); | ||
}, | ||
icon: const Icon(HeroiconsSolid.trash), | ||
), | ||
SizedBox.square( | ||
dimension: context.theme.spacingScheme.verticalSpacing, | ||
), | ||
BaseButton.icon( | ||
label: "Ver praises enviados", | ||
backgroundColor: Colors.black45, | ||
foregroundColor: Colors.white, | ||
onPressed: () { | ||
Navigator.of(context).pushNamed( | ||
PraisesSentScreen.routeName, | ||
arguments: PraisesSentArgs( | ||
community: community, | ||
member: member, | ||
), | ||
); | ||
}, | ||
icon: const Icon(HeroiconsSolid.magnifyingGlass), | ||
), | ||
SizedBox.square( | ||
dimension: context.theme.spacingScheme.verticalSpacing, | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.