Skip to content

Commit

Permalink
added favorites page
Browse files Browse the repository at this point in the history
  • Loading branch information
Bad-Raider committed Sep 17, 2023
1 parent 4ba5bb6 commit 6ecf7bd
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 44 deletions.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"react-router-dom": "^6.15.0",
"react-scripts": "5.0.1",
"redux": "^4.2.1",
"redux-persist": "^6.0.0",
"sass": "^1.66.1",
"web-vitals": "^2.1.3"
},
Expand Down
12 changes: 4 additions & 8 deletions src/components/CarCard/CarCard.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import {
ItemCar,
WraperImg,
Expand All @@ -17,11 +16,6 @@ import { toggleFavorite } from '../../redux/favoritesSlise';


const CarCard = ({ data }) => {
const dispatch = useDispatch();
const isFavorite = useSelector(state =>
state.favorites.items.some(car => car.id === data.id)
);

const {
id,
year,
Expand All @@ -34,9 +28,11 @@ const CarCard = ({ data }) => {
rentalCompany,
address,
} = data;

const dispatch = useDispatch();
const isFavorite = useSelector(state =>
state.favorites.items.some(car => car.id === data.id)
);
const shortAdress = address.substring(address.indexOf(",") + 2).trim();

const handleToggleFavorite = () => {
dispatch(toggleFavorite(data));
};
Expand Down
4 changes: 3 additions & 1 deletion src/components/CarCard/CarCard.styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ export const BtnLearneMore = styled.button`
&:focus {
background-color: ${colors.accentHoverColor};
}
`
`


25 changes: 25 additions & 0 deletions src/components/FavoritesList/FavoritesList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import CarCard from 'components/CarCard/CarCard';
import { useSelector, } from 'react-redux';
import { ListCar } from '../CarsList/CarsList.styled';


const FavoritesList = () => {
const { favorites } = useSelector(state => state);


return <>
{favorites.items.length === 0
&& <div> You have not added cars to your favorites list </div>}
<ListCar >
{favorites.items.map((data, index) => (
<CarCard
key={index}
data={data}
/>
))}
</ListCar>
</>
};

export default FavoritesList;

File renamed without changes.
File renamed without changes.
14 changes: 9 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import App from 'components/App/App';
import './index.scss';
import { BrowserRouter } from 'react-router-dom';
import { Provider } from "react-redux";
import { store } from "./redux/store";
import { PersistGate } from 'redux-persist/integration/react';

import { store, persistor } from "./redux/store";


ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<Provider store={store}>
<BrowserRouter basename="/auto-rent-app">
<App />
</BrowserRouter>
</Provider>
<PersistGate loading={null} persistor={persistor}>
<BrowserRouter basename="/auto-rent-app">
<App />
</BrowserRouter>
</PersistGate>
</Provider>
</React.StrictMode>
);
13 changes: 8 additions & 5 deletions src/pages/Favorites.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import CarsList from 'components/CarsList/CarsList';
import FavoritesList from 'components/FavoritesList/FavoritesList';
import { CatalogSection } from 'components/Catalog/CatalogPage.styled';
import { Container } from 'components/Shared/Container.styled';

const FavoritesPage = () => {
return (
<div>
<h2>FavoritesPage</h2>
<CarsList />
</div>
<CatalogSection>
<Container>
<FavoritesList />
</Container>
</CatalogSection>
);
};

Expand Down
8 changes: 0 additions & 8 deletions src/redux/reduser.js

This file was deleted.

37 changes: 35 additions & 2 deletions src/redux/store.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
import { configureStore } from "@reduxjs/toolkit";
import { reducer } from './reduser';
import { carReducer } from "./carSlice.js";
import { favoritesReducer } from "./favoritesSlise.js";

import {
persistStore,
persistReducer,
FLUSH,
REHYDRATE,
PAUSE,
PERSIST,
PURGE,
REGISTER,
} from 'redux-persist';
import storage from 'redux-persist/lib/storage';

const PersistConfig = {
key: "favorites",
storage,
};


export const store = configureStore({
reducer
reducer: {
car: carReducer,
favorites: persistReducer(PersistConfig, favoritesReducer),
},
middleware(getDefaultMiddleware) {
return getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
},
});
},
});

export const persistor = persistStore(store);




15 changes: 0 additions & 15 deletions src/styles/common/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@ body {
overflow-y: scroll;
overflow-x: hidden;

@media screen and (min-width: 768px) {
// font-size: 16px;
// line-height: 1.37;
}

&.is-open {
// padding-right: calc(-1 * (100vw - 100%));
overflow-y: hidden;
}

@media screen and (min-width: 1440px) {
// &.is-open {
// padding-right: 10px;
// }
}
}

code {
Expand Down

0 comments on commit 6ecf7bd

Please sign in to comment.