sort users in following tab by WOT

This commit is contained in:
hzrd149
2024-04-20 09:06:40 -05:00
parent d618028a4a
commit 260e2433b1
2 changed files with 7 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
import { memo } from "react";
import { Flex, FlexProps } from "@chakra-ui/react"; import { Flex, FlexProps } from "@chakra-ui/react";
import UserDnsIdentity from "../../../components/user/user-dns-identity"; import UserDnsIdentity from "../../../components/user/user-dns-identity";
@@ -7,7 +8,7 @@ import UserAvatarLink from "../../../components/user/user-avatar-link";
export type UserCardProps = { pubkey: string; relay?: string } & Omit<FlexProps, "children">; export type UserCardProps = { pubkey: string; relay?: string } & Omit<FlexProps, "children">;
export const UserCard = ({ pubkey, relay, ...props }: UserCardProps) => { export const UserCard = memo(({ pubkey, relay, ...props }: UserCardProps) => {
return ( return (
<Flex <Flex
borderWidth="1px" borderWidth="1px"
@@ -29,4 +30,4 @@ export const UserCard = ({ pubkey, relay, ...props }: UserCardProps) => {
<UserFollowButton pubkey={pubkey} size="sm" variant="outline" flexShrink={0} /> <UserFollowButton pubkey={pubkey} size="sm" variant="outline" flexShrink={0} />
</Flex> </Flex>
); );
}; });

View File

@@ -5,19 +5,22 @@ import { UserCard } from "./components/user-card";
import { useAdditionalRelayContext } from "../../providers/local/additional-relay-context"; import { useAdditionalRelayContext } from "../../providers/local/additional-relay-context";
import useUserContactList from "../../hooks/use-user-contact-list"; import useUserContactList from "../../hooks/use-user-contact-list";
import { getPubkeysFromList } from "../../helpers/nostr/lists"; import { getPubkeysFromList } from "../../helpers/nostr/lists";
import { getWebOfTrust } from "../../services/web-of-trust";
export default function UserFollowingTab() { export default function UserFollowingTab() {
const { pubkey } = useOutletContext() as { pubkey: string }; const { pubkey } = useOutletContext() as { pubkey: string };
const contextRelays = useAdditionalRelayContext(); const contextRelays = useAdditionalRelayContext();
const contactsList = useUserContactList(pubkey, contextRelays, { alwaysRequest: true }); const contactsList = useUserContactList(pubkey, contextRelays, { alwaysRequest: true });
const people = contactsList ? getPubkeysFromList(contactsList) : []; const people = contactsList ? getPubkeysFromList(contactsList) : [];
const sorted = getWebOfTrust().sortByDistanceAndConnections(people, (p) => p.pubkey);
if (!contactsList) return <Spinner />; if (!contactsList) return <Spinner />;
return ( return (
<SimpleGrid columns={{ base: 1, lg: 2, xl: 3 }} spacing="2" p="2"> <SimpleGrid columns={{ base: 1, lg: 2, xl: 3 }} spacing="2" p="2">
{people.map(({ pubkey, relay }) => ( {sorted.map(({ pubkey, relay }) => (
<UserCard key={pubkey} pubkey={pubkey} relay={relay} /> <UserCard key={pubkey} pubkey={pubkey} relay={relay} />
))} ))}
</SimpleGrid> </SimpleGrid>