opt: remove reply after deleted

This commit is contained in:
bggRGjQaUbCoE
2024-09-06 11:19:08 +08:00
parent d5fbde70fa
commit c37f6835f8
3 changed files with 61 additions and 9 deletions

View File

@@ -277,6 +277,26 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
} }
}); });
}, },
onDelete: (rpid, frpid) {
frpid == null
? _videoReplyController.replyList.value =
_videoReplyController.replyList
.where(
(item) => item.rpid != rpid)
.toList()
: _videoReplyController.replyList
.map((item) {
if (item.rpid == frpid) {
return item
..replies = item.replies
?.where((reply) =>
reply.rpid != rpid)
.toList();
} else {
return item;
}
}).toList();
},
); );
} }
}, },

View File

@@ -24,6 +24,7 @@ Box setting = GStorage.setting;
class ReplyItem extends StatelessWidget { class ReplyItem extends StatelessWidget {
const ReplyItem({ const ReplyItem({
super.key,
this.replyItem, this.replyItem,
this.addReply, this.addReply,
this.replyLevel, this.replyLevel,
@@ -32,7 +33,7 @@ class ReplyItem extends StatelessWidget {
this.replyType, this.replyType,
this.needDivider = true, this.needDivider = true,
this.onReply, this.onReply,
super.key, this.onDelete,
}); });
final ReplyItemModel? replyItem; final ReplyItemModel? replyItem;
final Function? addReply; final Function? addReply;
@@ -42,6 +43,7 @@ class ReplyItem extends StatelessWidget {
final ReplyType? replyType; final ReplyType? replyType;
final bool needDivider; final bool needDivider;
final Function()? onReply; final Function()? onReply;
final Function(dynamic rpid, dynamic frpid)? onDelete;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -61,7 +63,14 @@ class ReplyItem extends StatelessWidget {
useRootNavigator: true, useRootNavigator: true,
isScrollControlled: true, isScrollControlled: true,
builder: (context) { builder: (context) {
return MorePanel(item: replyItem!); return MorePanel(
item: replyItem!,
onDelete: (rpid) {
if (onDelete != null) {
onDelete!(rpid, null);
}
},
);
}, },
); );
}, },
@@ -107,7 +116,7 @@ class ReplyItem extends StatelessWidget {
decoration: BoxDecoration( decoration: BoxDecoration(
//borderRadius: BorderRadius.circular(7), //borderRadius: BorderRadius.circular(7),
shape: BoxShape.circle, shape: BoxShape.circle,
color: Theme.of(context).colorScheme.background, color: Theme.of(context).colorScheme.surface,
), ),
child: Image.asset( child: Image.asset(
'assets/images/big-vip.png', 'assets/images/big-vip.png',
@@ -288,6 +297,11 @@ class ReplyItem extends StatelessWidget {
// f_rpid: replyItem!.rpid, // f_rpid: replyItem!.rpid,
replyItem: replyItem, replyItem: replyItem,
replyReply: replyReply, replyReply: replyReply,
onDelete: (rpid) {
if (onDelete != null) {
onDelete!(rpid, replyItem!.rpid);
}
},
), ),
), ),
], ],
@@ -423,12 +437,14 @@ class ReplyItemRow extends StatelessWidget {
// this.f_rpid, // this.f_rpid,
this.replyItem, this.replyItem,
this.replyReply, this.replyReply,
this.onDelete,
}); });
final List<ReplyItemModel>? replies; final List<ReplyItemModel>? replies;
ReplyControl? replyControl; ReplyControl? replyControl;
// int? f_rpid; // int? f_rpid;
ReplyItemModel? replyItem; ReplyItemModel? replyItem;
Function? replyReply; Function? replyReply;
final Function(dynamic rpid)? onDelete;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -456,7 +472,10 @@ class ReplyItemRow extends StatelessWidget {
useRootNavigator: true, useRootNavigator: true,
isScrollControlled: true, isScrollControlled: true,
builder: (context) { builder: (context) {
return MorePanel(item: replies![i]); return MorePanel(
item: replies![i],
onDelete: onDelete,
);
}, },
); );
}, },
@@ -1071,8 +1090,9 @@ InlineSpan buildContent(
class MorePanel extends StatelessWidget { class MorePanel extends StatelessWidget {
final ReplyItemModel item; final ReplyItemModel item;
final Function(dynamic rpid)? onDelete;
const MorePanel({super.key, required this.item}); const MorePanel({super.key, required this.item, this.onDelete});
Future<dynamic> menuActionHandler(String type) async { Future<dynamic> menuActionHandler(String type) async {
String message = item.content?.message ?? ''; String message = item.content?.message ?? '';
@@ -1145,8 +1165,11 @@ class MorePanel extends StatelessWidget {
type: item.type!, oid: item.oid!, rpid: item.rpid!); type: item.type!, oid: item.oid!, rpid: item.rpid!);
SmartDialog.dismiss(); SmartDialog.dismiss();
if (result['status']) { if (result['status']) {
SmartDialog.showToast('删除成功,请刷新'); SmartDialog.showToast('删除成功');
// Get.back(); // Get.back();
if (onDelete != null) {
onDelete!(item.rpid!);
}
} else { } else {
SmartDialog.showToast('删除失败, ${result["msg"]}'); SmartDialog.showToast('删除失败, ${result["msg"]}');
} }

View File

@@ -127,7 +127,7 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
_videoReplyReplyController.replyList.add(replyItem); _videoReplyReplyController.replyList.add(replyItem);
}, },
replyType: widget.replyType, replyType: widget.replyType,
replyReply: (replyItem) => replyReply(replyItem), replyReply: replyReply,
needDivider: false, needDivider: false,
onReply: () { onReply: () {
_onReply(widget.firstFloor); _onReply(widget.firstFloor);
@@ -164,8 +164,8 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
.add(replyItem); .add(replyItem);
}, },
replyType: widget.replyType, replyType: widget.replyType,
replyReply: (replyItem) => replyReply: replyReply,
replyReply(replyItem), needDivider: false,
onReply: () { onReply: () {
_onReply(_videoReplyReplyController.root); _onReply(_videoReplyReplyController.root);
}, },
@@ -227,6 +227,15 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
_onReply(_videoReplyReplyController _onReply(_videoReplyReplyController
.replyList[index]); .replyList[index]);
}, },
onDelete: (rpid, frpid) {
_videoReplyReplyController
.replyList.value =
_videoReplyReplyController
.replyList
.where((item) =>
item.rpid != rpid)
.toList();
},
); );
} }
}, },