From 7eee3c8801c03b63299f4ecb5c906c24873de80e Mon Sep 17 00:00:00 2001 From: lbratkovskaya Date: Mon, 8 Mar 2021 12:23:33 +0500 Subject: [PATCH] fix: routing fix --- src/components/App.tsx | 8 +++----- src/components/CountryPage/index.tsx | 6 ++++-- src/components/ImagesGrid/index.tsx | 5 +++-- src/store/rootReducer.ts | 9 ++------- src/store/types.ts | 14 ++++++++++++++ 5 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 src/store/types.ts diff --git a/src/components/App.tsx b/src/components/App.tsx index 43f2088..b77bd41 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { BrowserRouter, - Redirect, Route, Switch, } from 'react-router-dom'; @@ -37,13 +36,12 @@ const App: React.FC = (props: rootProps) => ( - - - - + + + diff --git a/src/components/CountryPage/index.tsx b/src/components/CountryPage/index.tsx index 2e4adf2..55bf104 100644 --- a/src/components/CountryPage/index.tsx +++ b/src/components/CountryPage/index.tsx @@ -5,7 +5,9 @@ import { import { useParams, } from 'react-router-dom'; -import { rootProps } from '../../store/rootConnector'; +import rootConnector, { + rootProps, +} from '../../store/rootConnector'; import { URLParamTypes } from '../../types'; const CountryPage: React.FC = () => { @@ -18,4 +20,4 @@ const CountryPage: React.FC = () => { return (
{t(`${countryId}.name`)}
); }; -export default CountryPage; +export default rootConnector(CountryPage); diff --git a/src/components/ImagesGrid/index.tsx b/src/components/ImagesGrid/index.tsx index a036a4b..fb706c8 100644 --- a/src/components/ImagesGrid/index.tsx +++ b/src/components/ImagesGrid/index.tsx @@ -16,6 +16,7 @@ import rootConnector, { rootProps, } from '../../store/rootConnector'; +import { Country } from '../../types'; const useStyles = makeStyles(() => createStyles({ root: { @@ -52,9 +53,9 @@ const ImagesGrid: React.FC = (props: rootProps) => { return (
- {countries.map((country) => ( + {countries.map((country: Country) => ( - + {t(`${country.id}.name`)} { +const rootReducer = (state: IAppState = initialState, action: RootReducerAction) => { switch (action.type) { case 'SET_LANG': return { ...state, lang: action.payload.lang }; diff --git a/src/store/types.ts b/src/store/types.ts new file mode 100644 index 0000000..0133296 --- /dev/null +++ b/src/store/types.ts @@ -0,0 +1,14 @@ +import { Country } from '../types'; + +export interface IAppState { + lang: 'EN' | 'RU' | 'DE', + countries: Country[], +} + +export interface RootReducerAction { + type: string, + payload: { + lang?: string, + countries?: Country[], + } +}