-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
7 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
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,26 @@ | ||
import 'package:get/get.dart'; | ||
import 'package:knocky/helpers/api.dart'; | ||
import 'package:knocky/helpers/postsPerPage.dart'; | ||
import 'package:knocky/models/v2/alerts.dart'; | ||
import 'package:knocky/models/v2/thread.dart'; | ||
|
||
class HiddenThreadsController extends GetxController { | ||
final isFetching = false.obs; | ||
final RxList<ForumThread> threads = <ForumThread>[].obs; | ||
|
||
@override | ||
onInit() { | ||
super.onInit(); | ||
} | ||
|
||
initState() { | ||
fetch(); | ||
} | ||
|
||
void fetch() async { | ||
isFetching.value = true; | ||
// Get hidden threads | ||
threads.value = await KnockoutAPI().hiddenThreads(); | ||
isFetching.value = false; | ||
} | ||
} |
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,79 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:knocky/controllers/hiddenThreadsController.dart'; | ||
import 'package:knocky/controllers/subscriptionController.dart'; | ||
import 'package:knocky/widgets/KnockoutLoadingIndicator.dart'; | ||
import 'package:knocky/widgets/forum/ForumListItem.dart'; | ||
import 'package:knocky/widgets/hiddenThreads/hiddenThreadListItem.dart'; | ||
import 'package:knocky/widgets/shared/pageSelector.dart'; | ||
import 'package:knocky/widgets/shared/threadListItem.dart'; | ||
import 'package:knocky/widgets/subforum/subforumListItem.dart'; | ||
import 'package:knocky/widgets/subscriptions/subscriptionListItem.dart'; | ||
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; | ||
|
||
class ManageHiddenThreadsScreen extends StatefulWidget { | ||
@override | ||
_ManageHiddenThreadsScreenState createState() => | ||
_ManageHiddenThreadsScreenState(); | ||
} | ||
|
||
class _ManageHiddenThreadsScreenState extends State<ManageHiddenThreadsScreen> { | ||
final HiddenThreadsController hiddenThreadsController = | ||
Get.put(HiddenThreadsController()); | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
hiddenThreadsController.initState(); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text('Hidden threads'), | ||
), | ||
body: Container( | ||
child: Obx( | ||
() => KnockoutLoadingIndicator( | ||
show: hiddenThreadsController.isFetching.value, | ||
child: RefreshIndicator( | ||
onRefresh: () async => hiddenThreadsController.fetch(), | ||
child: hiddenThreadsController.threads.value.length == 0 | ||
? noHiddenThreads() | ||
: threads(), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget noHiddenThreads() { | ||
return Center( | ||
child: Text( | ||
"You don't have hidden any threads...", | ||
style: TextStyle( | ||
fontSize: 22, | ||
color: Colors.grey, | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget threads() { | ||
return Container( | ||
padding: EdgeInsets.fromLTRB(0, 4, 0, 4), | ||
child: ScrollablePositionedList.builder( | ||
// ignore: invalid_use_of_protected_member | ||
itemCount: hiddenThreadsController.threads.value.length ?? 0, | ||
itemBuilder: (BuildContext context, int index) { | ||
return HiddenThreadListItem( | ||
threadDetails: hiddenThreadsController.threads.value[index], | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} |
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,45 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:knocky/controllers/hiddenThreadsController.dart'; | ||
import 'package:knocky/controllers/subscriptionController.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/v2/thread.dart'; | ||
import 'package:knocky/screens/thread.dart'; | ||
import 'package:knocky/widgets/jumpToPageDialog.dart'; | ||
import 'package:knocky/widgets/shared/threadListItem.dart'; | ||
|
||
class HiddenThreadListItem extends ThreadListItem { | ||
final ForumThread? threadDetails; | ||
final HiddenThreadsController hiddenThreadsController = | ||
Get.put(HiddenThreadsController()); | ||
|
||
HiddenThreadListItem({required this.threadDetails}) | ||
: super(threadDetails: threadDetails); | ||
|
||
@override | ||
void onTapItem(BuildContext context) async { | ||
// TODO: implement onTapItem | ||
bool confirmResult = await (Get.dialog(ConfirmDialog( | ||
content: "Do you want unhide the thread?", | ||
))); | ||
|
||
if (!confirmResult) return; | ||
|
||
SnackbarController snackbarController = KnockySnackbar.normal( | ||
"Unhiding thread...", | ||
"Please wait...", | ||
isDismissible: false, | ||
showProgressIndicator: true, | ||
); | ||
|
||
await KnockoutAPI().unhideThread(threadDetails!.id!); | ||
snackbarController.close(); | ||
|
||
KnockySnackbar.success('Thread is now unhidden!'); | ||
hiddenThreadsController.fetch(); | ||
} | ||
} |
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