-
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
mashkin.m
committed
Jan 13, 2025
1 parent
878f2b0
commit cdeb6aa
Showing
65 changed files
with
1,938 additions
and
1,283 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 { createBrowserHistory } from 'history'; | ||
|
||
const browserHistory = createBrowserHistory(); | ||
|
||
export default browserHistory; |
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,40 @@ | ||
import { memo, useCallback } from 'react'; | ||
import { CityInfoList, CityData } from '../consts/consts.ts'; | ||
import { getCurrentCityName } from '../store/data-process/data-process.selectors.ts'; | ||
import { changeCityAction } from '../store/data-process/data-process.slice.ts'; | ||
import { useAppDispatch, useAppSelector } from '../store/hooks.ts'; | ||
import { City } from '../types/city.ts'; | ||
|
||
function CitiesList(): JSX.Element { | ||
const dispatch = useAppDispatch(); | ||
const currentCityName = useAppSelector(getCurrentCityName); | ||
const handleCityClick = useCallback( | ||
(city: City) => dispatch(changeCityAction(city)), | ||
[dispatch] | ||
); | ||
return ( | ||
<div className="tabs"> | ||
<section className="locations container"> | ||
<ul className="locations__list tabs__list"> | ||
{CityInfoList.map((city: City) => ( | ||
<li key={city.name} className="locations__item"> | ||
<a | ||
className={`locations__item-link tabs__item${ | ||
currentCityName === city.name ? ' tabs__item--active' : '' | ||
}`} | ||
onClick={() => { | ||
handleCityClick(CityData[city.name]); | ||
}} | ||
> | ||
<span>{city.name}</span> | ||
</a> | ||
</li> | ||
))} | ||
</ul> | ||
</section> | ||
</div> | ||
); | ||
} | ||
|
||
const MemorizedCitiesList = memo(CitiesList); | ||
export default MemorizedCitiesList; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,78 @@ | ||
import { Link } from 'react-router-dom'; | ||
import { AppRoutes } from '../consts/consts.ts'; | ||
import { useAppDispatch, useAppSelector } from '../store/hooks.ts'; | ||
import { logoutAction } from '../store/api-actions.ts'; | ||
import { | ||
getAuthCheckedStatus, | ||
getFavoriteOffersCount, | ||
getUserData, | ||
} from '../store/user-process/user-process.selectors.ts'; | ||
import { memo } from 'react'; | ||
|
||
function Header(): JSX.Element { | ||
const favoritesCount = useAppSelector(getFavoriteOffersCount); | ||
const isAuthorized = useAppSelector(getAuthCheckedStatus); | ||
const userData = useAppSelector(getUserData); | ||
const dispatch = useAppDispatch(); | ||
|
||
return ( | ||
<header className="header"> | ||
<div className="container"> | ||
<div className="header__wrapper"> | ||
<div className="header__left"> | ||
<Link className="header__logo-link" to="/"> | ||
<img | ||
className="header__logo" | ||
src="img/logo.svg" | ||
alt="6 cities logo" | ||
width="81" | ||
height="41" | ||
/> | ||
</Link> | ||
</div> | ||
<nav className="header__nav"> | ||
<ul className="header__nav-list"> | ||
{isAuthorized && ( | ||
<li className="header__nav-item user"> | ||
<Link | ||
className="header__nav-link header__nav-link--profile" | ||
to={AppRoutes.Favorites} | ||
> | ||
<div className="header__avatar-wrapper user__avatar-wrapper"></div> | ||
<span className="header__user-name user__name"> | ||
{userData?.name} | ||
</span> | ||
<span className="header__favorite-count"> | ||
{favoritesCount} | ||
</span> | ||
</Link> | ||
</li> | ||
)} | ||
<li className="header__nav-item"> | ||
{isAuthorized ? ( | ||
<Link | ||
className="header__nav-link" | ||
onClick={(evt) => { | ||
evt.preventDefault(); | ||
dispatch(logoutAction()); | ||
}} | ||
to={AppRoutes.Main} | ||
> | ||
<span className="header__signout">Sign out</span> | ||
</Link> | ||
) : ( | ||
<Link className="header__nav-link" to={AppRoutes.Login}> | ||
<span className="header__signout">Sign in</span> | ||
</Link> | ||
)} | ||
</li> | ||
</ul> | ||
</nav> | ||
</div> | ||
</div> | ||
</header> | ||
); | ||
} | ||
|
||
const MemorizedHeader = memo(Header); | ||
export default MemorizedHeader; |
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,31 @@ | ||
import { useState, useLayoutEffect } from 'react'; | ||
import { Router } from 'react-router-dom'; | ||
import type { BrowserHistory } from 'history'; | ||
|
||
export interface HistoryRouterProps { | ||
history: BrowserHistory; | ||
basename?: string; | ||
children?: React.ReactNode; | ||
} | ||
|
||
function HistoryRouter({ basename, children, history }: HistoryRouterProps) { | ||
const [state, setState] = useState({ | ||
action: history.action, | ||
location: history.location, | ||
}); | ||
|
||
useLayoutEffect(() => history.listen(setState), [history]); | ||
|
||
return ( | ||
<Router | ||
basename={basename} | ||
location={state.location} | ||
navigationType={state.action} | ||
navigator={history} | ||
> | ||
{children} | ||
</Router> | ||
); | ||
} | ||
|
||
export default HistoryRouter; |
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,3 @@ | ||
export function LoadingScreen(): JSX.Element { | ||
return <p>Loading ...</p>; | ||
} |
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 { Link } from 'react-router-dom'; | ||
import { AppRoutes, CityInfoList } from '../consts/consts.ts'; | ||
import { changeCityAction } from '../store/data-process/data-process.slice.ts'; | ||
import { useAppDispatch } from '../store/hooks.ts'; | ||
import { redirectToRoute } from '../store/actions.ts'; | ||
|
||
export function LocationItem(): JSX.Element { | ||
const randomCityIndex = Math.floor(Math.random() * CityInfoList.length); | ||
const randomCity = CityInfoList[randomCityIndex]; | ||
const dispatch = useAppDispatch(); | ||
const handleCityClick = () => { | ||
dispatch(changeCityAction(randomCity)); | ||
dispatch(redirectToRoute(AppRoutes.Main)); | ||
}; | ||
return ( | ||
<section className="locations locations--login locations--current"> | ||
<div className="locations__item"> | ||
<Link | ||
className="locations__item-link" | ||
to={AppRoutes.Main} | ||
onClick={handleCityClick} | ||
> | ||
<span>{randomCity.name}</span> | ||
</Link> | ||
</div> | ||
</section> | ||
); | ||
} |
Oops, something went wrong.