Handle follow errors
cgen-dcd5c23928014bf2956da27047be0be0
This commit is contained in:
parent
595bf558f7
commit
30e276b5a3
1 changed files with 19 additions and 7 deletions
|
|
@ -136,13 +136,25 @@ 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) {
|
||||||
if (isFollowingAuthor(targetId)) {
|
toast({ description: "Please sign in to manage follows." });
|
||||||
await aethexSocialService.unfollowUser(user.id, targetId);
|
return;
|
||||||
setFollowing((s) => s.filter((x) => x !== targetId));
|
}
|
||||||
} else {
|
|
||||||
await aethexSocialService.followUser(user.id, targetId);
|
try {
|
||||||
setFollowing((s) => Array.from(new Set([...s, targetId])));
|
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.",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue