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 { useMemo } from "react";
|
||||||
import useFollowsFeed from "../feed/FollowsFeed";
|
import useFollowsFeed from "../feed/FollowsFeed";
|
||||||
import { HexKey } from "../nostr";
|
import { HexKey } from "../nostr";
|
||||||
import EventKind from "../nostr/EventKind";
|
|
||||||
import FollowListBase from "./FollowListBase";
|
import FollowListBase from "./FollowListBase";
|
||||||
|
import { getFollowers} from "../feed/FollowsFeed";
|
||||||
|
|
||||||
export interface FollowsListProps {
|
export interface FollowsListProps {
|
||||||
pubkey: HexKey
|
pubkey: HexKey
|
||||||
@ -12,9 +12,7 @@ export default function FollowsList({ pubkey }: FollowsListProps) {
|
|||||||
const feed = useFollowsFeed(pubkey);
|
const feed = useFollowsFeed(pubkey);
|
||||||
|
|
||||||
const pubkeys = useMemo(() => {
|
const pubkeys = useMemo(() => {
|
||||||
let contactLists = feed?.notes.filter(a => a.kind === EventKind.ContactList && a.pubkey === pubkey);
|
return getFollowers(feed, pubkey);
|
||||||
let pTags = contactLists?.map(a => a.tags.filter(b => b[0] === "p").map(c => c[1]));
|
|
||||||
return [...new Set(pTags?.flat())];
|
|
||||||
}, [feed]);
|
}, [feed]);
|
||||||
|
|
||||||
return <FollowListBase pubkeys={pubkeys} title={`Following ${pubkeys?.length}`} />
|
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 }
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
@ -3,6 +3,7 @@ import { HexKey } from "../nostr";
|
|||||||
import EventKind from "../nostr/EventKind";
|
import EventKind from "../nostr/EventKind";
|
||||||
import { Subscriptions} from "../nostr/Subscriptions";
|
import { Subscriptions} from "../nostr/Subscriptions";
|
||||||
import useSubscription from "./Subscription";
|
import useSubscription from "./Subscription";
|
||||||
|
import { NoteStore } from "./Subscription"
|
||||||
|
|
||||||
export default function useFollowsFeed(pubkey: HexKey) {
|
export default function useFollowsFeed(pubkey: HexKey) {
|
||||||
const sub = useMemo(() => {
|
const sub = useMemo(() => {
|
||||||
@ -16,3 +17,9 @@ export default function useFollowsFeed(pubkey: HexKey) {
|
|||||||
|
|
||||||
return useSubscription(sub);
|
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 FollowsList from "../element/FollowsList";
|
||||||
import { RootState } from "../state/Store";
|
import { RootState } from "../state/Store";
|
||||||
import { HexKey } from "../nostr";
|
import { HexKey } from "../nostr";
|
||||||
|
import FollowsYou from "../element/FollowsYou"
|
||||||
|
|
||||||
enum ProfileTab {
|
enum ProfileTab {
|
||||||
Notes = "Notes",
|
Notes = "Notes",
|
||||||
@ -50,6 +51,14 @@ export default function ProfilePage() {
|
|||||||
<h2>{user?.display_name || user?.name || 'Nostrich'}</h2>
|
<h2>{user?.display_name || user?.name || 'Nostrich'}</h2>
|
||||||
<Copy text={params.id || ""} />
|
<Copy text={params.id || ""} />
|
||||||
{user?.nip05 && <Nip05 nip05={user.nip05} pubkey={user.pubkey} />}
|
{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>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user