Newer
Older
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { useFollow } from "./profile/hooks/use-follow"
import { Button } from "./ui/button"
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "./ui/dialog"
export const FollowButton = ({
userId,
username,
isFollowing = false,
}: {
userId: string
username: string
isFollowing?: boolean
}) => {
const followMutation = useFollow("follow")
const unfollowMutation = useFollow("unfollow")
return (
<Dialog>
{isFollowing ? (
<Button variant="outline" size="lg" >
<span className="hover:hidden">Following</span>
<DialogTrigger>
<span className="hidden hover:block text-destructive border-destructive">Unfollow</span>
</DialogTrigger>
</Button>
) : (
<Button variant="outline" size="lg" onClick={() => followMutation.mutate({ userId })}>
Follow
</Button>
)}
<DialogContent>
<DialogHeader>
<DialogTitle>Unfollow @{username}?</DialogTitle>
<DialogDescription>
Their Gweets will no longer show up in your home timeline.
You can still view their profile, unless their Tweets are protected.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button type="submit" onClick={() => unfollowMutation.mutate({ userId })}>
Unfollow
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}