Skip to content

Commit

Permalink
new files
Browse files Browse the repository at this point in the history
  • Loading branch information
GooDeene committed May 19, 2024
1 parent cb84d39 commit 6b63d93
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/components/cities-tabs/city-tab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {Link} from 'react-router-dom';
import {AppRoute} from '../../const.ts';
import classNames from 'classnames';
import {useDispatch} from 'react-redux';
import {setActiveCity} from '../../store/acions.ts';
import {City} from '../../types/city.ts';

type CityTabProps = {
city: City;
isActive: boolean;
}

function CityTab({city, isActive}: CityTabProps): JSX.Element {
const dispatch = useDispatch();
const handleTabClick = () => dispatch(setActiveCity(city));
const linkClassName = classNames('locations__item-link tabs__item', {'tabs__item--active': isActive});
return (
<li className="locations__item" key={city.name}>
<Link
to={AppRoute.Main}
className={linkClassName}
onClick={handleTabClick}
>
<span>{city.name}</span>
</Link>
</li>
);
}

export default CityTab;
4 changes: 4 additions & 0 deletions src/hooks/redux.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {TypedUseSelectorHook, useSelector} from 'react-redux';
import {RootState} from '../store';

export const useAppSelector : TypedUseSelectorHook<RootState> = useSelector;
4 changes: 4 additions & 0 deletions src/store/acions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {createAction} from '@reduxjs/toolkit';
import {City} from '../types/city.ts';

export const setActiveCity = createAction<City>('setCity');
6 changes: 6 additions & 0 deletions src/store/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {configureStore} from '@reduxjs/toolkit';
import {reducer} from './reducer.ts';

export const store = configureStore({reducer});

export type RootState = ReturnType<typeof store.getState>;
24 changes: 24 additions & 0 deletions src/store/reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {AvailableCities} from '../const.ts';
import {mockOffersShort} from '../moks/offers-short.ts';
import {OffersShort} from '../types/offers/offer-short.ts';
import {createReducer} from '@reduxjs/toolkit';
import {setActiveCity} from './acions.ts';
import {City} from '../types/city.ts';
import {mockCities} from '../moks/cities.ts';

type AppState = {
activeCity: City;
offers: OffersShort;
}

const initialState : AppState = {
activeCity: mockCities[AvailableCities.Paris],
offers: mockOffersShort,
};

export const reducer = createReducer(initialState, (builder) => {
builder
.addCase(setActiveCity, (state, action) => {
state.activeCity = action.payload;
});
});
8 changes: 8 additions & 0 deletions src/types/point.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {Location} from './location.ts';

export type Point = {
id: string;
location: Location;
}

export type Points = Point[];

0 comments on commit 6b63d93

Please sign in to comment.