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

Make HomeSection component more generic #1073

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions frontend/src/components/pages/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ const HomeUI: React.FC = () => {
.filter(({ results }) => results.length > 0)
.map(({ titleTranslationId, iconUrl, results }) => (
<HomeSection
className="mx-4 desktop:mx-10percent"
title={intl.formatMessage({ id: titleTranslationId })}
iconUrl={iconUrl}
key={titleTranslationId}
results={results}
asColumn
dtrucs marked this conversation as resolved.
Show resolved Hide resolved
/>
))}
{homeBottom !== undefined && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,45 @@ import { ResultCard } from 'components/pages/search/components/ResultCard';
import { getHoverId } from 'components/pages/search/utils';
import { ActivitySuggestion } from 'modules/activitySuggestions/interface';
import SVG from 'react-inlinesvg';
import styled from 'styled-components';
import { cn } from 'services/utils/cn';
import { optimizeAndDefineColor } from 'stylesheet';

export interface HomeSectionProps {
title: string;
iconUrl: string;
results: ActivitySuggestion['results'];
className?: string;
asColumn?: boolean;
}

export const HomeSection: React.FC<HomeSectionProps> = ({ title, iconUrl, results }) => {
export const HomeSection: React.FC<HomeSectionProps> = ({
asColumn = false,
title,
iconUrl,
results,
className,
}) => {
return (
<div id={'home_section'} className={`flex flex-col`}>
<h2
id="home_sectionTitle"
className="flex border-t border-greySoft border-solid pt-4 desktop:pt-10 mb-2 desktop:mb-6 mx-4 desktop:mx-10percent"
>
<SVG
src={iconUrl}
preProcessor={optimizeAndDefineColor()}
className="h-10 mr-2 desktop:mr-3"
/>
<span className="mt-1 desktop:mt-0 text-H2 desktop:text-H2 font-bold">{title}</span>
</h2>
<ScrollContainer className="flex p-5 overflow-scroll desktop:overflow-auto desktop:mx-10percent desktop:px-0 desktop:grid desktop:grid-cols-3 desktop:gap-3">
<div id={'home_section'} className={cn('custo-suggestions flex flex-col', className)}>
{title && (
<h2
id="home_sectionTitle"
className="custo-suggestions-title flex border-t border-greySoft border-solid pt-4 desktop:pt-10 mb-2 desktop:mb-6"
>
<SVG
src={iconUrl}
preProcessor={optimizeAndDefineColor()}
className="h-10 mr-2 desktop:mr-3"
aria-hidden
/>
<span className="mt-1 desktop:mt-0 text-H2 desktop:text-H2 font-bold">{title}</span>
</h2>
)}
<div className="custo-suggestions-content flex px-5 overflow-scroll desktop:overflow-auto desktop:px-0 desktop:grid desktop:grid-cols-3 gap-5">
{results.map(e => {
return (
<ResultCard
asColumn
asColumn={asColumn}
type={e.type}
key={e.name}
id={e.id}
Expand All @@ -43,22 +54,11 @@ export const HomeSection: React.FC<HomeSectionProps> = ({ title, iconUrl, result
badgeName={e.category?.label}
informations={e.informations}
redirectionUrl={generateDetailsUrlFromType(e.type, e.id, e.name)}
className="my-4 desktop:my-6 desktop:mx-1" // Height is not limited to let the card grow with long text & informations. Most photos are not vertical, and does not have to be restrained.
className="my-4 desktop:my-6 desktop:mx-1 min-w-70 max-w-70 desktop:max-w-none shrink-0"
/>
);
})}
</ScrollContainer>
</div>
</div>
);
};

const ScrollContainer = styled.div`
@media (max-width: 1024px) {
& > * {
flex: auto;
max-width: 300px;
min-width: 300px;
margin-right: 20px;
}
}
`;
Loading