Skip to content

Commit

Permalink
fix: routing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lbratkovskaya committed Mar 9, 2021
1 parent dafb94d commit 7eee3c8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
8 changes: 3 additions & 5 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import {
BrowserRouter,
Redirect,
Route,
Switch,
} from 'react-router-dom';
Expand Down Expand Up @@ -37,13 +36,12 @@ const App: React.FC<rootProps> = (props: rootProps) => (
</Button>
<BrowserRouter>
<Switch>
<Route path="/countries">
<MainPage />
</Route>
<Route path="/country/:countryId">
<CountryPage />
</Route>
<Redirect path="/" to="/countries" />
<Route path="/">
<MainPage />
</Route>
</Switch>
</BrowserRouter>
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/components/CountryPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<rootProps> = () => {
Expand All @@ -18,4 +20,4 @@ const CountryPage: React.FC<rootProps> = () => {
return (<div title={t(`${countryId}.name`)}>{t(`${countryId}.name`)}</div>);
};

export default CountryPage;
export default rootConnector(CountryPage);
5 changes: 3 additions & 2 deletions src/components/ImagesGrid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import rootConnector,
{
rootProps,
} from '../../store/rootConnector';
import { Country } from '../../types';

const useStyles = makeStyles(() => createStyles({
root: {
Expand Down Expand Up @@ -52,9 +53,9 @@ const ImagesGrid: React.FC<rootProps> = (props: rootProps) => {
return (
<div className={classes.root}>
<GridList className={classes.gridList} cols={2.5}>
{countries.map((country) => (
{countries.map((country: Country) => (
<GridListTile key={country.pictureURL}>
<Link to={`country/${country.id}`}>
<Link to={`/country/${country.id}`}>
<img
src={country.pictureURL}
alt={t(`${country.id}.name`)}
Expand Down
9 changes: 2 additions & 7 deletions src/store/rootReducer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { Country } from '../types';

export interface IAppState {
lang: 'EN' | 'RU' | 'DE',
countries: Country[],
}
import { IAppState, RootReducerAction } from './types';

const initialState: IAppState = {
lang: 'EN',
Expand Down Expand Up @@ -55,7 +50,7 @@ const initialState: IAppState = {
],
};

const rootReducer = (state: IAppState = initialState, action: any) => {
const rootReducer = (state: IAppState = initialState, action: RootReducerAction) => {
switch (action.type) {
case 'SET_LANG':
return { ...state, lang: action.payload.lang };
Expand Down
14 changes: 14 additions & 0 deletions src/store/types.ts
Original file line number Diff line number Diff line change
@@ -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[],
}
}

0 comments on commit 7eee3c8

Please sign in to comment.