Skip to content

Commit

Permalink
[SCSE-264] Implement Memories Section (#101)
Browse files Browse the repository at this point in the history
* [SCSE-264] Implement Memories Section

* [SCSE-264] Implement Memories Section

* style: enhance ui

* fix: unique key for footer social links

* update jest test

* fix linting errors

* fixed home memories carousel autoscroll bug

---------

Co-authored-by: Jing Qiang <[email protected]>
  • Loading branch information
brandonlokemk and xJQx authored Jun 4, 2023
1 parent 3bbcee6 commit 7180e2a
Show file tree
Hide file tree
Showing 17 changed files with 471 additions and 18 deletions.
163 changes: 163 additions & 0 deletions apps/web/__tests__/__snapshots__/index.snapshot.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,169 @@ exports[`renders homepage unchanged 1`] = `
/>
</div>
</div>
<div
class="css-p7zbsy"
>
<div
class="css-1yc5myk"
>
<div
class="css-368bfx"
/>
<div
class="css-ia346u"
>
<div
class="framed-text-container css-5wel2l"
>
<p
class="chakra-text css-1gu5k9l"
>
Memories
</p>
<div
class="css-19mfpbt"
/>
<div
class="css-1nfbmmu"
/>
</div>
</div>
</div>
<div
class="css-h9kdrx"
>
<div
class="css-kw7qpy"
>
<div
class="css-177g2fo"
>
<svg
class="chakra-icon css-1sbq9ay"
fill="currentColor"
focusable="false"
height="1em"
stroke="currentColor"
stroke-width="0"
viewBox="0 0 512 512"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M48 32C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h416c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48H48zm0 32h106c3.3 0 6 2.7 6 6v20c0 3.3-2.7 6-6 6H38c-3.3 0-6-2.7-6-6V80c0-8.8 7.2-16 16-16zm426 96H38c-3.3 0-6-2.7-6-6v-36c0-3.3 2.7-6 6-6h138l30.2-45.3c1.1-1.7 3-2.7 5-2.7H464c8.8 0 16 7.2 16 16v74c0 3.3-2.7 6-6 6zM256 424c-66.2 0-120-53.8-120-120s53.8-120 120-120 120 53.8 120 120-53.8 120-120 120zm0-208c-48.5 0-88 39.5-88 88s39.5 88 88 88 88-39.5 88-88-39.5-88-88-88zm-48 104c-8.8 0-16-7.2-16-16 0-35.3 28.7-64 64-64 8.8 0 16 7.2 16 16s-7.2 16-16 16c-17.6 0-32 14.4-32 32 0 8.8-7.2 16-16 16z"
/>
</svg>
<div
class="css-1e0zu2b"
>
<svg
class="chakra-icon css-1d5rxcs"
fill="currentColor"
focusable="false"
height="1em"
stroke="currentColor"
stroke-width="0"
viewBox="0 0 320 512"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M34.52 239.03L228.87 44.69c9.37-9.37 24.57-9.37 33.94 0l22.67 22.67c9.36 9.36 9.37 24.52.04 33.9L131.49 256l154.02 154.75c9.34 9.38 9.32 24.54-.04 33.9l-22.67 22.67c-9.37 9.37-24.57 9.37-33.94 0L34.52 272.97c-9.37-9.37-9.37-24.57 0-33.94z"
/>
</svg>
</div>
<div
class="css-s88hxx"
>
<div
class="css-135g186"
>
<div
class="css-m29uso"
>
<img
alt="back to school"
class="chakra-image css-m017b4"
src="https://images.unsplash.com/photo-1523050854058-8df90110c9f1?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1740&q=80"
style="object-fit: cover; width: 100%; height: 100%;"
/>
</div>
<div
class="css-m29uso"
>
<img
alt="students doing project work together"
class="chakra-image css-m017b4"
src="https://images.unsplash.com/photo-1523240795612-9a054b0db644?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1740&q=80"
style="object-fit: cover; width: 100%; height: 100%;"
/>
</div>
<div
class="css-m29uso"
>
<img
alt="library"
class="chakra-image css-m017b4"
src="https://images.unsplash.com/photo-1537202108838-e7072bad1927?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=892&q=80"
style="object-fit: cover; width: 100%; height: 100%;"
/>
</div>
<div
class="css-m29uso"
>
<img
alt="beautiful campus"
class="chakra-image css-m017b4"
src="https://images.unsplash.com/photo-1580537782437-8d6a0ca13de6?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1740&q=80"
style="object-fit: cover; width: 100%; height: 100%;"
/>
</div>
<div
class="css-m29uso"
>
<img
alt="scse friends"
class="chakra-image css-m017b4"
src="https://plus.unsplash.com/premium_photo-1683887034179-c498b684dd57?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1738&q=80"
style="object-fit: cover; width: 100%; height: 100%;"
/>
</div>
<div
class="css-m29uso"
>
<img
alt="scse networking event"
class="chakra-image css-m017b4"
src="https://images.unsplash.com/photo-1527529482837-4698179dc6ce?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1740&q=80"
style="object-fit: cover; width: 100%; height: 100%;"
/>
</div>
</div>
</div>
<div
class="css-1iimj3y"
>
<svg
class="chakra-icon css-1d5rxcs"
fill="currentColor"
focusable="false"
height="1em"
stroke="currentColor"
stroke-width="0"
viewBox="0 0 320 512"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z"
/>
</svg>
</div>
</div>
</div>
</div>
</div>
<div
class="chakra-stack css-12nxbtz"
>
Expand Down
1 change: 1 addition & 0 deletions apps/web/features/home/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { memoriesData } from "./memoriesData"
34 changes: 34 additions & 0 deletions apps/web/features/home/api/memoriesData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { HomeMemoriesCarouselProps } from "../components/HomeMemoriesCarousel";

export let memoriesData: HomeMemoriesCarouselProps["images"] = [
{
src:
"https://images.unsplash.com/photo-1523050854058-8df90110c9f1?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1740&q=80",
alt: "back to school",
},
{
src:
"https://images.unsplash.com/photo-1523240795612-9a054b0db644?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1740&q=80",
alt: "students doing project work together",
},
{
src:
"https://images.unsplash.com/photo-1537202108838-e7072bad1927?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=892&q=80",
alt: "library",
},
{
src:
"https://images.unsplash.com/photo-1580537782437-8d6a0ca13de6?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1740&q=80",
alt: "beautiful campus",
},
{
src:
"https://plus.unsplash.com/premium_photo-1683887034179-c498b684dd57?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1738&q=80",
alt: "scse friends",
},
{
src:
"https://images.unsplash.com/photo-1527529482837-4698179dc6ce?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1740&q=80",
alt: "scse networking event",
},
];
54 changes: 54 additions & 0 deletions apps/web/features/home/components/HomeMemories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Box, Flex } from "@chakra-ui/react";
import { FramedText} from "ui";
import { memoriesData } from "../api";
import { HomeMemoriesCarousel } from "@/features/home/components/HomeMemoriesCarousel";

export const HomeMemories = () => {
return (
<>
<Flex // Outer box
pos={"relative"}
h={"90vh"}
backgroundColor={"brand.navy.dark"}
flexDir={"column"}
justify={"center"}
>
<Flex // Top Section
pos={"relative"}
w={"100%"}
h={"45%"}
flexDir={"column"}
justifyContent={"end"}
alignItems={"center"}
>
<Box // Banner image
pos={"absolute"}
backgroundImage={"/home/home-memories-top-banner.png"}
backgroundPosition={"top"}
backgroundRepeat={"no-repeat"}
backgroundSize={"cover"}
w={"100%"}
h={"100%"}
/>
<Box
pos={"relative"}
backgroundColor={"brand.navy.dark"}
h={"max-content"}
w={"max-content"}
paddingX={"64px"}
paddingY={"24px"}
borderRadius={"37px 37px 0px 0px"}
borderBottom={"1px dashed #FFFFFF"}
>
<FramedText text={"Memories"} />
</Box>
</Flex>
<Flex h={["55%", "55%", "65%", "65%"]} w={"100%"} justifyContent={"center"} alignItems={"center"}>
<Box w={"85%"} height={"35vh"}>
<HomeMemoriesCarousel images={memoriesData} autoSlide />
</Box>
</Flex>
</Flex>
</>
);
};
133 changes: 133 additions & 0 deletions apps/web/features/home/components/HomeMemoriesCarousel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { useState, useEffect } from "react";
import { Box, Flex, Icon, Image, useBreakpointValue } from "@chakra-ui/react";
import { FaChevronLeft, FaChevronRight, FaCameraRetro } from "react-icons/fa";
import { keyframes } from "@emotion/react";

export interface HomeMemoriesCarouselProps {
images: Array<{
src: string;
alt: string;
}>;
autoSlide?: boolean;
autoSlideInterval?: number;
}

export const HomeMemoriesCarousel = (props: HomeMemoriesCarouselProps) => {
const {
images,
autoSlide = false,
autoSlideInterval = 5000,
} = props;

const imageEndOffset = useBreakpointValue({ base: 1, sm: 2, md: 3 }) ?? 1;
const imageWidth = useBreakpointValue({ base: 100, sm: 50, md: 33 }) ?? 100;

const [curr, setCurr] = useState(0);

const prev = () => setCurr((curr) => (curr === 0 ? images?.length - imageEndOffset : curr - 1));
const next = () => setCurr((curr) => (curr === images?.length - imageEndOffset ? 0 : curr + 1));

// Auto Slide
useEffect(() => {
if (!autoSlide) return;
const slideInterval = setInterval(next, autoSlideInterval);
return () => clearInterval(slideInterval);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [next]);

return (
<Flex
position={"relative"}
w={"100%"}
h={"100%"}
flexDir={"row"}
>
<Icon
as={FaCameraRetro}
position={"absolute"}
zIndex={10}
boxSize={"48px"}
background={"brand.navy.dark"}
transform={"rotate(-30deg) translateY(-18px) translateX(36px)"}
animation={`${cameraAnimation} 2s infinite`}
/>
{/* Left Arrow */}
<Flex
zIndex={2}
backgroundColor={"brand.navy.dark"}
alignItems={"center"}
paddingRight={"8px"}
>
<Icon
as={FaChevronLeft}
onClick={prev}
boxSize={["24px", "32px", "32px", "32px"]}
color={"white"}
cursor={"pointer"}
/>
</Flex>

{/* Images */}
<Flex
overflow={"hidden"}>
<Flex
zIndex={1}
transition={"ease-out"}
transitionDuration={"500ms"}
transform={`translateX(-${curr * imageWidth}%)`}
h={"100%"}
>
{images.map(image => (
// eslint-disable-next-line @next/next/no-img-element
<Box
key={image.alt}
minWidth={`${imageWidth}%`}
maxWidth={`${imageWidth}%`}
overflow={"hidden"}
>
<Image
src={image.src}
alt={image.alt}
paddingX={"4px"}
style={{
objectFit: 'cover',
width: '100%',
height: '100%',
}}
_hover={{
// transform: 'scale(1.1)',
paddingX: '24px',
paddingY: '12px'
}}
transition={"ease-in-out"}
transitionDuration={"100ms"}
/>
</Box>
))}
</Flex>
</Flex>

{/* Right Arrow */}
<Flex
zIndex={2}
backgroundColor={"brand.navy.dark"}
alignItems={"center"}
paddingLeft={"8px"}
>
<Icon
as={FaChevronRight}
onClick={next}
boxSize={["24px", "32px", "32px", "32px"]}
color={"white"}
cursor={"pointer"}
/>
</Flex>
</Flex>
)
}

const cameraAnimation = keyframes`
0% { color: #EF8891 }
50% { color: #DD616B }
100% { color: #EF8891 }
`;
Loading

1 comment on commit 7180e2a

@vercel
Copy link

@vercel vercel bot commented on 7180e2a Jun 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

website-ui-storybook – ./packages/ui

website-ui-storybook-cse-it.vercel.app
website-ui-storybook-git-main-cse-it.vercel.app
storybook.ui.dev.ntuscse.com

Please sign in to comment.