2023-02-09 11:24:15 +00:00
|
|
|
import { ReactNode } from "react";
|
2023-02-08 21:10:26 +00:00
|
|
|
import { FormattedMessage } from "react-intl";
|
2023-05-10 10:41:38 +00:00
|
|
|
import { HexKey } from "@snort/nostr";
|
2023-02-08 21:10:26 +00:00
|
|
|
|
2023-01-20 11:11:50 +00:00
|
|
|
import useEventPublisher from "Feed/EventPublisher";
|
|
|
|
import ProfilePreview from "Element/ProfilePreview";
|
2023-05-10 10:41:38 +00:00
|
|
|
import useLogin from "Hooks/useLogin";
|
2023-01-10 12:05:36 +00:00
|
|
|
|
2023-02-08 21:10:26 +00:00
|
|
|
import messages from "./messages";
|
|
|
|
|
2023-01-16 17:48:25 +00:00
|
|
|
export interface FollowListBaseProps {
|
2023-02-07 20:04:50 +00:00
|
|
|
pubkeys: HexKey[];
|
2023-02-09 11:24:15 +00:00
|
|
|
title?: ReactNode | string;
|
2023-02-25 21:27:01 +00:00
|
|
|
showFollowAll?: boolean;
|
|
|
|
showAbout?: boolean;
|
2023-01-16 17:48:25 +00:00
|
|
|
}
|
2023-02-25 21:27:01 +00:00
|
|
|
export default function FollowListBase({ pubkeys, title, showFollowAll, showAbout }: FollowListBaseProps) {
|
2023-02-07 20:04:50 +00:00
|
|
|
const publisher = useEventPublisher();
|
2023-04-14 15:02:15 +00:00
|
|
|
const { follows, relays } = useLogin();
|
2023-01-10 12:05:36 +00:00
|
|
|
|
2023-02-07 20:04:50 +00:00
|
|
|
async function followAll() {
|
2023-04-14 15:02:15 +00:00
|
|
|
if (publisher) {
|
|
|
|
const ev = await publisher.contactList([...pubkeys, ...follows.item], relays.item);
|
|
|
|
publisher.broadcast(ev);
|
|
|
|
}
|
2023-02-07 20:04:50 +00:00
|
|
|
}
|
2023-01-10 12:05:36 +00:00
|
|
|
|
2023-02-07 20:04:50 +00:00
|
|
|
return (
|
2023-05-10 10:41:38 +00:00
|
|
|
<>
|
2023-02-25 21:27:01 +00:00
|
|
|
{(showFollowAll ?? true) && (
|
|
|
|
<div className="flex mt10 mb10">
|
|
|
|
<div className="f-grow bold">{title}</div>
|
|
|
|
<button className="transparent" type="button" onClick={() => followAll()}>
|
|
|
|
<FormattedMessage {...messages.FollowAll} />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-02-09 12:26:54 +00:00
|
|
|
{pubkeys?.map(a => (
|
2023-02-25 21:27:01 +00:00
|
|
|
<ProfilePreview pubkey={a} key={a} options={{ about: showAbout }} />
|
2023-02-07 20:04:50 +00:00
|
|
|
))}
|
2023-05-10 10:41:38 +00:00
|
|
|
</>
|
2023-02-07 20:04:50 +00:00
|
|
|
);
|
2023-01-25 18:08:53 +00:00
|
|
|
}
|