import { Flex, Heading, HStack, Link, LoadingState, MetaTag, MetaTile, MetaTileBody, MetaTileHeader, Text, VStack, Wrap, WrapItem, } from '@metafam/ds'; import type { Maybe } from '@metafam/utils'; import React, { useCallback, useEffect, useState } from 'react'; import { PatronRank } from '#components/Patron/PatronRank'; import { PlayerContacts } from '#components/Player/PlayerContacts'; import { PlayerProfilePicture } from '#components/Player/PlayerProfilePicture'; import { SkillsTags } from '#components/Quest/Skills'; import type { Player, Skill } from '#graphql/autogen/hasura-sdk'; import { getAllMemberships, GuildMembership } from '#graphql/getMemberships'; import type { Patron } from '#graphql/types'; import { usePlayerName } from '#lib/hooks/player/usePlayerName'; import { usePlayerURL } from '#lib/hooks/player/usePlayerURL'; import { getPlayerDescription } from '#utils/playerHelpers'; import { PlayerRank } from './PlayerRank'; import { DAOMembershipSmall } from './Section/PlayerLinks/PlayerMemberships'; type Props = { player: Player; isPatron?: boolean; pSeedPrice?: Maybe; showSeasonalXP?: boolean; index?: number; }; export const PlayerTile: React.FC = ({ player, isPatron = false, pSeedPrice, showSeasonalXP, index, }) => { const description = getPlayerDescription(player); const [memberships, setMemberships] = useState([]); // default player name and url const linkURL = usePlayerURL(player); const playerName = usePlayerName(player); const [loading, setLoading] = useState(true); const daosRef = React.useRef(null); const [limit, setLimit] = useState(12); useEffect(() => { getAllMemberships(player).then(({ all }) => { setLoading(false); setMemberships(all); }); }, [player]); const handleResize = useCallback(() => { const width = daosRef.current?.scrollWidth; setLimit(Math.max(8, Math.floor((width ?? 22) / 22))); }, []); useEffect(() => { const elem = daosRef.current; elem?.addEventListener('resize', handleResize); return () => elem?.removeEventListener('resize', handleResize); }, [handleResize]); return ( {isPatron && typeof index === 'number' && pSeedPrice ? ( ) : ( )} {playerName} {description && ( About {description} )} {!!player.skills?.length && ( Skills s) as Skill[]} /> )} {!!memberships.length && ( <> Member of {loading ? ( ) : ( {memberships .slice( 0, memberships.length > limit ? limit - 1 : limit, ) .map((membership) => ( ))} {memberships.length > limit && ( {`+${memberships.length - limit + 1}`} )} )} )} {!!player.accounts?.length && ( Contact )} ); };