Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unnecessary Avatar renders which cause extra unnecessary alt text #949

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 110 additions & 101 deletions src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,14 @@ const LikeButton = ({
</Tooltip>
);

const Card = ({ mentor, onFavMentor, isFav, appearance }: CardProps) => {
const extended = appearance === 'extended';
const { setFilterParams } = useFilterParams();
const CardHeader = ({mentor, onFavMentor, isFav}) => {
const {country, mentorID} = mentor;
const { currentUser } = useUser();
const urls = useRoutes();
const {
name,
country,
description,
tags,
title,
_id: mentorID,
available: availability,
createdAt,
} = mentor;

const auth = useAuth();

const { setFilterParams } = useFilterParams();
const handleCountryClick = (country: Country) => {
setFilterParams('country', country);
};
const toggleFav = () => {
if (currentUser) {
isFav = !isFav;
Expand All @@ -171,45 +161,27 @@ const Card = ({ mentor, onFavMentor, isFav, appearance }: CardProps) => {
}
};

const handleTagClick = (tag: string) => {
setFilterParams('technology', tag);
};

const handleCountryClick = (country: Country) => {
setFilterParams('country', country);
};

const MentorDescription = () => {
return description ? (
<p className="description">{description}</p>
) : (
<React.Fragment />
);
};
const tooltip = currentUser
? undefined
: messages.CARD_ANONYMOUS_LIKE_TOOLTIP;
return (
<div className="header">
<button
className="country location"
onClick={() => handleCountryClick(country)}
>
<i className={'fa fa-map-marker'} />
<p>{country}</p>
</button>

const MentorInfo = () => {
return (
<div>
<h2 className="name" id={`${mentorID}`}>
{name}
</h2>
<h4 className="title">{title}</h4>
{extended && (
<>
<Languages />
<Joined />
</>
)}
<MentorDescription />
</div>
);
};
<Avatar mentor={mentor} id={mentorID} />
<LikeButton onClick={toggleFav} liked={isFav} tooltip={tooltip} />
</div>
);
};

const SkillsTags = () => {
return (
<div className="tags">{tagsList(tags, handleTagClick, extended)}</div>
);
};
const CardFooter = ({mentor, availability, appearance}) => {
const urls = useRoutes();

const MentorNotAvailable = () => {
return (
Expand All @@ -219,52 +191,6 @@ const Card = ({ mentor, onFavMentor, isFav, appearance }: CardProps) => {
);
};

const getChannelsContent = () => {
const isMyMentor = mentor.channels.length > 0;
if (!availability && !isMyMentor) {
return <MentorNotAvailable />;
}
return appearance === 'extended' ? (
<Channels channels={mentor.channels} />
) : (
<CTAButton
tooltipProps={{
disabled: true,
}}
link={urls.user.get(mentor)}
text="Go to profile"
/>
);
};

const CardFooter = () => {
return (
<div className="channels">
<div className="channel-inner">{getChannelsContent()}</div>
</div>
);
};

const CardHeader = () => {
const tooltip = currentUser
? undefined
: messages.CARD_ANONYMOUS_LIKE_TOOLTIP;
return (
<div className="header">
<button
className="country location"
onClick={() => handleCountryClick(country)}
>
<i className={'fa fa-map-marker'} />
<p>{country}</p>
</button>

<Avatar mentor={mentor} id={mentorID} />
<LikeButton onClick={toggleFav} liked={isFav} tooltip={tooltip} />
</div>
);
};

const Channels = ({ channels }: { channels: Channel[] }) => {
if (!channels.length) {
return <ApplyButton mentor={mentor} />;
Expand Down Expand Up @@ -310,6 +236,81 @@ const Card = ({ mentor, onFavMentor, isFav, appearance }: CardProps) => {
);
};

const getChannelsContent = () => {
const isMyMentor = mentor.channels.length > 0;
if (!availability && !isMyMentor) {
return <MentorNotAvailable />;
}
return appearance === 'extended' ? (
<Channels channels={mentor.channels} />
) : (
<CTAButton
tooltipProps={{
disabled: true,
}}
link={urls.user.get(mentor)}
text="Go to profile"
/>
);
};

return (
<div className="channels">
<div className="channel-inner">{getChannelsContent()}</div>
</div>
);
};

const Card = ({ mentor, onFavMentor, isFav, appearance }: CardProps) => {
const extended = appearance === 'extended';
const { setFilterParams } = useFilterParams();
const {
name,
country,
description,
tags,
title,
_id: mentorID,
available: availability,
createdAt,
} = mentor;

const handleTagClick = (tag: string) => {
setFilterParams('technology', tag);
};

const MentorDescription = () => {
return description ? (
<p className="description">{description}</p>
) : (
<React.Fragment />
);
};

const MentorInfo = () => {
return (
<div>
<h2 className="name" id={`${mentorID}`}>
{name}
</h2>
<h4 className="title">{title}</h4>
{extended && (
<>
<Languages />
<Joined />
</>
)}
<MentorDescription />
</div>
);
};

const SkillsTags = () => {
return (
<div className="tags">{tagsList(tags, handleTagClick, extended)}</div>
);
};

const Languages = () => (
<div className="languages" title="Spoken Languages">
<i className="fa fa-language" />
Expand All @@ -335,10 +336,18 @@ const Card = ({ mentor, onFavMentor, isFav, appearance }: CardProps) => {
data-testid="mentor-card"
appearance={appearance}
>
<CardHeader />
<CardHeader
mentor={mentor}
onFavMentor={onFavMentor}
isFav={isFav}
/>
<MentorInfo />
<SkillsTags />
<CardFooter />
<CardFooter
mentor={mentor}
availability={availability}
appearance={appearance}
/>
</StyledCard>
);
};
Expand Down
Loading