Skip to content

Commit

Permalink
Merge pull request #94 from IamMuuo/chirp
Browse files Browse the repository at this point in the history
Chirp
  • Loading branch information
IamMuuo authored Oct 3, 2024
2 parents f051414 + 6653e5f commit fe33044
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 121 deletions.
8 changes: 6 additions & 2 deletions lib/tools/chirp/pages/post_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ class _PostViewPageState extends State<PostViewPage> {
child: TextFormField(
controller: replyController,
decoration: InputDecoration(
fillColor:
Theme.of(context).colorScheme.surfaceContainer,
suffixIcon: IconButton(
onPressed: () async {
final result = await controller.postComment(
Expand All @@ -225,12 +227,14 @@ class _PostViewPageState extends State<PostViewPage> {
replyController.clear();
});
});
FocusManager.instance.primaryFocus?.unfocus();
},
icon: const Icon(Ionicons.send),
),
hintText: "Send a reply",
border: const OutlineInputBorder(
borderSide: BorderSide(width: 1),
border: OutlineInputBorder(
borderSide: const BorderSide(width: 1),
borderRadius: BorderRadius.circular(24),
),
),
),
Expand Down
245 changes: 130 additions & 115 deletions lib/tools/chirp/widgets/comment_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,137 +26,152 @@ class _CommentWidgetState extends State<CommentWidget> {
void initState() {
super.initState();
setState(() {
showSubPosts = widget.depth > 0 ? false : true;
showSubPosts = widget.depth > 10 ? false : true;
});
}

@override
Widget build(BuildContext context) {
return SwipeTo(
onRightSwipe: (data) {
showModalBottomSheet(
useSafeArea: true,
context: context,
builder: (context) => Container(
height: 120,
padding: const EdgeInsets.all(8),
child: Column(
children: [
Text(
"Send a reply to @${widget.comment.user.username}",
style: Theme.of(context).textTheme.titleMedium,
return GestureDetector(
onTap: () {
setState(() {
showSubPosts = !showSubPosts;
});
},
child: SwipeTo(
onRightSwipe: (data) {
showModalBottomSheet(
useSafeArea: true,
context: context,
isScrollControlled: true,
builder: (context) => SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(
top: 8,
right: 8,
left: 8,
bottom: MediaQuery.of(context).viewInsets.bottom,
),
const SizedBox(height: 22),
TextFormField(
controller: replyController,
decoration: InputDecoration(
suffixIcon: IconButton(
onPressed: () async {
final result = await chirpController.postComment(
userController.user.value!.id!,
widget.comment.post.id,
widget.comment.id,
replyController.text,
);
result.fold((l) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text("Error"),
content: Text(l),
));
}, (r) {
setState(() {
widget.comment.replies.add(r);
});
});
},
icon: const Icon(Ionicons.send),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Send a reply to @${widget.comment.user.username}",
style: Theme.of(context).textTheme.titleMedium,
),
hintText: "Send a reply",
border: const OutlineInputBorder(
borderSide: BorderSide(width: 1),
const SizedBox(height: 22),
TextFormField(
controller: replyController,
decoration: InputDecoration(
suffixIcon: IconButton(
onPressed: () async {
final result = await chirpController.postComment(
userController.user.value!.id!,
widget.comment.post.id,
widget.comment.id,
replyController.text,
);
result.fold((l) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text("Error"),
content: Text(l),
));
}, (r) {
setState(() {
widget.comment.replies.add(r);
});
});
},
icon: const Icon(Ionicons.send),
),
hintText: "Send a reply",
border: const OutlineInputBorder(
borderSide: BorderSide(width: 1),
),
),
),
),
],
),
],
),
),
),
);
},
child: Container(
decoration: BoxDecoration(
border: Border(
left: BorderSide(
color: Theme.of(context).colorScheme.tertiary,
width: 1.0,
);
},
child: Container(
decoration: BoxDecoration(
border: Border(
left: BorderSide(
color: Theme.of(context).colorScheme.tertiary,
width: 1.0,
),
),
),
),
padding: const EdgeInsets.all(4),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
widget.comment.user.profilePhoto != null
? CircleAvatar(
backgroundImage: CachedNetworkImageProvider(
widget.comment.user.profilePhoto ?? '',
padding: const EdgeInsets.all(4),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
widget.comment.user.profilePhoto != null
? CircleAvatar(
backgroundImage: CachedNetworkImageProvider(
widget.comment.user.profilePhoto ?? '',
),
)
: Image.asset(
"assets/images/male_student.png",
height: 30,
),
)
: Image.asset(
"assets/images/male_student.png",
height: 30,
),
const SizedBox(width: 4),
Text((userController.user.value?.id ?? "") ==
widget.comment.user.id
? "You"
: "@${widget.comment.user.username}"),
const SizedBox(width: 12),
Text(
timeago.format(widget.comment.createdAt),
style: Theme.of(context).textTheme.bodySmall,
),
],
),
const SizedBox(height: 4),
Text(
widget.comment.content,
style: Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 4),
Padding(
padding: const EdgeInsets.only(
left: 8,
const SizedBox(width: 4),
Text((userController.user.value?.id ?? "") ==
widget.comment.user.id
? "You"
: "@${widget.comment.user.username}"),
const SizedBox(width: 12),
Text(
timeago.format(widget.comment.createdAt),
style: Theme.of(context).textTheme.bodySmall,
),
],
),
const SizedBox(height: 4),
Text(
widget.comment.content,
style: Theme.of(context).textTheme.bodySmall,
),
child: showSubPosts
? ListView.builder(
shrinkWrap: true,
itemBuilder: (context, index) {
final data = widget.comment.replies[index];
return CommentWidget(
comment: data,
depth: widget.depth + 1,
);
},
itemCount: widget.comment.replies.length,
)
: Visibility(
visible: widget.comment.replies.isNotEmpty,
child: TextButton(
onPressed: () {
setState(() {
showSubPosts = !showSubPosts;
});
const SizedBox(height: 4),
Padding(
padding: const EdgeInsets.only(
left: 8,
),
child: showSubPosts
? ListView.builder(
shrinkWrap: true,
itemBuilder: (context, index) {
final data = widget.comment.replies[index];
return CommentWidget(
comment: data,
depth: widget.depth + 1,
);
},
child: const Text("Show replies"),
itemCount: widget.comment.replies.length,
)
: Visibility(
visible: widget.comment.replies.isNotEmpty,
child: TextButton(
onPressed: () {
setState(() {
showSubPosts = !showSubPosts;
});
},
child: const Text("Show replies"),
),
),
),
),
],
),
],
),
),
),
);
Expand Down
19 changes: 15 additions & 4 deletions lib/tools/chirp/widgets/post_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PostCard extends StatefulWidget {
});

final Post post;

@override
State<PostCard> createState() => _PostCardState();
}
Expand Down Expand Up @@ -38,7 +39,7 @@ class _PostCardState extends State<PostCard> {
));
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: Column(
children: [
Row(
Expand Down Expand Up @@ -114,15 +115,15 @@ class _PostCardState extends State<PostCard> {
const SizedBox(height: 4),
Text(
trimTo99Characters(widget.post.content),
style: Theme.of(context).textTheme.bodySmall,
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
const SizedBox(height: 4),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
FilledButton.tonalIcon(
OutlinedButton.icon(
icon: const Icon(Ionicons.arrow_up_circle_outline),
onPressed: () {
ps
Expand All @@ -147,7 +148,7 @@ class _PostCardState extends State<PostCard> {
label: Text(upvotes.toString()),
),
const SizedBox(width: 4),
FilledButton.tonalIcon(
OutlinedButton.icon(
label: Text(downvotes.toString()),
onPressed: () {
ps
Expand All @@ -171,6 +172,16 @@ class _PostCardState extends State<PostCard> {
},
icon: const Icon(Ionicons.arrow_down_circle_outline),
),
const Spacer(),
Row(
children: [
const Icon(
Ionicons.chatbubble_ellipses,
),
const SizedBox(width: 8),
Text(widget.post.commentsCount.toString())
],
)
],
),
],
Expand Down

0 comments on commit fe33044

Please sign in to comment.