diff --git a/lib/helpers/api.dart b/lib/helpers/api.dart index 1678a4b..54e8abd 100644 --- a/lib/helpers/api.dart +++ b/lib/helpers/api.dart @@ -195,7 +195,7 @@ class KnockoutAPI { Future 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; diff --git a/lib/screens/subforum.dart b/lib/screens/subforum.dart index 0a6575c..5066189 100644 --- a/lib/screens/subforum.dart +++ b/lib/screens/subforum.dart @@ -54,6 +54,9 @@ class _SubforumScreenState extends State { widgets.add( SubforumListItem( threadDetails: thread, + onShouldRefresh: () { + subforumController.fetchData(); + }, ), ); }); diff --git a/lib/widgets/subforum/subforumListItem.dart b/lib/widgets/subforum/subforumListItem.dart index c5d2b44..0fe55b5 100644 --- a/lib/widgets/subforum/subforumListItem.dart +++ b/lib/widgets/subforum/subforumListItem.dart @@ -1,6 +1,10 @@ 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'; @@ -8,10 +12,19 @@ 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, @@ -25,6 +38,53 @@ class SubforumListItem extends ThreadListItem { } } + Widget longPressBottomSheetContent() { + return Container( + color: Get.theme.bottomAppBarTheme.color, + child: Wrap( + children: [ + 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 [