Skip to content

Commit

Permalink
seperate round PFP into own component exchange useEffect & useState w…
Browse files Browse the repository at this point in the history
…ith useMemo
  • Loading branch information
Seroxdesign committed Jul 3, 2023
1 parent 2449c1f commit d444133
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/web/components/Landing/UserGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Link, Text } from '@metafam/ds';
import { PlayerProfilePicture } from 'components/Player/PlayerProfilePicture';
import { PlayerProfilePictureRound } from 'components/Player/PlayerProfilePictureRound';
import { RoundImage } from 'components/RoundImage';
import { GuildFragment, Player } from 'graphql/autogen/types';
import React from 'react';
Expand Down Expand Up @@ -55,7 +55,7 @@ export const UserGrid: React.FC<{
textAlign: 'center',
}}
>
<PlayerProfilePicture {...{ player }} round={true} size="xxs" />
<PlayerProfilePictureRound {...{ player }} size="xxs" />
<Text sx={{ fontSize: 'xs' }} noOfLines={1}>
{player.profile?.name || formatAddress(player.ethereumAddress)}
</Text>
Expand Down
11 changes: 3 additions & 8 deletions packages/web/components/Landing/WhoAreWe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
import BackgroundImageMobile from 'assets/landing/sections/section-5.sm.webp';
import BackgroundImageDesktop from 'assets/landing/sections/section-5.webp';
import { FullPageContainer } from 'components/Container';
import { GuildFragment, Player } from 'graphql/autogen/types';
import { GuildFragment } from 'graphql/autogen/types';
import { Patron } from 'graphql/types';
import { usePlayerFilter } from 'lib/hooks/player/players';
import { useMotionDetector } from 'lib/hooks/useMotionDetector';
import { useOnScreen } from 'lib/hooks/useOnScreen';
import React, { useEffect, useRef, useState } from 'react';
import React, { useMemo, useRef } from 'react';

import { LandingNextButton } from './LandingNextButton';
import { LandingPageSectionProps } from './landingSection';
Expand Down Expand Up @@ -79,13 +79,8 @@ export const WhoAreWe: React.FC<
});

const { players } = usePlayerFilter();
const [topPlayers, setTopPlayers] = useState<Player[]>();

useEffect(() => {
if (players.length) {
setTopPlayers(players.slice(0, 7));
}
}, [players]);
const topPlayers = useMemo(() => players.slice(0, 7), [players]);

return (
<FullPageContainer
Expand Down
6 changes: 1 addition & 5 deletions packages/web/components/Player/PlayerProfilePicture.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { AvatarProps } from '@metafam/ds';
import { RoundImage } from 'components/RoundImage';
import { SquareImage } from 'components/SquareImage';
import type { Player } from 'graphql/autogen/types';
import type { GuildPlayer } from 'graphql/types';
Expand All @@ -9,13 +8,11 @@ import { getPlayerImage } from 'utils/playerHelpers';

type PlayerProfilePictureProps = AvatarProps & {
player?: Player | GuildPlayer;
round?: boolean;
};

export const PlayerProfilePicture: React.FC<PlayerProfilePictureProps> = ({
player: user,
src: source,
round = false,
...props
}) => {
const player = user as Player;
Expand All @@ -29,8 +26,7 @@ export const PlayerProfilePicture: React.FC<PlayerProfilePictureProps> = ({

return (
<>
{round && <RoundImage {...{ src, ...props }} />}
{!round && <SquareImage {...{ src, ...props }} />}
<SquareImage {...{ src, ...props }} />
</>
);
};
32 changes: 32 additions & 0 deletions packages/web/components/Player/PlayerProfilePictureRound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { AvatarProps } from '@metafam/ds';
import { RoundImage } from 'components/RoundImage';
import type { Player } from 'graphql/autogen/types';
import type { GuildPlayer } from 'graphql/types';
import { useProfileField } from 'lib/hooks';
import React from 'react';
import { getPlayerImage } from 'utils/playerHelpers';

type PlayerProfilePictureProps = AvatarProps & {
player?: Player | GuildPlayer;
};

export const PlayerProfilePictureRound: React.FC<PlayerProfilePictureProps> = ({
player: user,
src: source,
...props
}) => {
const player = user as Player;
const { value: image } = useProfileField({
field: 'profileImageURL',
player,
getter: getPlayerImage,
});

const src = source ?? image ?? undefined;

return (
<>
<RoundImage {...{ src, ...props }} />
</>
);
};

0 comments on commit d444133

Please sign in to comment.