Skip to content

Commit

Permalink
add vecel
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolaus-B committed Mar 24, 2024
1 parent 697c6e3 commit f280814
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/components/Car/Car.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useDispatch } from "react-redux";
import { toggleFavourite } from "../../redux/cars/carsSlice";
import { useIsFavourite } from "../../hooks/useIsFavourite";

export const Car = ({ car }) => {
export const Car = ({ car, hidden }) => {
const [modalIsOpen, setIsOpen] = useState(false);
const dispatch = useDispatch();

Expand All @@ -37,7 +37,7 @@ export const Car = ({ car }) => {
const isFavourite = useIsFavourite(car._id);

return (
<CarItem>
<CarItem className={hidden ? "hidden" : ""}>
<CarImage
$bgImage={
car.gallery[0] ||
Expand Down
37 changes: 35 additions & 2 deletions src/components/Car/Car.styled.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import styled from "styled-components";
import styled, { keyframes } from "styled-components";

// const getImage = (props) => props.$bgImage;
const fadeIn = keyframes`
from {
opacity: 0;
}
to {
opacity: 1;
}
`;

const fadeOut = keyframes`
from {
opacity: 1;
}
to {
opacity: 0;
}
`;

export const CarItem = styled.li`
display: flex;
Expand All @@ -12,6 +28,23 @@ export const CarItem = styled.li`
border: 1px solid ${(p) => p.theme.colors.borderColor};
border-radius: ${(p) => p.theme.radius.md};
animation: ${fadeIn} 0.5s ease;
&.hidden {
position: absolute;
width: 1px;
height: 1px;
bottom: -100px;
margin: -1px;
border: 0;
padding: 0;
opacity: 0;
animation: ${fadeOut} 0.5s ease;
pointer-events: none;
}
`;

export const CarImage = styled.div`
Expand Down
25 changes: 5 additions & 20 deletions src/components/CarsList/CarsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import { CarList, ListContainer, LoadMore } from "./CarsList.styled";
import { useState } from "react";

export const CarsList = () => {
const [visibleCars, setVisibleCars] = useState(4); // Локальний стан для кількості відображених елементів
const [visibleCars, setVisibleCars] = useState(4);
const filteredCars = useSelector(selectFilteredCars);

const loadMore = () => {
setVisibleCars((prevVisibleCars) => prevVisibleCars + 4); // Збільшуємо кількість відображених елементів на 4
setVisibleCars((prevVisibleCars) => prevVisibleCars + 4);
};

const allCarsDisplayed = visibleCars >= filteredCars.length; // Перевіряємо, чи всі елементи вже відображені
const allCarsDisplayed = visibleCars >= filteredCars.length;

return (
<ListContainer>
<CarList>
{filteredCars.slice(0, visibleCars).map((car) => (
<Car key={car.id} car={car.car} />
{filteredCars.map((car, index) => (
<Car key={car.id} car={car.car} hidden={index >= visibleCars} />
))}
</CarList>
{!allCarsDisplayed && (
Expand All @@ -29,18 +29,3 @@ export const CarsList = () => {
</ListContainer>
);
};

// export const CarsList = () => {
// const filteredCars = useSelector(selectFilteredCars);

// return (
// <ListContainer>
// <CarList>
// {filteredCars.map((car) => {
// return <Car key={car.id} car={car.car} />;
// })}
// </CarList>
// <LoadMore>Load more</LoadMore>
// </ListContainer>
// );
// };
2 changes: 1 addition & 1 deletion src/components/GlobalStyle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ button {
margin: -1px;
border: 0;
padding: 0;
opacity: 0;
white-space: nowrap;
clip-path: inset(100%);
clip: rect(0 0 0 0);
Expand Down
3 changes: 3 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rewrites": [{ "source": "/(.*)", "destination": "/" }]
}

0 comments on commit f280814

Please sign in to comment.