Skip to content

Commit

Permalink
feat(home): show only 1 tile in featured shelf
Browse files Browse the repository at this point in the history
  • Loading branch information
royschut committed Jun 9, 2021
1 parent 7ad0361 commit e7cd1ba
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/components/Shelf/Shelf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export const tileBreakpoints: Breakpoints = {
export const featuredTileBreakpoints: Breakpoints = {
[Breakpoint.xs]: 1,
[Breakpoint.sm]: 1,
[Breakpoint.md]: 2,
[Breakpoint.lg]: 2,
[Breakpoint.xl]: 2,
[Breakpoint.md]: 1,
[Breakpoint.lg]: 1,
[Breakpoint.xl]: 1,
};

export type ShelfProps = {
Expand Down
6 changes: 6 additions & 0 deletions src/screens/Home/Home.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
}
.shelfContainer {
padding: 12px 56px;
&.featured {
padding: 12px 20%;
}

@include responsive.mobile-only() {
padding: 24px 60px 24px variables.$base-spacing;
Expand All @@ -19,5 +22,8 @@
}
@include responsive.tablet-only() {
padding: 0 variables.$base-spacing * 2;
&.featured {
padding: 24px variables.$base-spacing * 2;
}
}
}
34 changes: 24 additions & 10 deletions src/screens/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,33 @@ const Home = (): JSX.Element => {

const calculateHeight = (index: number): number => {
const item = content[index];
const isMobile = tileBreakpoints[breakpoint] <= Breakpoint.sm;
const isLargeScreen = breakpoint >= Breakpoint.md;

if (!item) return 0;

const tilesToShow: number = item.featured ? featuredTileBreakpoints[breakpoint] : tileBreakpoints[breakpoint];
const shelfTitlesHeight = config.options.shelveTitles ? 40 : 0;
const shelfMetaHeight = item.featured ? 24 : shelfTitlesHeight + 24;
const cardMetaHeight = item.featured ? 0 : 40;
const shelfHorizontalMargin = (isMobile && item.featured ? 20 : 56) * featuredTileBreakpoints[breakpoint];
const cardWidth = (document.body.offsetWidth - shelfHorizontalMargin) / tilesToShow;
const cardHeight = cardWidth * (9 / 16);

return cardHeight + shelfMetaHeight + cardMetaHeight;
const calculateFeatured = () => {
const tilesToShow = featuredTileBreakpoints[breakpoint];
const shelfMetaHeight = 24;
const cardMetaHeight = 10;
const shelfHorizontalMargin = isLargeScreen ? document.body.offsetWidth * 0.4 : 0;
const cardWidth = (document.body.offsetWidth - shelfHorizontalMargin) / tilesToShow;
const cardHeight = cardWidth * (9 / 16);

return cardHeight + shelfMetaHeight + cardMetaHeight;
};
const calculateRegular = () => {
const tilesToShow = tileBreakpoints[breakpoint];
const shelfTitlesHeight = config.options.shelveTitles ? 40 : 0;
const shelfMetaHeight = shelfTitlesHeight + 24;
const cardMetaHeight = 40;
const shelfHorizontalMargin = 0 * featuredTileBreakpoints[breakpoint];
const cardWidth = (document.body.offsetWidth - shelfHorizontalMargin) / tilesToShow;
const cardHeight = cardWidth * (9 / 16);

return cardHeight + shelfMetaHeight + cardMetaHeight;
};

return item.featured ? calculateFeatured() : calculateRegular();
};

useEffect(() => {
Expand Down

0 comments on commit e7cd1ba

Please sign in to comment.