fix: disable follow button if no follow list available

This commit is contained in:
Alejandro Gomez 2023-07-25 16:38:57 +02:00
parent 192f5cb600
commit 9e437c6425
No known key found for this signature in database
GPG Key ID: 4DF39E566658C817
2 changed files with 4 additions and 3 deletions

View File

@ -12,7 +12,8 @@ export function LoggedInFollowButton({
pubkey: string;
}) {
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 isFollowing = follows.find((t) => t.at(1) === pubkey);
@ -52,6 +53,7 @@ export function LoggedInFollowButton({
return (
<AsyncButton
disabled={!following}
type="button"
className="btn btn-primary"
onClick={isFollowing ? unfollow : follow}

View File

@ -22,6 +22,5 @@ export default function useFollows(pubkey: string, leaveOpen = false) {
);
const relays = JSON.parse(data?.content ?? "{}");
return { tags: data?.tags ?? [], relays };
return data ? { tags: data.tags, relays } : null
}