auto add to created fav/follow

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-04-27 19:06:26 +08:00
parent fa05f2678f
commit bf1a906e2d
4 changed files with 81 additions and 75 deletions

View File

@@ -18,9 +18,11 @@ class MemberTagItemModel {
tip = json['tip']; tip = json['tip'];
} }
MemberTagItemModel.fromCreate(({int tagid, String tagName}) res) { MemberTagItemModel.fromCreate(
({int tagid, String tagName}) res, {
this.count = 0,
}) {
tagid = res.tagid; tagid = res.tagid;
name = res.tagName; name = res.tagName;
count = 0;
} }
} }

View File

@@ -90,8 +90,10 @@ class _CreateFavPageState extends State<CreateFavPage> {
intro: _introController.text, intro: _introController.text,
).then((res) { ).then((res) {
if (res case Success(:final response)) { if (res case Success(:final response)) {
Get.back(result: response);
SmartDialog.showToast('${_mediaId != null ? '编辑' : '创建'}成功'); SmartDialog.showToast('${_mediaId != null ? '编辑' : '创建'}成功');
if (mounted) {
Get.back(result: response);
}
} else { } else {
res.toast(); res.toast();
} }

View File

@@ -27,10 +27,10 @@ class _FavPanelState extends State<FavPanel> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_query(); _queryVideoInFolder();
} }
Future<void> _query() async { Future<void> _queryVideoInFolder() async {
final res = await widget.ctr.queryVideoInFolder(); final res = await widget.ctr.queryVideoInFolder();
if (mounted) { if (mounted) {
loadingState = res; loadingState = res;
@@ -39,58 +39,60 @@ class _FavPanelState extends State<FavPanel> {
} }
Widget get _buildBody { Widget get _buildBody {
late final list = widget.ctr.favFolderData.value.list!; switch (loadingState) {
return switch (loadingState) { case Loading():
Loading() => m3eLoading, return m3eLoading;
Success() => ListView.builder( case Success():
controller: widget.scrollController, final list = widget.ctr.favFolderData.value.list!;
itemCount: list.length, return ListView.builder(
itemBuilder: (context, index) { controller: widget.scrollController,
FavFolderInfo item = list[index]; itemCount: list.length,
return Material( itemBuilder: (context, index) {
type: MaterialType.transparency, FavFolderInfo item = list[index];
child: Builder( return Material(
builder: (context) { type: .transparency,
void onTap() { child: Builder(
bool isChecked = item.favState == 1; builder: (context) {
item final isChecked = item.favState == 1;
..favState = isChecked ? 0 : 1
..mediaCount = isChecked
? item.mediaCount - 1
: item.mediaCount + 1;
(context as Element).markNeedsBuild();
}
return ListTile( void onTap() {
onTap: onTap, item
dense: true, ..favState = isChecked ? 0 : 1
leading: FavUtils.isPublicFav(item.attr) ..mediaCount += isChecked ? -1 : 1;
? const Icon(Icons.folder_outlined) (context as Element).markNeedsBuild();
: const Icon(Icons.lock_outline), }
minLeadingWidth: 0,
title: Text(item.title), return ListTile(
subtitle: Text( onTap: onTap,
'${item.mediaCount}个内容 . ${FavUtils.isPublicFavText(item.attr)}', dense: true,
), leading: FavUtils.isPublicFav(item.attr)
trailing: Transform.scale( ? const Icon(Icons.folder_outlined)
scale: 0.9, : const Icon(Icons.lock_outline),
child: Checkbox( minLeadingWidth: 0,
value: item.favState == 1, title: Text(item.title),
onChanged: (bool? checkValue) => onTap(), subtitle: Text(
'${item.mediaCount}个内容 . ${FavUtils.isPublicFavText(item.attr)}',
), ),
), trailing: Transform.scale(
); scale: 0.9,
}, child: Checkbox(
), value: isChecked,
); onChanged: (bool? checkValue) => onTap(),
}, ),
), ),
Error(:final errMsg) => scrollErrorWidget( );
controller: widget.scrollController, },
errMsg: errMsg, ),
onReload: _query, );
), },
}; );
case Error(:final errMsg):
return scrollErrorWidget(
errMsg: errMsg,
controller: widget.scrollController,
onReload: _queryVideoInFolder,
);
}
} }
@override @override
@@ -109,23 +111,23 @@ class _FavPanelState extends State<FavPanel> {
actions: [ actions: [
TextButton.icon( TextButton.icon(
onPressed: () => Get.toNamed('/createFav')?.then((data) { onPressed: () => Get.toNamed('/createFav')?.then((data) {
if (data != null) { if (data is FavFolderInfo && mounted) {
widget.ctr.favFolderData widget.ctr.favFolderData.value.list?.insert(
..value.list?.insert(1, data) 1,
..refresh(); data
..favState = 1
..mediaCount = 1,
);
setState(() {});
} }
}), }),
icon: Icon( icon: Icon(Icons.add, color: theme.primary),
Icons.add,
color: theme.primary,
),
label: const Text('新建收藏夹'), label: const Text('新建收藏夹'),
style: TextButton.styleFrom( style: const ButtonStyle(
padding: const EdgeInsets.symmetric( visualDensity: .compact,
horizontal: 18, padding: WidgetStatePropertyAll(
vertical: 14, .symmetric(horizontal: 18, vertical: 14),
), ),
visualDensity: VisualDensity.compact,
), ),
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
@@ -137,7 +139,7 @@ class _FavPanelState extends State<FavPanel> {
color: theme.outline.withValues(alpha: 0.1), color: theme.outline.withValues(alpha: 0.1),
), ),
Padding( Padding(
padding: EdgeInsets.only( padding: .only(
left: 20, left: 20,
right: 20, right: 20,
top: 12, top: 12,
@@ -145,12 +147,12 @@ class _FavPanelState extends State<FavPanel> {
), ),
child: Row( child: Row(
spacing: 25, spacing: 25,
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: .end,
children: [ children: [
FilledButton.tonal( FilledButton.tonal(
onPressed: Get.back, onPressed: Get.back,
style: FilledButton.styleFrom( style: FilledButton.styleFrom(
visualDensity: VisualDensity.compact, visualDensity: .compact,
foregroundColor: theme.outline, foregroundColor: theme.outline,
backgroundColor: theme.onInverseSurface, backgroundColor: theme.onInverseSurface,
), ),
@@ -161,9 +163,7 @@ class _FavPanelState extends State<FavPanel> {
feedBack(); feedBack();
widget.ctr.actionFavVideo(); widget.ctr.actionFavVideo();
}, },
style: FilledButton.styleFrom( style: const ButtonStyle(visualDensity: .compact),
visualDensity: VisualDensity.compact,
),
child: const Text('完成'), child: const Text('完成'),
), ),
], ],

View File

@@ -176,7 +176,9 @@ class _GroupPanelState extends State<GroupPanel> {
void _onCreateFavTag(({int tagid, String tagName}) res) { void _onCreateFavTag(({int tagid, String tagName}) res) {
if (!mounted) return; if (!mounted) return;
if (loadingState case Success(:final response)) { if (loadingState case Success(:final response)) {
response.add(MemberTagItemModel.fromCreate(res)); response.add(MemberTagItemModel.fromCreate(res, count: 1));
tags.add(res.tagid);
showDefaultBtn.value = false;
setState(() {}); setState(() {});
} else { } else {
_queryFollowUpTags(); _queryFollowUpTags();