-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ivan3008/homework 6 - черновик #181
base: Ivan3008/homework_6
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
import { MOVE_ORDER_TO_CUSTOMER } from './farmTypes'; | ||
|
||
export const moveOrderToCustomer = id => { | ||
return { | ||
type: MOVE_ORDER_TO_CUSTOMER, | ||
payload: id | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
import { CREATE_ORDER, MOVE_ORDER_TO_FARM } from './marketTypes'; | ||
import { | ||
CREATE_ORDER, | ||
MOVE_ORDER_TO_FARM, | ||
DELETE_ORDER_FROM_MARKET | ||
} from './marketTypes'; | ||
|
||
export const createOrder = (id, name, price, createdAt) => { | ||
return { | ||
type: CREATE_ORDER, | ||
payload: { | ||
id, | ||
name, | ||
price, | ||
createdAt | ||
} | ||
}; | ||
}; | ||
|
||
export const moveOrderToFarm = (id, name, price, createdAt) => { | ||
return { | ||
type: MOVE_ORDER_TO_FARM, | ||
payload: { | ||
id, | ||
name, | ||
price, | ||
createdAt | ||
} | ||
}; | ||
}; | ||
|
||
export const deleteOrderFromMarket = id => { | ||
return { | ||
type: DELETE_ORDER_FROM_MARKET, | ||
payload: id | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
import React, { Component } from 'react'; | ||
import './Farm.css'; | ||
import { connect } from 'react-redux'; | ||
import Order from 'components/Order'; | ||
import { | ||
moveOrderToCustomer | ||
} from 'actions/farmActions'; | ||
|
||
const mapStateToProps = state => ({ | ||
farm: state.farm | ||
}); | ||
|
||
const mapDispatchToProps = { | ||
moveOrderToCustomer | ||
}; | ||
|
||
export class Farm extends Component { | ||
render() { | ||
return <div className="farm" />; | ||
return ( | ||
<div className="farm"> | ||
<h2>Производство на ферме</h2> | ||
<button>Отправить урожай клиенту</button> | ||
<div /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Farm; | ||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(Farm); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
import React from 'react'; | ||
import './Order.css'; | ||
|
||
const Order = ({ name, price, createdAt }) => ( | ||
<div className="order" /> | ||
const Order = (order) => ( | ||
<div className="order"> | ||
<div className="order__upper"> | ||
<p className="p--order">Название: {order.name}</p> | ||
<p className="p--order"> | ||
Цена: <span className="order-price">{order.price}</span> | ||
</p> | ||
</div> | ||
<div className="order__lower"> | ||
<p className="p--order"> | ||
Создан: {order.createdAt.toISOString().slice(0,10)} | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
|
||
|
||
export default Order; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
CREATE_ORDER, | ||
MOVE_ORDER_TO_FARM, | ||
DELETE_ORDER_FROM_MARKET | ||
} from 'actions/marketTypes'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нужно добавить |
||
export default (state = [], action) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Перепиши эту строчку так |
||
switch (action.type) { | ||
case CREATE_ORDER: | ||
return [action.payload, ...state]; | ||
|
||
case MOVE_ORDER_TO_FARM: | ||
return [action.payload, ...state]; | ||
|
||
case DELETE_ORDER_FROM_MARKET: | ||
return state.filter(order => order.id !== action.payload); | ||
|
||
default: | ||
return state; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Код свитча сверь с этим: switch (action.type) {
case CREATE_ORDER:
const { payload } = action;
return [...state, payload];
case MOVE_ORDER_TO_FARM:
const { id } = action.payload;
return state.filter(order => order.id !== id);
default:
return state;
} |
||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Потребуется вот это export default combineReducers({
orders
});
export const getMarketOrders = state => state.market.orders; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
этот экшен тебе не нужен в этом месте.