adding follow button
This commit is contained in:
parent
8d42a957fc
commit
21d2c6fec8
44
app/(app)/(profile)/[npub]/_components/FollowButton.tsx
Normal file
44
app/(app)/(profile)/[npub]/_components/FollowButton.tsx
Normal file
@ -0,0 +1,44 @@
|
||||
"use client";
|
||||
import { useState } from "react";
|
||||
import { useNDK } from "@/app/_providers/ndk";
|
||||
import useCurrentUser from "@/lib/hooks/useCurrentUser";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { follow } from "@/lib/actions/create";
|
||||
import { toast } from "sonner";
|
||||
import { NDKUser } from "@nostr-dev-kit/ndk";
|
||||
|
||||
type FollowButtonProps = {
|
||||
pubkey: string;
|
||||
follows: Set<NDKUser>;
|
||||
};
|
||||
|
||||
export default function FollowButton({ pubkey, follows }: FollowButtonProps) {
|
||||
const { currentUser } = useCurrentUser();
|
||||
const { ndk } = useNDK();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function handleFollow() {
|
||||
if (!ndk || !currentUser) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
await follow(ndk, currentUser, pubkey);
|
||||
toast.success("Payment Sent!");
|
||||
} catch (err) {
|
||||
console.log("Error", err);
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
if (Array.from(follows).find((i) => i.pubkey === pubkey)) {
|
||||
return (
|
||||
<Button
|
||||
onClick={handleFollow}
|
||||
loading={loading}
|
||||
variant={"default"}
|
||||
className="rounded-sm px-5 max-sm:h-8 max-sm:text-xs"
|
||||
>
|
||||
Follow
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
@ -27,6 +27,9 @@ const CreateSubecriptionTierModal = dynamic(
|
||||
ssr: false,
|
||||
},
|
||||
);
|
||||
const FollowButton = dynamic(() => import("./_components/FollowButton"), {
|
||||
ssr: false,
|
||||
});
|
||||
|
||||
export default function ProfilePage({
|
||||
params: { npub },
|
||||
@ -104,22 +107,7 @@ export default function ProfilePage({
|
||||
Edit
|
||||
</Button>
|
||||
)}
|
||||
{currentUser &&
|
||||
!Array.from(follows).find((i) => i.pubkey === pubkey) && (
|
||||
<Button
|
||||
onClick={() =>
|
||||
void currentUser.follow(
|
||||
new NDKUser({
|
||||
hexpubkey: pubkey,
|
||||
}),
|
||||
)
|
||||
}
|
||||
variant={"default"}
|
||||
className="rounded-sm px-5 max-sm:h-8 max-sm:text-xs"
|
||||
>
|
||||
Follow
|
||||
</Button>
|
||||
)}
|
||||
{currentUser && <FollowButton pubkey={pubkey} follows={follows} />}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mx-auto max-w-[800px] space-y-1 px-4">
|
||||
|
Loading…
x
Reference in New Issue
Block a user