Skip to content

Commit

Permalink
Recover post if it failed to send.
Browse files Browse the repository at this point in the history
  • Loading branch information
SupertigerDev committed Dec 23, 2024
1 parent d1bddf3 commit aae3100
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
10 changes: 7 additions & 3 deletions src/chat-api/store/usePosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export function usePosts() {
...this.commentIds!,
]);
});
return true;
},
cachedComments() {
return this.commentIds?.map((postId) => state.posts[postId] as Post);
Expand Down Expand Up @@ -247,9 +248,12 @@ export function usePosts() {
alert(err.message);
});
if (!post) return;
pushPost(post, account.user()?.id!);
setState("feedPostIds", [post.id, ...state.feedPostIds]);
setState("discoverPostIds", [post.id, ...state.discoverPostIds]);
batch(() => {
pushPost(post, account.user()?.id!);
setState("feedPostIds", [post.id, ...state.feedPostIds]);
setState("discoverPostIds", [post.id, ...state.discoverPostIds]);
});
return true;
};

const fetchUserPosts = async (userId: string, withReplies?: boolean) => {
Expand Down
32 changes: 23 additions & 9 deletions src/components/PostsArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,32 @@ function NewPostArea(props: {
};

const onCreateClick = () => {
const tempContent = content();
const formattedContent = formatMessage(content().trim());
if (props.postId) {
posts.cachedPost(props.postId)?.submitReply({
content: formattedContent,
attachment: attachedFile(),
});
posts
.cachedPost(props.postId)
?.submitReply({
content: formattedContent,
attachment: attachedFile(),
})
.then((res) => {
if (!res) {
setContent(tempContent);
}
});
} else {
posts.submitPost({
content: formattedContent,
file: attachedFile(),
poll: showPollOptions() ? { choices: pollOptions } : undefined,
});
posts
.submitPost({
content: formattedContent,
file: attachedFile(),
poll: showPollOptions() ? { choices: pollOptions } : undefined,
})
.then((res) => {
if (!res) {
setContent(tempContent);
}
});
}
setContent("");
setPollOptions(reconcile([""]));
Expand Down

0 comments on commit aae3100

Please sign in to comment.