add publish throttle

Closes #2152

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-05-19 21:51:47 +08:00
parent 89522e2059
commit 66f15f532f
7 changed files with 16 additions and 8 deletions

View File

@@ -37,6 +37,8 @@ abstract class CommonPublishPageState<T extends CommonPublishPage>
late final RxBool readOnly = false.obs; late final RxBool readOnly = false.obs;
late final RxBool enablePublish = false.obs; late final RxBool enablePublish = false.obs;
bool isPublishing = false;
bool hasPub = false; bool hasPub = false;
void initPubState(); void initPubState();
@@ -208,10 +210,16 @@ abstract class CommonPublishPageState<T extends CommonPublishPage>
void onSubmitted(String value) { void onSubmitted(String value) {
if (enablePublish.value) { if (enablePublish.value) {
onPublish(); onPublishThrottle();
} }
} }
void onPublishThrottle() {
if (isPublishing) return;
isPublishing = true;
onPublish().whenComplete(() => isPublishing = false);
}
Future<void> onPublish(); Future<void> onPublish();
Future<void> onCustomPublish({List? pictures}); Future<void> onCustomPublish({List? pictures});

View File

@@ -550,6 +550,6 @@ abstract class CommonRichTextPubPageState<T extends CommonRichTextPubPage>
return; return;
} }
} }
onCustomPublish(pictures: pictures); return onCustomPublish(pictures: pictures);
} }
} }

View File

@@ -361,7 +361,7 @@ class _CreateDynPanelState extends CommonRichTextPubPageState<CreateDynPanel> {
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: Obx( child: Obx(
() => FilledButton.tonal( () => FilledButton.tonal(
onPressed: enablePublish.value ? onPublish : null, onPressed: enablePublish.value ? onPublishThrottle : null,
style: FilledButton.styleFrom( style: FilledButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap, tapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(

View File

@@ -267,7 +267,7 @@ class _RepostPanelState extends CommonRichTextPubPageState<RepostPanel> {
), ),
const Spacer(), const Spacer(),
TextButton( TextButton(
onPressed: onPublish, onPressed: onPublishThrottle,
style: TextButton.styleFrom( style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 20, horizontal: 20,
@@ -320,7 +320,7 @@ class _RepostPanelState extends CommonRichTextPubPageState<RepostPanel> {
Align( Align(
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: FilledButton.tonal( child: FilledButton.tonal(
onPressed: onPublish, onPressed: onPublishThrottle,
style: FilledButton.styleFrom( style: FilledButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap, tapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(

View File

@@ -135,7 +135,7 @@ class _ReplyPageState extends CommonRichTextPubPageState<LiveSendDmPanel> {
emojiBtn, emojiBtn,
Obx( Obx(
() => FilledButton.tonal( () => FilledButton.tonal(
onPressed: enablePublish.value ? onPublish : null, onPressed: enablePublish.value ? onPublishThrottle : null,
style: FilledButton.styleFrom( style: FilledButton.styleFrom(
visualDensity: .compact, visualDensity: .compact,
padding: const .symmetric(horizontal: 20, vertical: 10), padding: const .symmetric(horizontal: 20, vertical: 10),

View File

@@ -210,7 +210,7 @@ class _ReplyPageState extends CommonRichTextPubPageState<ReplyPage> {
const Spacer(), const Spacer(),
Obx( Obx(
() => FilledButton.tonal( () => FilledButton.tonal(
onPressed: enablePublish.value ? onPublish : null, onPressed: enablePublish.value ? onPublishThrottle : null,
style: FilledButton.styleFrom( style: FilledButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap, tapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(

View File

@@ -419,7 +419,7 @@ class _SendDanmakuPanelState extends CommonTextPubPageState<SendDanmakuPanel> {
iconColor: enablePublish.value iconColor: enablePublish.value
? themeData.colorScheme.primary ? themeData.colorScheme.primary
: themeData.colorScheme.outline, : themeData.colorScheme.outline,
onPressed: enablePublish.value ? onPublish : null, onPressed: enablePublish.value ? onPublishThrottle : null,
icon: const Icon(Icons.send), icon: const Icon(Icons.send),
), ),
), ),