Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/reduxStore/bars/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import * as actionTypes from './actionTypes';
import { barApi } from '../../service/api/bar';

export const getBars = () => async dispatch => {
dispatch({ type: actionTypes.GET_ALL_BARS });
dispatch({ type: actionTypes.GET_ALL_BARS });

try {
const bars = await barApi.getBars();
dispatch({ type: actionTypes.GET_ALL_BARS_SUCCESS, payload: bars });
} catch(e) {
dispatch({ type: actionTypes.GET_ALL_BARS_ERROR, payload: e });
}
}
try {
const bars = await barApi.getBars();
dispatch({ type: actionTypes.GET_ALL_BARS_SUCCESS, payload: bars });
} catch (e) {
dispatch({ type: actionTypes.GET_ALL_BARS_ERROR, payload: e });
}
};
50 changes: 25 additions & 25 deletions src/reduxStore/bars/reducer.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import * as actionTypes from './actionTypes';

const initialState = {
allBars: [],
isBarListLoading: false,
barListLoadingError: {},
}
allBars: [],
isBarListLoading: false,
barListLoadingError: {},
};

export function barsReducer(state = initialState, action) {
switch (action.type) {
case actionTypes.GET_ALL_BARS:
return {
...state,
isBarListLoading: true,
};
case actionTypes.GET_ALL_BARS_SUCCESS:
return {
...state,
allBars: action.payload,
isBarListLoading: false,
};
case actionTypes.GET_ALL_BARS_ERROR:
return {
...state,
isBarListLoading: false,
barListLoadingError: action.payload,
}
default:
return state;
}
switch (action.type) {
case actionTypes.GET_ALL_BARS:
return {
...state,
isBarListLoading: true,
};
case actionTypes.GET_ALL_BARS_SUCCESS:
return {
...state,
allBars: action.payload,
isBarListLoading: false,
};
case actionTypes.GET_ALL_BARS_ERROR:
return {
...state,
isBarListLoading: false,
barListLoadingError: action.payload,
};
default:
return state;
}
}
4 changes: 2 additions & 2 deletions src/routes/ProtectedRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Switch } from 'react-router-dom';
// eslint-disable-next-line import/no-named-as-default-member
import PrivateRoute from '../ui/components/AuthHOC';
import BarCrawlPage from '../ui/components/BarCrawlPage';
import Bars from '../ui/components/Bars';
import BarPage from '../ui/components/BarPage';

const ProtectedRoutes = () => {
return (
Expand All @@ -15,7 +15,7 @@ const ProtectedRoutes = () => {
<BarCrawlPage />
</PrivateRoute>
<PrivateRoute exact path="/adminBars">
<Bars />
<BarPage />
</PrivateRoute>
</Switch>
);
Expand Down
7 changes: 7 additions & 0 deletions src/ui/components/BarCrawlPage/BarCrawlItem/BarCrawlItem.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.barCrawl {
border: 2px solid rgb(212, 36, 36);
margin-left: 10px;
padding-left: 3px;
margin-top: 40px;
width: 300px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { object, func, string } from 'prop-types';
import './BarCrawlItem.scss';

const propTypes = {
barCrawlItem: object,
onClickHandler: func,
bcName: string,
bcTime: string,
bcPrice: string,
};

const BarCrawlItemComponent = ({ barCrawlItem }) => {
const { bcName, bcTime, bcPrice } = barCrawlItem;
function onClickHandler() {
console.log(barCrawlItem._id);
}
return (
<div className="barCrawl">
<h2>{bcName}</h2>
<p>{bcTime}</p>
<p>{bcPrice}</p>
<button onClick={onClickHandler} type="button">
test
</button>
</div>
);
};

BarCrawlItemComponent.propTypes = propTypes;

export { BarCrawlItemComponent };
4 changes: 2 additions & 2 deletions src/ui/components/BarCrawlPage/BarCrawlPageComponent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import BarItem from './BarItem';
import BarCrawlItem from './BarCrawlItem';
import { array } from 'prop-types';

const propTypes = {
Expand All @@ -12,7 +12,7 @@ const BarCrawlPageComponent = ({ barCrawlFeed }) => {
<div>
{barCrawlFeed.length > 0 &&
barCrawlFeed.map(barCrawlItem => {
return <BarItem barCrawlItem={barCrawlItem} key={barCrawlItem._id} />;
return <BarCrawlItem barCrawlItem={barCrawlItem} key={barCrawlItem._id} />;
})}
</div>
);
Expand Down
18 changes: 0 additions & 18 deletions src/ui/components/BarCrawlPage/BarItem/BarCrawlItemComponent.js

This file was deleted.

28 changes: 28 additions & 0 deletions src/ui/components/BarPage/BarItem/BarItemComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import './BarItem.scss';
import { object } from 'prop-types';

const propTypes = {
barItem: object,
};

const BarItemComponent = ({ barItem }) => {
const { barName, address, barInfo } = barItem;
function onClickHandler() {
console.log(barItem._id);
}
return (
<div className="bar">
<h2>{barName}</h2>
<p>{address}</p>
<p>{barInfo}</p>
<button onClick={onClickHandler} type="button">
test
</button>
</div>
);
};

BarItemComponent.propTypes = propTypes;

export { BarItemComponent };
14 changes: 14 additions & 0 deletions src/ui/components/BarPage/BarPageComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import BarItem from './BarItem';

Comment thread
karypotter marked this conversation as resolved.
const BarPageComponent = ({ allBars }) => {
return (
<div>
{allBars.map(item => {
return <BarItem barItem={item} />;
})}
</div>
);
};

export default BarPageComponent;
28 changes: 28 additions & 0 deletions src/ui/components/BarPage/BarPageContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import BarPageComponent from './BarPageComponent';
import { getBars } from '../../../reduxStore/bars/actions';
import { func } from 'prop-types';

const propTypes = {
getBars: func,
};

const BarPageContainer = () => {
const allBars = useSelector(state => state.barsReducer.allBars);
const dispatch = useDispatch();

const useBar = someFetchActionCreator => {
useEffect(() => {
dispatch(someFetchActionCreator());
}, [someFetchActionCreator]);
};

useBar(getBars);

return <BarPageComponent allBars={allBars} />;
};

BarPageContainer.propTypes = propTypes;

export default BarPageContainer;
3 changes: 3 additions & 0 deletions src/ui/components/BarPage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import BarPageContainer from './BarPageContainer';

export default BarPageContainer;
14 changes: 0 additions & 14 deletions src/ui/components/Bars/BarComponent.js

This file was deleted.

30 changes: 0 additions & 30 deletions src/ui/components/Bars/BarContainer.js

This file was deleted.

28 changes: 0 additions & 28 deletions src/ui/components/Bars/BarItem/BarItemComponent.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/ui/components/Bars/index.js

This file was deleted.