Skip to content

Commit

Permalink
Add mark thread unread
Browse files Browse the repository at this point in the history
  • Loading branch information
dasmikko committed Feb 27, 2023
1 parent c822706 commit 6c6f769
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/helpers/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class KnockoutAPI {
Future<void> readThreadsMarkUnread(int threadId) async {
try {
await _request(
type: 'post', url: 'readThreads', data: {'thread_id': threadId});
type: 'delete', url: 'readThreads', data: {'threadId': threadId});
} on DioError catch (e) {
onDioErrorHandler(e);
throw e;
Expand Down
3 changes: 3 additions & 0 deletions lib/screens/subforum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class _SubforumScreenState extends State<SubforumScreen> {
widgets.add(
SubforumListItem(
threadDetails: thread,
onShouldRefresh: () {
subforumController.fetchData();
},
),
);
});
Expand Down
62 changes: 61 additions & 1 deletion lib/widgets/subforum/subforumListItem.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';
import 'package:knocky/dialogs/confirmDialog.dart';
import 'package:knocky/helpers/api.dart';
import 'package:knocky/helpers/postsPerPage.dart';
import 'package:knocky/helpers/snackbar.dart';
import 'package:knocky/models/subforumv2.dart' as Subforumv2;
import 'package:knocky/widgets/jumpToPageDialog.dart';
import 'package:knocky/screens/thread.dart';
import 'package:knocky/widgets/shared/threadListItem.dart';

class SubforumListItem extends ThreadListItem {
final Subforumv2.Thread? threadDetails;
SubforumListItem({this.threadDetails});
final Function? onShouldRefresh;
SubforumListItem({this.threadDetails, this.onShouldRefresh});

@override
void onLongPressItem(BuildContext context) async {
Get.bottomSheet(
longPressBottomSheetContent(),
enterBottomSheetDuration: Duration(milliseconds: 150),
exitBottomSheetDuration: Duration(milliseconds: 150),
);
}

void showJumpDialog() async {
int? page = await Get.dialog(
JumpToPageDialog(
minValue: 1,
Expand All @@ -25,6 +38,53 @@ class SubforumListItem extends ThreadListItem {
}
}

Widget longPressBottomSheetContent() {
return Container(
color: Get.theme.bottomAppBarTheme.color,
child: Wrap(
children: <Widget>[
ListTile(
enabled: threadDetails?.read == true,
leading: FaIcon(FontAwesomeIcons.glasses),
title: Text('Mark thread unread'),
onTap: () async {
Get.back();

bool confirmResult = await (Get.dialog(ConfirmDialog(
content: "Do you want to mark thread unread?",
)));

if (!confirmResult) return;

SnackbarController snackbarController = KnockySnackbar.normal(
"Marking thread unread...",
"Please wait...",
isDismissible: false,
showProgressIndicator: true,
);

await KnockoutAPI().readThreadsMarkUnread(threadDetails!.id!);
snackbarController.close();

KnockySnackbar.success("Thread was marked unread");

if (onShouldRefresh != null) {
onShouldRefresh!();
}
}),
ListTile(
leading: FaIcon(FontAwesomeIcons.arrowRotateRight),
title: Text('Go to page'),
onTap: () {
Get.back();
showJumpDialog();
},
),
],
),
);
}

@override
List getTagWidgets(BuildContext context) {
return [
Expand Down

0 comments on commit 6c6f769

Please sign in to comment.