forked from Kieran/snort
Merge pull request #64 from ivanacostarubio/follows-you
feat: follows you on profile page
This commit is contained in:
commit
fa8166e9d5
@ -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}`} />
|
||||
|
27
src/element/FollowsYou.tsx
Normal file
27
src/element/FollowsYou.tsx
Normal 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 }
|
||||
</>
|
||||
)
|
||||
}
|
@ -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())];
|
||||
}
|
||||
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user