Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned up reply functionality #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions app/lib/service/http_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,25 @@ import 'package:opengov_common/models/poll.dart';
import 'package:opengov_common/models/report.dart';
import 'package:opengov_common/models/token.dart';
import 'package:opengov_common/models/user.dart';
import 'package:opengov_common/actions/comment_details.dart';
import 'package:shared_preferences/shared_preferences.dart';


class HttpService {
static final _client = Client();

static Uri _uri(String path) {
var scheme = 'https';
var host = 'app.crimsonopengov.us';
int? port;

assert(() {
scheme = 'http';
host = '192.168.2.198';
port = 8017;
return true;
}());


return Uri(scheme: scheme, host: host, port: port, path: 'api/$path');
}
Expand Down Expand Up @@ -83,12 +86,15 @@ class HttpService {
static Future<Comment?> getCommentDetails(CommentBase comment) =>
_get('poll/comment/${comment.id}', Comment.fromJson);

static Future<Report?> getReport(Poll poll) =>
_get('poll/report/${poll.id}', Report.fromJson);
static Future<Report?> getReport(int pollId, int parentId) =>
_get('poll/report/$pollId/$parentId', Report.fromJson);

static Future<AddCommentResponse?> addComment(AddCommentRequest request) =>
_post('poll/add-comment', request.toJson(), AddCommentResponse.fromJson);

static Future<CommentDetailsResponse?> getCommentReplies(int commentId) =>
_get('poll/details/comment/$commentId', CommentDetailsResponse.fromJson);

static Future<GenericResponse?> vote(VoteRequest request) =>
_post('poll/vote', request.toJson(), GenericResponse.fromJson);

Expand Down Expand Up @@ -123,6 +129,6 @@ class HttpService {

static Future<FeedResponse?> getRandomFeed() =>
_get('feed/random', FeedResponse.fromJson);

static Future<User?> getMe() => _get('user/me', User.fromJson);
}
2 changes: 1 addition & 1 deletion app/lib/service/notification_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NotificationService {
context,
MaterialPageRoute(
builder: (_) =>
PollDetails(pollId: int.parse(message.data['pollId']))),
PollDetails(parentId: int.parse(message.data['pollId']), isReply: false)),
);
} else if (message.data.containsKey('announcementId')) {
Navigator.push(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/widgets/announcement/announcement_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class _AnnouncementDetailsState extends State<AnnouncementDetails> {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => PollDetails(pollId: _poll!.id)),
builder: (_) => PollDetails(parentId: _poll!.id, isReply: false)),
);
},
),
Expand Down
3 changes: 2 additions & 1 deletion app/lib/widgets/feed/feed_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ class _FeedViewState extends State<FeedView> {
CommentList(
comments: _comments!,
onActionPressed: _fetchComment,
isReply: false,
),
OutlinedButton(
child: const Text('Load more comments'),
child: const Text('Load more messages'),
onPressed: _fetchData,
),
],
Expand Down
23 changes: 12 additions & 11 deletions app/lib/widgets/polls/details/add_comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'package:opengov_common/actions/add_comment.dart';
import 'package:opengov_common/models/poll.dart';

class AddComment extends StatefulWidget {
final Poll poll;

const AddComment({required this.poll});
final int pollId;
final int parentId; //0 if top level comment
const AddComment({required this.pollId, required this.parentId});

@override
_AddCommentState createState() => _AddCommentState();
Expand All @@ -32,22 +32,23 @@ class _AddCommentState extends State<AddComment> {

Future<void> _addComment() async {
final response = await HttpService.addComment(AddCommentRequest(
pollId: widget.poll.id,
comment: _textController.text,
));
pollId: widget.pollId,
comment: _textController.text,
parentId: widget.parentId,
));

switch (response?.reason) {
case null:
case AddCommentResponseReason.error:
setState(() {
_responseMessage =
'A server error occurred while posting your comment.';
'A server error occurred while posting your message.';
});
break;
case AddCommentResponseReason.curseWords:
setState(() {
_responseMessage =
"Please ensure that your comment doesn't contain any swear "
"Please ensure that your message doesn't contain any swear "
"words.";
});
break;
Expand All @@ -56,9 +57,9 @@ class _AddCommentState extends State<AddComment> {
setState(() {
_responseMessage = response!.reason ==
AddCommentResponseReason.needsApproval
? 'Comment sent! Your comment will be displayed to other users '
? 'Message sent! Your message will be displayed to other users '
'once it is approved by an admin.'
: 'Comment sent! Your comment is now visible to other users.';
: 'Message sent! Your message is now visible to other users.';
_textController.clear();
});
if (await InAppReview.instance.isAvailable()) {
Expand Down Expand Up @@ -86,7 +87,7 @@ class _AddCommentState extends State<AddComment> {
children: [
const Expanded(
child: Text(
'Your comment will appear in other people’s feeds to be '
'Your message will appear in other people’s feeds to be '
'voted on.',
style: TextStyle(fontStyle: FontStyle.italic),
),
Expand Down
Loading