Skip to content

Commit

Permalink
Merge pull request #611 from ShouvikGhosh2048/dynamically-size-mod-ca…
Browse files Browse the repository at this point in the history
…rousel

Dynamically size mod carousel
  • Loading branch information
otobot1 authored Nov 12, 2023
2 parents 7660d15 + 045f41c commit 325d12c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/mods/expandedMod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const ExpandedMod = ({ isLoading, mod }: ExpandedModProps) => {
isMapperNameVisiblePermitted={isMapperNameVisiblePermitted}
mapIds={mod.Map.map(({ id }) => id)}
/>
<ModCarousel gamebananaModId={mod.gamebananaModId} />
<ModCarousel gamebananaModId={mod.gamebananaModId} numberOfMaps={mod.Map.length}/>
</Flex>
</Stack>
);
Expand Down
20 changes: 16 additions & 4 deletions src/components/mods/modCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,23 @@ const useStyles = createStyles(
},
},
viewport: {
border: "3px solid #263972",
"div": {
alignItems: 'center',
}
},
slide: {
width: "400px",
},
imgMaxHeight250: {
"img": {
maxHeight: "250px",
}
},
imgMaxHeight400: {
"img": {
maxHeight: "400px",
}
},
controls: {
transform: "translate(0, 0)",
position: "unset"
Expand All @@ -44,12 +56,13 @@ const useStyles = createStyles(

type modCarouselProps = {
gamebananaModId: number,
numberOfMaps: number,
};




const ModCarousel = ({ gamebananaModId }: modCarouselProps) => {
const ModCarousel = ({ gamebananaModId, numberOfMaps }: modCarouselProps) => {
const { imageUrls } = useGamebananaModImageUrls({ gamebananaModId });


Expand All @@ -63,7 +76,7 @@ const ModCarousel = ({ gamebananaModId }: modCarouselProps) => {
<Carousel classNames={{
root: classes.carousel,
viewport: classes.viewport,
slide: classes.slide,
slide: cx(classes.slide, numberOfMaps >= 4 ? classes.imgMaxHeight400 : classes.imgMaxHeight250),
controls: classes.controls,
control:classes.control,
}}>
Expand All @@ -76,7 +89,6 @@ const ModCarousel = ({ gamebananaModId }: modCarouselProps) => {
<Image
src={imageUrl}
alt="Mod image"
height={250} //TODO!!: add responsive image sizes
/>
</Carousel.Slide>
))}
Expand Down
10 changes: 7 additions & 3 deletions src/components/mods/modsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ export const ModsTable = ({ qualities, difficulties, modsWithInfo, isLoading }:
setCurrentTabIndex(parentDifficultyNames.length > 0 ? 0 : null);
}, [difficulties, parentDifficultyNames]);

// Check child difficulties when childDifficultyNames changes.
// Check selected child difficulties when childDifficultyNames changes.
useEffect(() => {
setSelectedChildDifficulties(selectedChildDifficulties => selectedChildDifficulties.filter(childDifficulty => childDifficultyNames.includes(childDifficulty)));
}, [childDifficultyNames]);
const newSelectedChildDifficulties = selectedChildDifficulties.filter(childDifficulty => childDifficultyNames.includes(childDifficulty));
// Only set when the list actually reduces.
if (newSelectedChildDifficulties.length !== selectedChildDifficulties.length) {
setSelectedChildDifficulties(newSelectedChildDifficulties);
}
}, [selectedChildDifficulties, childDifficultyNames]);

const filteredModsWithInfo = useMemo(() => {
return modsWithInfo.filter((modWithInfo) => {
Expand Down

0 comments on commit 325d12c

Please sign in to comment.