-
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
Open
Ivan3008
wants to merge
3
commits into
dex157:Ivan3008/homework_6
Choose a base branch
from
Ivan3008:Ivan3008/homework_6
base: Ivan3008/homework_6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+290
−15
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,20 @@ | ||
import { MOVE_ORDER_TO_CUSTOMER } from './farmTypes'; | ||
import { MOVE_ORDER_TO_CUSTOMER, ADD_ORDER_TO_FARM } from './farmTypes'; | ||
|
||
export const moveOrderToCustomer = id => { | ||
return { | ||
type: MOVE_ORDER_TO_CUSTOMER, | ||
payload: id | ||
}; | ||
}; | ||
|
||
export const addOrderToFarm = (id, name, price, createdAt) => { | ||
return { | ||
type: ADD_ORDER_TO_FARM, | ||
payload: { | ||
id, | ||
name, | ||
price, | ||
createdAt | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const MOVE_ORDER_TO_CUSTOMER = 'MOVE_ORDER_TO_CUSTOMER'; | ||
export const ADD_ORDER_TO_FARM = 'ADD_ORDER_TO_FARM'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
import { CREATE_ORDER, MOVE_ORDER_TO_FARM } from './marketTypes'; | ||
import { | ||
CREATE_ORDER, | ||
DELETE_ORDER_FROM_MARKET | ||
} from './marketTypes'; | ||
|
||
export const createOrder = (id, name, price, createdAt) => { | ||
return { | ||
type: CREATE_ORDER, | ||
payload: { | ||
id, | ||
name, | ||
price, | ||
createdAt | ||
} | ||
}; | ||
}; | ||
|
||
export const deleteOrderFromMarket = (id) => { | ||
return { | ||
type: DELETE_ORDER_FROM_MARKET, | ||
payload: id | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export const CREATE_ORDER = 'CREATE_ORDER'; | ||
|
||
export const MOVE_ORDER_TO_FARM = 'MOVE_ORDER_TO_FARM'; | ||
//export const MOVE_ORDER_TO_FARM = 'MOVE_ORDER_TO_FARM'; | ||
|
||
export const DELETE_ORDER_FROM_MARKET = 'DELETE_ORDER_FROM_MARKET'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,41 @@ | ||
import React from 'react'; | ||
import './Budget.css'; | ||
import { connect } from 'react-redux'; | ||
import { getBudget } from 'reducers/budget'; | ||
|
||
export const Budget = () => <div className="budget" />; | ||
const mapStateToProps = state => ({ | ||
budget: getBudget(state) | ||
}); | ||
|
||
export default Budget; | ||
export const Budget = props => { | ||
const { | ||
income, | ||
sellersExpences, | ||
farmExpences, | ||
deliveryExpences | ||
} = props.budget; | ||
const total = income + (sellersExpences + farmExpences + deliveryExpences); | ||
return ( | ||
<div className="budget"> | ||
<h2>Бюджет</h2> | ||
<p> | ||
Всего получено денег: <span className="t-profit">{income}</span> | ||
</p> | ||
<p> | ||
Расходы продавцов: <span className="t-sellers">{sellersExpences}</span> | ||
</p> | ||
<p> | ||
Расходы на ферме: <span className="t-farm">{farmExpences}</span> | ||
</p> | ||
<p> | ||
Расходы на доставку:{' '} | ||
<span className="t-delivery">{deliveryExpences}</span> | ||
</p> | ||
<p> | ||
Итого: <span className="t-total">{total}</span> | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default connect(mapStateToProps)(Budget); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,39 @@ | ||
import React, { Component } from 'react'; | ||
import './Farm.css'; | ||
import { connect } from 'react-redux'; | ||
import Order from 'components/Order'; | ||
import { getFarmOrders } from 'reducers/farm'; | ||
import { moveOrderToCustomer } from 'actions/farmActions'; | ||
|
||
const mapStateToProps = state => ({ | ||
farm: getFarmOrders(state) | ||
}); | ||
|
||
const mapDispatchToProps = { | ||
moveOrderToCustomer | ||
}; | ||
|
||
export class Farm extends Component { | ||
render() { | ||
return <div className="farm" />; | ||
const { moveOrderToCustomer } = this.props; | ||
const { farm } = this.props; | ||
return ( | ||
<div className="farm"> | ||
<h2>Производство на ферме</h2> | ||
<button | ||
onClick={() => { | ||
Object.keys(farm).length > 0 && moveOrderToCustomer(farm[0].id); | ||
}} | ||
> | ||
Отправить урожай клиенту | ||
</button> | ||
<div>{farm.map(order => <Order key={order.id} {...order} />)}</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Farm; | ||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(Farm); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { CREATE_ORDER } from 'actions/marketTypes'; | ||
import { ADD_ORDER_TO_FARM, MOVE_ORDER_TO_CUSTOMER } from 'actions/farmTypes'; | ||
|
||
const initialState = { | ||
income: 0, | ||
sellersExpences: 0, | ||
farmExpences: 0, | ||
deliveryExpences: 0 | ||
}; | ||
|
||
export default (state = initialState, action) => { | ||
switch (action.type) { | ||
case CREATE_ORDER: | ||
const income = state.income + action.payload.price; | ||
const sellersExpences = state.sellersExpences - 20; | ||
return { | ||
...state, | ||
income, | ||
sellersExpences | ||
}; | ||
|
||
case ADD_ORDER_TO_FARM: | ||
const farmExpences = state.farmExpences - 100; | ||
return { | ||
...state, | ||
farmExpences | ||
}; | ||
|
||
case MOVE_ORDER_TO_CUSTOMER: | ||
const deliveryExpences = state.deliveryExpences - 20; | ||
return { | ||
...state, | ||
deliveryExpences | ||
}; | ||
|
||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export const getBudget = state => state.budget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { combineReducers } from 'redux'; | ||
import { MOVE_ORDER_TO_CUSTOMER, ADD_ORDER_TO_FARM } from 'actions/farmTypes'; | ||
|
||
const orders = (state = [], action) => { | ||
switch (action.type) { | ||
case ADD_ORDER_TO_FARM: | ||
const { payload } = action; | ||
return [...state, payload]; | ||
|
||
case MOVE_ORDER_TO_CUSTOMER: | ||
const id = action.payload; | ||
return state.filter(order => order.id !== id); | ||
|
||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default combineReducers({ | ||
orders | ||
}); | ||
|
||
export const getFarmOrders = state => state.farm.orders; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { combineReducers } from 'redux'; | ||
import { CREATE_ORDER, DELETE_ORDER_FROM_MARKET } from 'actions/marketTypes'; | ||
|
||
const orders = (state = [], action) => { | ||
switch (action.type) { | ||
case CREATE_ORDER: | ||
const { payload } = action; | ||
return [...state, payload]; | ||
|
||
case DELETE_ORDER_FROM_MARKET: | ||
const id = action.payload; | ||
return state.filter(order => order.id !== id); | ||
|
||
// case DELETE_ORDER_FROM_MARKET: | ||
// return state.filter(order => order.id !== action.payload); | ||
|
||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default combineReducers({ | ||
orders | ||
}); | ||
|
||
export const getMarketOrders = state => state.market.orders; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Потребуется вот это