Handle follow errors

cgen-dcd5c23928014bf2956da27047be0be0
This commit is contained in:
Builder.io 2025-09-30 23:10:15 +00:00
parent 595bf558f7
commit 30e276b5a3

View file

@ -136,13 +136,25 @@ export default function Feed() {
const isFollowingAuthor = (id: string) => following.includes(id);
const toggleFollow = async (targetId: string) => {
if (!user) return;
if (isFollowingAuthor(targetId)) {
await aethexSocialService.unfollowUser(user.id, targetId);
setFollowing((s) => s.filter((x) => x !== targetId));
} else {
await aethexSocialService.followUser(user.id, targetId);
setFollowing((s) => Array.from(new Set([...s, targetId])));
if (!user) {
toast({ description: "Please sign in to manage follows." });
return;
}
try {
if (isFollowingAuthor(targetId)) {
await aethexSocialService.unfollowUser(user.id, targetId);
setFollowing((s) => s.filter((x) => x !== targetId));
} else {
await aethexSocialService.followUser(user.id, targetId);
setFollowing((s) => Array.from(new Set([...s, targetId])));
}
} catch (error: any) {
toast({
variant: "destructive",
title: "Action failed",
description: error?.message || "Try again in a moment.",
});
}
};