-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Zombe2203/module6-task1
- Loading branch information
Showing
13 changed files
with
110 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useAppDispatch, useAppSelector } from '../../hooks/useAppSelector'; | ||
import { mockOffers } from '../../mocks/offers'; | ||
import { CITIES } from '../../recources/Cities'; | ||
import { setCity, setOffers } from '../../store/actions'; | ||
|
||
export const CityList = () => { | ||
const currentCity = useAppSelector((state) => state.city); | ||
const dispatch = useAppDispatch(); | ||
|
||
return ( | ||
<ul className="locations__list tabs__list"> | ||
{ | ||
Object.entries(CITIES).map(([cityName, city]) => ( | ||
<li key={cityName} className="locations__item"> | ||
<a className={`locations__item-link tabs__item ${(cityName === currentCity.name) ? 'tabs__item--active' : null}`} | ||
href="#" | ||
onClick={() => { | ||
dispatch(setCity({city: city})); | ||
dispatch(setOffers({offers: mockOffers})); | ||
}} | ||
> | ||
<span>{cityName}</span> | ||
</a> | ||
</li> | ||
)) | ||
} | ||
</ul> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {TypedUseSelectorHook, useDispatch, useSelector} from 'react-redux'; | ||
import { store } from '../store'; | ||
|
||
export type State = ReturnType<typeof store.getState>; | ||
export type AppDispatch = typeof store.dispatch; | ||
|
||
export const useAppDispatch = () => useDispatch<AppDispatch>(); | ||
export const useAppSelector: TypedUseSelectorHook<State> = useSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from './components/App/App'; | ||
import { Configuration } from './recources/Configuration'; | ||
import { offers } from './mocks/offers'; | ||
import { favoriteOffers } from './mocks/favoriteOffers'; | ||
import { mockOfferReviewsList } from './mocks/reviews'; | ||
import { Provider } from 'react-redux'; | ||
import { store } from './store'; | ||
|
||
const root = ReactDOM.createRoot( | ||
document.getElementById('root') as HTMLElement | ||
); | ||
|
||
root.render( | ||
<React.StrictMode> | ||
<App | ||
numberOfOffers={Configuration.numberOfOffers} | ||
listOfOffers={offers} | ||
listOfFavoriteOffers={favoriteOffers} | ||
offersProps={mockOfferReviewsList} | ||
/> | ||
<Provider store={store}> | ||
<App | ||
listOfFavoriteOffers={favoriteOffers} | ||
offersProps={mockOfferReviewsList} | ||
/> | ||
</Provider> | ||
</React.StrictMode> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {createAction} from '@reduxjs/toolkit'; | ||
import { City } from '../components/Map/Map'; | ||
import { CardProps } from '../recources/Types'; | ||
|
||
export const setCity = createAction<{city: City}>('setCity'); | ||
export const setOffers = createAction<{offers: CardProps[]}>('setOffers'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {configureStore} from '@reduxjs/toolkit'; | ||
import {reducer} from './reducer'; | ||
|
||
export const store = configureStore({reducer}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {createReducer} from '@reduxjs/toolkit'; | ||
import { CITIES } from '../recources/Cities'; | ||
import { mockOffers } from '../mocks/offers'; | ||
import { setCity, setOffers } from './actions'; | ||
|
||
const startState = { | ||
city: CITIES.Paris, | ||
stateOffers: mockOffers | ||
}; | ||
|
||
const reducer = createReducer(startState, (builder) => { | ||
builder | ||
.addCase(setCity, (state, action) => { | ||
const {city} = action.payload; | ||
state.city = city; | ||
}) | ||
.addCase(setOffers, (state, action) => { | ||
const {offers} = action.payload; | ||
state.stateOffers = offers; | ||
}); | ||
}); | ||
|
||
export {reducer}; |