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,25 +39,26 @@ 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():
final list = widget.ctr.favFolderData.value.list!;
return ListView.builder(
controller: widget.scrollController, controller: widget.scrollController,
itemCount: list.length, itemCount: list.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
FavFolderInfo item = list[index]; FavFolderInfo item = list[index];
return Material( return Material(
type: MaterialType.transparency, type: .transparency,
child: Builder( child: Builder(
builder: (context) { builder: (context) {
final isChecked = item.favState == 1;
void onTap() { void onTap() {
bool isChecked = item.favState == 1;
item item
..favState = isChecked ? 0 : 1 ..favState = isChecked ? 0 : 1
..mediaCount = isChecked ..mediaCount += isChecked ? -1 : 1;
? item.mediaCount - 1
: item.mediaCount + 1;
(context as Element).markNeedsBuild(); (context as Element).markNeedsBuild();
} }
@@ -75,7 +76,7 @@ class _FavPanelState extends State<FavPanel> {
trailing: Transform.scale( trailing: Transform.scale(
scale: 0.9, scale: 0.9,
child: Checkbox( child: Checkbox(
value: item.favState == 1, value: isChecked,
onChanged: (bool? checkValue) => onTap(), onChanged: (bool? checkValue) => onTap(),
), ),
), ),
@@ -84,13 +85,14 @@ class _FavPanelState extends State<FavPanel> {
), ),
); );
}, },
), );
Error(:final errMsg) => scrollErrorWidget( case Error(:final errMsg):
controller: widget.scrollController, return scrollErrorWidget(
errMsg: errMsg, errMsg: errMsg,
onReload: _query, 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();