snort/packages/app/src/Pages/Profile/ProfileTab.tsx

151 lines
3.8 KiB
TypeScript
Raw Normal View History

2023-11-15 11:24:11 +00:00
import { HexKey, NostrLink, NostrPrefix } from "@snort/system";
2024-01-04 17:01:18 +00:00
import { FormattedMessage } from "react-intl";
2024-01-04 17:01:18 +00:00
import { default as ZapElement } from "@/Components/Event/Zap";
import Icon from "@/Components/Icons/Icon";
import RelaysMetadata from "@/Components/Relay/RelaysMetadata";
import { Tab } from "@/Components/Tabs/Tabs";
import Bookmarks from "@/Components/User/Bookmarks";
import FollowsList from "@/Components/User/FollowListBase";
2024-01-04 17:01:18 +00:00
import useFollowersFeed from "@/Feed/FollowersFeed";
2023-11-17 11:52:10 +00:00
import useFollowsFeed from "@/Feed/FollowsFeed";
import useRelaysFeed from "@/Feed/RelaysFeed";
2024-01-04 17:01:18 +00:00
import useZapsFeed from "@/Feed/ZapsFeed";
2023-11-22 15:34:46 +00:00
import { useBookmarkList } from "@/Hooks/useLists";
2024-01-04 17:01:18 +00:00
import { formatShort } from "@/Utils/Number";
2023-10-06 10:13:49 +00:00
import messages from "../messages";
2023-10-06 10:13:49 +00:00
export enum ProfileTabType {
NOTES = 0,
REACTIONS = 1,
FOLLOWERS = 2,
FOLLOWS = 3,
ZAPS = 4,
MUTED = 5,
BLOCKED = 6,
RELAYS = 7,
BOOKMARKS = 8,
}
export function ZapsProfileTab({ id }: { id: HexKey }) {
const zaps = useZapsFeed(new NostrLink(NostrPrefix.PublicKey, id));
const zapsTotal = zaps.reduce((acc, z) => acc + z.amount, 0);
return (
2023-10-31 15:40:12 +00:00
<>
2023-10-06 10:13:49 +00:00
<h2 className="p">
<FormattedMessage {...messages.Sats} values={{ n: formatShort(zapsTotal) }} />
</h2>
{zaps.map(z => (
2024-01-04 10:43:45 +00:00
<ZapElement key={z.id} showZapped={false} zap={z} />
2023-10-06 10:13:49 +00:00
))}
2023-10-31 15:40:12 +00:00
</>
2023-10-06 10:13:49 +00:00
);
}
export function FollowersTab({ id }: { id: HexKey }) {
const followers = useFollowersFeed(id);
return <FollowsList pubkeys={followers} showAbout={true} className="p" />;
}
export function FollowsTab({ id }: { id: HexKey }) {
const follows = useFollowsFeed(id);
return <FollowsList pubkeys={follows} showAbout={true} className="p" />;
}
export function RelaysTab({ id }: { id: HexKey }) {
const relays = useRelaysFeed(id);
return <RelaysMetadata relays={relays} />;
}
export function BookMarksTab({ id }: { id: HexKey }) {
2023-11-22 15:34:46 +00:00
const bookmarks = useBookmarkList(id);
2024-01-08 09:24:14 +00:00
return <Bookmarks pubkey={id} bookmarks={bookmarks} />;
2023-10-06 10:13:49 +00:00
}
const ProfileTab = {
Notes: {
text: (
<>
<Icon name="pencil" size={16} />
<FormattedMessage defaultMessage="Notes" id="7+Domh" />
</>
),
value: ProfileTabType.NOTES,
},
Reactions: {
text: (
<>
<Icon name="reaction" size={16} />
<FormattedMessage defaultMessage="Reactions" id="XgWvGA" />
</>
),
value: ProfileTabType.REACTIONS,
},
Followers: {
text: (
<>
<Icon name="user-v2" size={16} />
<FormattedMessage defaultMessage="Followers" id="pzTOmv" />
</>
),
value: ProfileTabType.FOLLOWERS,
},
Follows: {
text: (
<>
<Icon name="stars" size={16} />
<FormattedMessage defaultMessage="Follows" id="IKKHqV" />
</>
),
value: ProfileTabType.FOLLOWS,
},
Zaps: {
text: (
<>
<Icon name="zap-solid" size={16} />
<FormattedMessage defaultMessage="Zaps" id="OEW7yJ" />
</>
),
value: ProfileTabType.ZAPS,
},
Muted: {
text: (
<>
<Icon name="mute" size={16} />
<FormattedMessage defaultMessage="Muted" id="HOzFdo" />
</>
),
value: ProfileTabType.MUTED,
},
Blocked: {
text: (
<>
<Icon name="block" size={16} />
<FormattedMessage defaultMessage="Blocked" id="qUJTsT" />
</>
),
value: ProfileTabType.BLOCKED,
},
Relays: {
text: (
<>
<Icon name="wifi" size={16} />
<FormattedMessage defaultMessage="Relays" id="RoOyAh" />
</>
),
value: ProfileTabType.RELAYS,
},
Bookmarks: {
text: (
<>
<Icon name="bookmark-solid" size={16} />
<FormattedMessage defaultMessage="Bookmarks" id="nGBrvw" />
</>
),
value: ProfileTabType.BOOKMARKS,
},
} as { [key: string]: Tab };
2023-10-06 10:13:49 +00:00
export default ProfileTab;