fix(post): prevent duplicate submission and fix navigation after posting
- 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:
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user