feat: set top dyn

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-04-16 08:01:21 +08:00
parent 2cc9324f08
commit 3638d65008
8 changed files with 75 additions and 1 deletions

View File

@@ -764,4 +764,6 @@ class Api {
static const String pgcTimeline = '/pgc/web/timeline';
static const String searchTrending = '/x/v2/search/trending/ranking';
static const String setTopDyn = '/x/dynamic/feed/space/set_top';
}

View File

@@ -118,4 +118,23 @@ class DynamicsHttp {
};
}
}
static Future setTop({
required dynamic dynamicId,
}) async {
var res = await Request().post(
Api.setTopDyn,
queryParameters: {
'csrf': await Request.getCsrf(),
},
data: {
'dyn_str': dynamicId,
},
);
if (res.data['code'] == 0) {
return {'status': true};
} else {
return {'status': false, 'msg': res.data['message']};
}
}
}

View File

@@ -64,6 +64,15 @@ class DynamicsTabController
}
}
Future onSetTop(bool isTop, dynamic dynamicId) async {
var res = await DynamicsHttp.setTop(dynamicId: dynamicId);
if (res['status']) {
SmartDialog.showToast('${isTop ? '取消' : ''}置顶成功');
} else {
SmartDialog.showToast(res['msg']);
}
}
@override
Future onReload() {
scrollController.jumpToTop();

View File

@@ -170,6 +170,7 @@ class _DynamicsTabPageState
DynamicPanel(
item: i,
onRemove: controller.onRemove,
// onSetTop: controller.onSetTop,
),
] else ...[
for (var i in loadingState.response!)
@@ -178,6 +179,7 @@ class _DynamicsTabPageState
DynamicPanel(
item: i,
onRemove: controller.onRemove,
// onSetTop: controller.onSetTop,
),
]
],
@@ -203,6 +205,7 @@ class _DynamicsTabPageState
return DynamicPanel(
item: item,
onRemove: controller.onRemove,
// onSetTop: controller.onSetTop,
);
}
return const SizedBox.shrink();

View File

@@ -25,6 +25,7 @@ class AuthorPanel extends StatelessWidget {
final String? source;
final Function? onRemove;
final bool isSave;
final Function(bool isTop, dynamic dynId)? onSetTop;
const AuthorPanel({
super.key,
@@ -33,6 +34,7 @@ class AuthorPanel extends StatelessWidget {
this.source,
this.onRemove,
this.isSave = false,
this.onSetTop,
});
Widget _buildAvatar(double size) => NetworkImgLayer(
@@ -354,6 +356,18 @@ class AuthorPanel extends StatelessWidget {
title:
Text('检查动态', style: Theme.of(context).textTheme.titleSmall!),
),
if (onSetTop != null)
ListTile(
onTap: () {
Get.back();
onSetTop!(item.modules?.moduleTag?.text != null, item.idStr);
},
minLeadingWidth: 0,
leading: const Icon(Icons.vertical_align_top, size: 19),
title: Text(
'${item.modules?.moduleTag?.text != null ? '取消' : ''}置顶',
style: Theme.of(context).textTheme.titleSmall!),
),
if (onRemove != null)
ListTile(
onTap: () {

View File

@@ -15,14 +15,16 @@ class DynamicPanel extends StatelessWidget {
final Function? onRemove;
final Function(List<String>, int)? callback;
final bool isSave;
final Function(bool isTop, dynamic dynId)? onSetTop;
const DynamicPanel({
super.key,
required this.item,
this.source,
this.onRemove,
this.callback,
this.isSave = false,
super.key,
this.onSetTop,
});
@override
@@ -134,6 +136,7 @@ class DynamicPanel extends StatelessWidget {
source: source,
onRemove: onRemove,
isSave: isSave,
onSetTop: onSetTop,
),
),
if (item!.modules!.moduleDynamic!.desc != null ||

View File

@@ -1,3 +1,4 @@
import 'package:PiliPlus/http/dynamics.dart';
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/http/msg.dart';
import 'package:PiliPlus/pages/common/common_list_controller.dart';
@@ -66,4 +67,25 @@ class MemberDynamicsController
SmartDialog.showToast(res['msg']);
}
}
Future onSetTop(bool isTop, dynamic dynamicId) async {
var res = await DynamicsHttp.setTop(dynamicId: dynamicId);
if (res['status']) {
List<DynamicItemModel> list = (loadingState.value as Success).response;
list[0].modules?.moduleTag = null;
if (isTop) {
loadingState.refresh();
SmartDialog.showToast('取消置顶成功');
} else {
final item = list.firstWhere((item) => item.idStr == dynamicId);
item.modules?.moduleTag = ModuleTag(text: '置顶');
list.remove(item);
list.insert(0, item);
loadingState.refresh();
SmartDialog.showToast('置顶成功');
}
} else {
SmartDialog.showToast(res['msg']);
}
}
}

View File

@@ -130,6 +130,7 @@ class _MemberDynamicsPageState extends State<MemberDynamicsPage>
(item) => DynamicPanel(
item: item,
onRemove: _memberDynamicController.onRemove,
onSetTop: _memberDynamicController.onSetTop,
),
)
.toList(),
@@ -149,6 +150,7 @@ class _MemberDynamicsPageState extends State<MemberDynamicsPage>
return DynamicPanel(
item: loadingState.response![index],
onRemove: _memberDynamicController.onRemove,
onSetTop: _memberDynamicController.onSetTop,
);
},
childCount: loadingState.response!.length,