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 enablePublish = false.obs;
bool isPublishing = false;
bool hasPub = false;
void initPubState();
@@ -208,10 +210,16 @@ abstract class CommonPublishPageState<T extends CommonPublishPage>
void onSubmitted(String value) {
if (enablePublish.value) {
onPublish();
onPublishThrottle();
}
}
void onPublishThrottle() {
if (isPublishing) return;
isPublishing = true;
onPublish().whenComplete(() => isPublishing = false);
}
Future<void> onPublish();
Future<void> onCustomPublish({List? pictures});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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