Adds follows you on profile

This commit is contained in:
Ivan 2023-01-17 21:26:42 -06:00
parent b22c194202
commit 1309c66789
No known key found for this signature in database
GPG Key ID: 600CE24100F54574
4 changed files with 47 additions and 6 deletions

View File

@ -1,8 +1,8 @@
import { useMemo } from "react";
import useFollowsFeed from "../feed/FollowsFeed";
import { HexKey } from "../nostr";
import EventKind from "../nostr/EventKind";
import FollowListBase from "./FollowListBase";
import { getFollowers} from "../feed/FollowsFeed";
export interface FollowsListProps {
pubkey: HexKey
@ -12,9 +12,7 @@ export default function FollowsList({ pubkey }: FollowsListProps) {
const feed = useFollowsFeed(pubkey);
const pubkeys = useMemo(() => {
let contactLists = feed?.notes.filter(a => a.kind === EventKind.ContactList && a.pubkey === pubkey);
let pTags = contactLists?.map(a => a.tags.filter(b => b[0] === "p").map(c => c[1]));
return [...new Set(pTags?.flat())];
return getFollowers(feed, pubkey);
}, [feed]);
return <FollowListBase pubkeys={pubkeys} title={`Following ${pubkeys?.length}`} />

View File

@ -0,0 +1,27 @@
import { useMemo } from "react";
import { useSelector } from "react-redux";
import { HexKey } from "../nostr";
import { RootState } from "../state/Store";
import useFollowsFeed from "../feed/FollowsFeed";
import { getFollowers } from "../feed/FollowsFeed";
export interface FollowsYouProps {
pubkey: HexKey
}
export default function FollowsYou({ pubkey }: FollowsYouProps ) {
const feed = useFollowsFeed(pubkey);
const loginPubKey = useSelector<RootState, HexKey | undefined>(s => s.login.publicKey);
const pubkeys = useMemo(() => {
return getFollowers(feed, pubkey);
}, [feed]);
const followsMe = pubkeys.includes(loginPubKey!) ?? false ;
return (
<>
{ followsMe ? <div className="copy"><span className="body">follows you</span></div> : null }
</>
)
}

View File

@ -1,8 +1,9 @@
import { useMemo } from "react";
import { HexKey } from "../nostr";
import EventKind from "../nostr/EventKind";
import { Subscriptions } from "../nostr/Subscriptions";
import { Subscriptions} from "../nostr/Subscriptions";
import useSubscription from "./Subscription";
import { NoteStore } from "./Subscription"
export default function useFollowsFeed(pubkey: HexKey) {
const sub = useMemo(() => {
@ -15,4 +16,10 @@ export default function useFollowsFeed(pubkey: HexKey) {
}, [pubkey]);
return useSubscription(sub);
}
}
export function getFollowers(feed: NoteStore, pubkey: HexKey) {
let contactLists = feed?.notes.filter(a => a.kind === EventKind.ContactList && a.pubkey === pubkey);
let pTags = contactLists?.map(a => a.tags.filter(b => b[0] === "p").map(c => c[1]));
return [...new Set(pTags?.flat())];
}

View File

@ -20,6 +20,7 @@ import FollowersList from "../element/FollowersList";
import FollowsList from "../element/FollowsList";
import { RootState } from "../state/Store";
import { HexKey } from "../nostr";
import FollowsYou from "../element/FollowsYou"
enum ProfileTab {
Notes = "Notes",
@ -50,6 +51,14 @@ export default function ProfilePage() {
<h2>{user?.display_name || user?.name || 'Nostrich'}</h2>
<Copy text={params.id || ""} />
{user?.nip05 && <Nip05 nip05={user.nip05} pubkey={user.pubkey} />}
{ followsYou() }
</div>
)
}
function followsYou(){
return (
<div className="flex">
<div className="f-grow">{ <FollowsYou pubkey={id}/> }</div>
</div>
)
}