Skip to content

Commit 8db03d9

Browse files
committed
Fix carousel
1 parent 3c3c46c commit 8db03d9

File tree

5 files changed

+25
-30
lines changed

5 files changed

+25
-30
lines changed

peerprep/app/page.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ export default function Home() {
2727
<p> Code with a friend 👥 instead! 😊</p>
2828
<p>PeerPrep is a platform for technical interview preparation</p>
2929

30-
<div className={"m-5 rounded-md border-black p-5"}>
31-
<p>
32-
<strong>Features:</strong>
33-
</p>
34-
<ol>
35-
<li>- Online coding</li>
36-
<li>- A code editor</li>
37-
</ol>
38-
</div>
30+
<p>
31+
<strong>Features:</strong>
32+
</p>
33+
<ol>
34+
<li>- Online coding</li>
35+
<li>- A collaborative code editor</li>
36+
<li>- Camera and audio support</li>
37+
<li>
38+
- Syntax highlighting and formatting for three languages!
39+
</li>
40+
</ol>
3941
</div>
4042
</div>
4143
</div>

peerprep/components/home/Carousel.tsx

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import React, { useState, useEffect, useRef } from "react";
1+
import React, { useEffect, useRef, useState } from "react";
22
import { AnimatePresence, motion, MotionConfig } from "framer-motion";
33
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
44

5-
// code adapted from https://buildui.com/courses/framer-motion-recipes/carousel-part-1
6-
75
export type ImageProps = {
86
url: string;
97
alt: string;
@@ -23,7 +21,7 @@ const Carousel = ({ images }: { images: ImageProps[] }) => {
2321
clearExistingInterval();
2422
intervalRef.current = setInterval(() => {
2523
setIndex((prevIndex) => (prevIndex + 1) % images.length);
26-
}, 3000);
24+
}, 5000);
2725
};
2826

2927
const prevSlide = () => {
@@ -42,30 +40,25 @@ const Carousel = ({ images }: { images: ImageProps[] }) => {
4240
startInterval();
4341

4442
return () => clearExistingInterval();
45-
});
46-
47-
// TODO: make it infinite scroll to not show white background
48-
// TODO: use bigger pictures
43+
}, [images.length]);
4944

5045
return (
51-
<div className="m-auto flex flex-auto items-center">
46+
<div className="m-auto flex max-w-screen-md flex-auto items-center">
5247
<MotionConfig transition={{ duration: 0.7, ease: [0.32, 0.72, 0, 1] }}>
53-
<div className="relative w-full max-w-7xl overflow-hidden">
48+
<div className="relative w-full overflow-hidden">
5449
<div className="relative flex justify-center">
5550
<motion.div
56-
animate={{ x: `-${index * 33}%` }}
57-
className="flex"
58-
initial={"center"}
59-
// style={{ width: `${200 * images.length}%` }}
51+
animate={{ x: `-${index * 100}%` }}
52+
className="w-[100 * images.length]% flex"
6053
>
61-
{images.map((image, i) => (
54+
{[...images, ...images].map((image, i) => (
6255
<motion.img
6356
key={i}
6457
src={image.url}
6558
alt={image.alt}
6659
width={800}
6760
height={800}
68-
className="h-auto w-full rounded-md border-2 border-white object-cover"
61+
className="w-[100 / images.length]% h-auto rounded-md border-2 border-white object-cover"
6962
/>
7063
))}
7164
</motion.div>
@@ -75,10 +68,10 @@ const Carousel = ({ images }: { images: ImageProps[] }) => {
7568
animate={{ opacity: 0.7 }}
7669
exit={{ opacity: 0, pointerEvents: "none" }}
7770
whileHover={{ opacity: 1 }}
78-
className="absolute left-4 top-1/2 flex h-8 w-8 items-center justify-center rounded-full bg-white"
71+
className="absolute left-4 top-1/2 flex h-8 w-8 items-center justify-center rounded-full border border-gray-3 bg-white"
7972
onClick={prevSlide}
8073
>
81-
<ChevronLeftIcon className="h-6 w-6" />
74+
<ChevronLeftIcon className="h-6 w-6" color={"black"} />
8275
</motion.button>
8376
</AnimatePresence>
8477
<AnimatePresence initial={false}>
@@ -87,10 +80,10 @@ const Carousel = ({ images }: { images: ImageProps[] }) => {
8780
animate={{ opacity: 0.7 }}
8881
exit={{ opacity: 0, pointerEvents: "none" }}
8982
whileHover={{ opacity: 1 }}
90-
className="absolute right-4 top-1/2 flex h-8 w-8 items-center justify-center rounded-full bg-white"
83+
className="absolute right-4 top-1/2 flex h-8 w-8 items-center justify-center rounded-full border border-gray-3 bg-white hover:border-gray-2"
9184
onClick={nextSlide}
9285
>
93-
<ChevronRightIcon className="h-6 w-6" />
86+
<ChevronRightIcon className="h-6 w-6" color={"black"} />
9487
</motion.button>
9588
</AnimatePresence>
9689
</div>
@@ -100,4 +93,4 @@ const Carousel = ({ images }: { images: ImageProps[] }) => {
10093
);
10194
};
10295

103-
export default Carousel;
96+
export default Carousel;

peerprep/public/boring1.png

262 KB
Loading

peerprep/public/boring2.png

364 KB
Loading

peerprep/public/boring3.png

143 KB
Loading

0 commit comments

Comments
 (0)