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,7 +136,12 @@ export default function Feed() {
const isFollowingAuthor = (id: string) => following.includes(id); const isFollowingAuthor = (id: string) => following.includes(id);
const toggleFollow = async (targetId: string) => { const toggleFollow = async (targetId: string) => {
if (!user) return; if (!user) {
toast({ description: "Please sign in to manage follows." });
return;
}
try {
if (isFollowingAuthor(targetId)) { if (isFollowingAuthor(targetId)) {
await aethexSocialService.unfollowUser(user.id, targetId); await aethexSocialService.unfollowUser(user.id, targetId);
setFollowing((s) => s.filter((x) => x !== targetId)); setFollowing((s) => s.filter((x) => x !== targetId));
@ -144,6 +149,13 @@ export default function Feed() {
await aethexSocialService.followUser(user.id, targetId); await aethexSocialService.followUser(user.id, targetId);
setFollowing((s) => Array.from(new Set([...s, 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.",
});
}
}; };
const share = async (id: string) => { const share = async (id: string) => {