fix(post): prevent duplicate submission and fix navigation after posting
All checks were successful
Frontend CI / ota-android (push) Successful in 13m26s
Frontend CI / build-android-apk (push) Successful in 54m22s
Frontend CI / build-and-push-web (push) Successful in 10m44s

- add guard clause to prevent duplicate clicks when posting is in progress
- replace navigation.goBack() with navigation.reset to Main screen for cleaner navigation stack after post creation, update, and voting post submission
This commit is contained in:
lafay
2026-03-18 21:09:55 +08:00
parent b11e6548d5
commit a9c514f664

View File

@@ -334,6 +334,9 @@ export const CreatePostScreen: React.FC<CreatePostScreenProps> = (props) => {
// 发布帖子 // 发布帖子
const handlePost = async () => { const handlePost = async () => {
// 防止重复点击
if (posting) return;
if (!content.trim()) { if (!content.trim()) {
Alert.alert('错误', '请输入帖子内容'); Alert.alert('错误', '请输入帖子内容');
return; return;
@@ -373,7 +376,10 @@ export const CreatePostScreen: React.FC<CreatePostScreenProps> = (props) => {
message: '投票帖已提交,内容审核中,稍后展示', message: '投票帖已提交,内容审核中,稍后展示',
duration: 2600, duration: 2600,
}); });
navigation.goBack(); navigation.reset({
index: 0,
routes: [{ name: 'Main' }],
});
} else { } else {
if (isEditMode && editPostID) { if (isEditMode && editPostID) {
const updated = await postService.updatePost(editPostID, { const updated = await postService.updatePost(editPostID, {
@@ -390,7 +396,10 @@ export const CreatePostScreen: React.FC<CreatePostScreenProps> = (props) => {
message: '帖子内容已更新', message: '帖子内容已更新',
duration: 2200, duration: 2200,
}); });
navigation.goBack(); navigation.reset({
index: 0,
routes: [{ name: 'Main' }],
});
} else { } else {
// 创建普通帖子 // 创建普通帖子
await postService.createPost({ await postService.createPost({
@@ -404,7 +413,10 @@ export const CreatePostScreen: React.FC<CreatePostScreenProps> = (props) => {
message: '帖子已提交,内容审核中,稍后展示', message: '帖子已提交,内容审核中,稍后展示',
duration: 2600, duration: 2600,
}); });
navigation.goBack(); navigation.reset({
index: 0,
routes: [{ name: 'Main' }],
});
} }
} }
} catch (error) { } catch (error) {