fix: disable follow button if no follow list available
This commit is contained in:
@ -12,7 +12,8 @@ export function LoggedInFollowButton({
|
|||||||
pubkey: string;
|
pubkey: string;
|
||||||
}) {
|
}) {
|
||||||
const login = useLogin();
|
const login = useLogin();
|
||||||
const { tags, relays } = useFollows(loggedIn, true);
|
const following = useFollows(loggedIn, true);
|
||||||
|
const { tags, relays } = following ? following : { tags: [], relays: {} }
|
||||||
const follows = tags.filter((t) => t.at(0) === "p")
|
const follows = tags.filter((t) => t.at(0) === "p")
|
||||||
const isFollowing = follows.find((t) => t.at(1) === pubkey);
|
const isFollowing = follows.find((t) => t.at(1) === pubkey);
|
||||||
|
|
||||||
@ -52,6 +53,7 @@ export function LoggedInFollowButton({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<AsyncButton
|
<AsyncButton
|
||||||
|
disabled={!following}
|
||||||
type="button"
|
type="button"
|
||||||
className="btn btn-primary"
|
className="btn btn-primary"
|
||||||
onClick={isFollowing ? unfollow : follow}
|
onClick={isFollowing ? unfollow : follow}
|
||||||
|
@ -22,6 +22,5 @@ export default function useFollows(pubkey: string, leaveOpen = false) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const relays = JSON.parse(data?.content ?? "{}");
|
const relays = JSON.parse(data?.content ?? "{}");
|
||||||
|
return data ? { tags: data.tags, relays } : null
|
||||||
return { tags: data?.tags ?? [], relays };
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user