-
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.
- Loading branch information
Showing
15 changed files
with
155 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,28 @@ | ||
import { City } from '../../types/city'; | ||
import { useAppDispatch } from '../../hooks'; | ||
import { changeCity } from '../../store/action'; | ||
import { CITIES } from '../../mocks/cities'; | ||
|
||
type CityListProps = { | ||
chosenCity: City; | ||
} | ||
|
||
function CityList({chosenCity}: CityListProps): JSX.Element { | ||
const dispatch = useAppDispatch(); | ||
const handleCityChange = (city: City) => { | ||
dispatch(changeCity(city)); | ||
}; | ||
return( | ||
<ul className="locations__list tabs__list"> | ||
{CITIES.map((city) => ( | ||
<li className="locations__item" key={city.title}> | ||
<a className={`locations__item-link tabs__item ${(city === chosenCity) ? 'tabs__item--active' : ''}`} onClick={() => {handleCityChange(city)}}> | ||
Check failure on line 19 in src/components/city-list/city-list.tsx GitHub Actions / Check
Check failure on line 19 in src/components/city-list/city-list.tsx GitHub Actions / Check
|
||
<span>{city.title}</span> | ||
</a> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
} | ||
|
||
export default CityList; | ||
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 { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'; | ||
import type { State, AppDispatch } from '../types/state'; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from './components/app/app'; | ||
import { Settings } from './const'; | ||
import { Provider } from 'react-redux'; | ||
import { store } from './store'; | ||
|
||
const root = ReactDOM.createRoot( | ||
document.getElementById('root') as HTMLElement | ||
); | ||
|
||
root.render( | ||
<React.StrictMode> | ||
<App placesCount={Settings.placesCount}/> | ||
<Provider store = {store}> | ||
<App/> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,34 @@ | ||
import { City } from '../types/city'; | ||
|
||
export const AMSTERDAM: City = { | ||
title: 'Amsterdam', | ||
lat: 52.3740300, | ||
lng: 4.8896900 | ||
}; | ||
export const CITIES: City[] = [ | ||
{ | ||
title: 'Paris', | ||
lat: 52.3740300, | ||
lng: 4.8896900 | ||
}, | ||
{ | ||
title: 'Brussels', | ||
lat: 52.3740300, | ||
lng: 4.8896900 | ||
}, | ||
{ | ||
title: 'Cologne', | ||
lat: 52.3740300, | ||
lng: 4.8896900 | ||
}, | ||
{ | ||
title: 'Amsterdam', | ||
lat: 52.3740300, | ||
lng: 4.8896900 | ||
}, | ||
{ | ||
title: 'Hamburg', | ||
lat: 52.3740300, | ||
lng: 4.8896900 | ||
}, | ||
{ | ||
title: 'Dusseldorf', | ||
lat: 52.3740300, | ||
lng: 4.8896900 | ||
}, | ||
]; |
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,17 +1,15 @@ | ||
import { Offer } from '../../types/offer'; | ||
import OfferList from '../../components/offer-list/offer-list'; | ||
import { Link } from 'react-router-dom'; | ||
import Map from '../../components/map/map'; | ||
import { POINTS } from '../../mocks/points'; | ||
import { AMSTERDAM } from '../../mocks/cities'; | ||
import { typeOfCardList } from '../../const'; | ||
import { useAppSelector } from '../../hooks'; | ||
import CityList from '../../components/city-list/city-list'; | ||
|
||
type MainScreenProps = { | ||
placesCount: number; | ||
offers: Offer[]; | ||
} | ||
|
||
function MainScreen({placesCount, offers}: MainScreenProps): JSX.Element { | ||
function MainScreen(): JSX.Element { | ||
const [city, offers] = useAppSelector((state) => [state.city, state.offers]); | ||
const chosenOffers = offers.filter((offer) => offer.city === city); | ||
const points = chosenOffers.map((offer) => offer.point); | ||
const favoriteOffers = offers.filter((offer) => offer.isFavorite); | ||
return ( | ||
<div className="page page--gray page--main"> | ||
<header className="header"> | ||
|
@@ -30,7 +28,7 @@ function MainScreen({placesCount, offers}: MainScreenProps): JSX.Element { | |
</div> | ||
<span className="header__user-name user__name">[email protected]</span> | ||
<Link to="/favorites"> | ||
<span className="header__favorite-count">3</span> | ||
<span className="header__favorite-count">{favoriteOffers.length}</span> | ||
</Link> | ||
</a> | ||
</li> | ||
|
@@ -49,45 +47,14 @@ function MainScreen({placesCount, offers}: MainScreenProps): JSX.Element { | |
<h1 className="visually-hidden">Cities</h1> | ||
<div className="tabs"> | ||
<section className="locations container"> | ||
<ul className="locations__list tabs__list"> | ||
<li className="locations__item"> | ||
<a className="locations__item-link tabs__item" href="#"> | ||
<span>Paris</span> | ||
</a> | ||
</li> | ||
<li className="locations__item"> | ||
<a className="locations__item-link tabs__item" href="#"> | ||
<span>Cologne</span> | ||
</a> | ||
</li> | ||
<li className="locations__item"> | ||
<a className="locations__item-link tabs__item" href="#"> | ||
<span>Brussels</span> | ||
</a> | ||
</li> | ||
<li className="locations__item"> | ||
<a className="locations__item-link tabs__item tabs__item--active"> | ||
<span>Amsterdam</span> | ||
</a> | ||
</li> | ||
<li className="locations__item"> | ||
<a className="locations__item-link tabs__item" href="#"> | ||
<span>Hamburg</span> | ||
</a> | ||
</li> | ||
<li className="locations__item"> | ||
<a className="locations__item-link tabs__item" href="#"> | ||
<span>Dusseldorf</span> | ||
</a> | ||
</li> | ||
</ul> | ||
<CityList chosenCity={city}/> | ||
</section> | ||
</div> | ||
<div className="cities"> | ||
<div className="cities__places-container container"> | ||
<section className="cities__places places"> | ||
<h2 className="visually-hidden">Places</h2> | ||
<b className="places__found">{placesCount} places to stay in Amsterdam</b> | ||
<b className="places__found">{chosenOffers.length} places to stay in {city.title}</b> | ||
<form className="places__sorting" action="#" method="get"> | ||
<span className="places__sorting-caption">Sort by</span> | ||
<span className="places__sorting-type" tabIndex={0}> | ||
|
@@ -103,11 +70,11 @@ function MainScreen({placesCount, offers}: MainScreenProps): JSX.Element { | |
<li className="places__option" tabIndex={0}>Top rated first</li> | ||
</ul> | ||
</form> | ||
<OfferList offers={offers} listType={typeOfCardList.standart}/> | ||
<OfferList offers={chosenOffers} listType={typeOfCardList.standart}/> | ||
</section> | ||
<div className="cities__right-section"> | ||
<section className="cities__map map"> | ||
<Map points={POINTS} city={AMSTERDAM} selectedPoint={undefined}/> | ||
<Map points={points} city={city} selectedPoint={undefined}/> | ||
</section> | ||
</div> | ||
</div> | ||
|
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 { createAction } from "@reduxjs/toolkit"; | ||
import { City } from "../types/city"; | ||
|
||
export const getOffers = createAction('OFFERS_GET') | ||
|
||
export const changeCity = createAction('CITY_CHANGE', (value: City) => ({ | ||
payload: value | ||
})); | ||
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,28 @@ | ||
import { createReducer } from '@reduxjs/toolkit'; | ||
import { CITIES } from '../mocks/cities'; | ||
import { OFFERS } from '../mocks/offers'; | ||
import { City } from '../types/city'; | ||
import { Offer } from '../types/offer'; | ||
import { changeCity, getOffers } from './action'; | ||
|
||
type StateType = { | ||
city: City; | ||
offers: Offer[] | ||
} | ||
|
||
const initialState: StateType = { | ||
city: CITIES[0], | ||
offers: OFFERS | ||
}; | ||
|
||
const reducer = createReducer(initialState, (builder) => { | ||
builder | ||
.addCase(getOffers, (state) => { | ||
state.offers = OFFERS; | ||
}) | ||
.addCase(changeCity, (state, action) => { | ||
state.city = action.payload; | ||
}); | ||
}); | ||
|
||
export {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
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,5 @@ | ||
import { store } from '../store/index.js'; | ||
|
||
export type State = ReturnType<typeof store.getState>; | ||
|
||
export type AppDispatch = typeof store.dispatch; |