From 43e3404dbbf8210f6014309a1fdafe03ede056ac Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 15 Feb 2025 18:43:06 +0800 Subject: [PATCH] :sparkles: Delete publisher --- api/Wallet/Create Transaction.bru | 4 +- assets/translations/en-US.json | 4 +- assets/translations/zh-CN.json | 4 +- .../account/publishers/publishers.dart | 39 +++++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/api/Wallet/Create Transaction.bru b/api/Wallet/Create Transaction.bru index 8a82ee9..d8bef2d 100644 --- a/api/Wallet/Create Transaction.bru +++ b/api/Wallet/Create Transaction.bru @@ -15,7 +15,7 @@ body:json { "client_id": "alphabot", "client_secret": "_uR0sVnHTh", "remark": "新年红包", - "amount": 9705, - "payee_id": 2 + "amount": 150, + "payee_id": 18 } } diff --git a/assets/translations/en-US.json b/assets/translations/en-US.json index d6a4b29..31eac46 100644 --- a/assets/translations/en-US.json +++ b/assets/translations/en-US.json @@ -638,5 +638,7 @@ "pollVotes": { "one": "{} vote", "other": "{} votes" - } + }, + "publisherDelete": "Delete Publisher {}", + "publisherDeleteDescription": "Are you sure you want to delete this publisher? This operation is irreversible." } diff --git a/assets/translations/zh-CN.json b/assets/translations/zh-CN.json index c0a6619..2be0a9a 100644 --- a/assets/translations/zh-CN.json +++ b/assets/translations/zh-CN.json @@ -637,5 +637,7 @@ "pollVotes": { "one": "{} 票", "other": "{} 票" - } + }, + "publisherDelete": "删除发布者 {}", + "publisherDeleteDescription": "你确定要删除这个发布者吗?该操作不可撤销。" } diff --git a/lib/screens/account/publishers/publishers.dart b/lib/screens/account/publishers/publishers.dart index 14720bf..d9d2c6a 100644 --- a/lib/screens/account/publishers/publishers.dart +++ b/lib/screens/account/publishers/publishers.dart @@ -45,6 +45,33 @@ class _PublisherScreenState extends State { } } + Future _deletePublisher(SnPublisher publisher) async { + final confirm = await context.showConfirmDialog( + 'publisherDelete'.tr(args: ['#${publisher.name}']), + 'publisherDeleteDescription'.tr(), + ); + if (!confirm) return; + + if (!mounted) return; + setState(() => _isBusy = true); + + try { + await context + .read() + .client + .delete('/cgi/co/publishers/${publisher.name}'); + if (!mounted) return; + context.showSnackbar('publisherDeleted'.tr(args: ['#${publisher.name}'])); + _publishers.remove(publisher); + _fetchPublishers(); + } catch (err) { + if (!mounted) return; + context.showErrorDialog(err); + } finally { + setState(() => _isBusy = false); + } + } + @override void initState() { super.initState(); @@ -118,6 +145,18 @@ class _PublisherScreenState extends State { }); }, ), + PopupMenuItem( + child: Row( + children: [ + const Icon(Symbols.delete), + const Gap(16), + Text('delete').tr(), + ], + ), + onTap: () { + _deletePublisher(publisher); + }, + ), ], ), );