-
Notifications
You must be signed in to change notification settings - Fork 13
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
Ht7 #57
base: master
Are you sure you want to change the base?
Ht7 #57
Changes from all 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './loadBanner'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import Loader from '../loader'; | ||
import styles from './loadBanner.module.css'; | ||
|
||
function LoadBanner() { | ||
return ( | ||
<div className={styles.loadBanner}> | ||
<Loader /> | ||
</div> | ||
); | ||
} | ||
|
||
export default LoadBanner; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.loadBanner { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
top: 0; | ||
left: 0; | ||
display: flex; | ||
align-items: center; | ||
background: rgb(0 0 0 / 18%); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,18 @@ import { | |
LOAD_REVIEWS, | ||
LOAD_PRODUCTS, | ||
LOAD_USERS, | ||
ORDER_SUCCESS, | ||
ORDER_ERROR, | ||
ORDER_LOADING_TOGGLE, | ||
CLEAN_OUT, | ||
} from './constants'; | ||
import products from './reducer/products'; | ||
import { | ||
usersLoadingSelector, | ||
usersLoadedSelector, | ||
reviewsLoadingSelector, | ||
reviewsLoadedSelector, | ||
orderSelector, | ||
} from './selectors'; | ||
|
||
export const increment = (id) => ({ type: INCREMENT, payload: { id } }); | ||
|
@@ -63,3 +69,47 @@ export const loadUsers = () => async (dispatch, getState) => { | |
|
||
dispatch(_loadUsers()); | ||
}; | ||
|
||
export const takeOrder = () => async (dispatch, getState) => { | ||
const state = orderSelector(getState()); | ||
const order = Object.keys(state).map((productId) => { | ||
return { id: productId, amount: state[productId] }; | ||
}); | ||
|
||
dispatch(orderLoading(true)); | ||
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. лучше делать такого же вида екшены, как и на загрузку данных (через REQUEST, SUCCESS, FAILURE) - тогда все будет в едином стиле и проще для понимания 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. Я не очень поняла, как через REQUEST, SUCCESS, FAILURE это работает и зачем два значения в state, если можно ввести одно значение для определения,, что идет загрузка. |
||
|
||
await fetch('/api/order', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(order), | ||
}) | ||
.then((res) => { | ||
return res.json(); | ||
}) | ||
.then((res) => { | ||
dispatch(orderLoading(false)); | ||
if (res === 'ok') { | ||
dispatch(orderSuccess()); | ||
|
||
return; | ||
} | ||
|
||
dispatch(orderError(res)); | ||
}) | ||
.catch(dispatch(orderError)); | ||
}; | ||
|
||
const orderSuccess = () => ({ | ||
type: CLEAN_OUT, | ||
payload: {}, | ||
}); | ||
|
||
const orderLoading = (isLoad) => ({ | ||
type: ORDER_LOADING_TOGGLE, | ||
payload: { loading: isLoad }, | ||
}); | ||
|
||
const orderError = (error) => ({ | ||
type: ORDER_ERROR, | ||
payload: { error }, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,20 @@ import { createSelector } from 'reselect'; | |
import { getById } from './utils'; | ||
|
||
const restaurantsSelector = (state) => state.restaurants.entities; | ||
const orderSelector = (state) => state.order; | ||
export const orderSelector = (state) => state.order.entities; | ||
const productsSelector = (state) => state.products.entities; | ||
const reviewsSelector = (state) => state.reviews.entities; | ||
const usersSelector = (state) => state.users.entities; | ||
const historyRouterSelector = (state) => state.router; | ||
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. в connected-react-router есть свои селекторы, которые можно так же использовать |
||
|
||
export const orderLoadingSelector = (state) => state.order.loading; | ||
export const errorOrderSelector = (state) => state.order.error; | ||
export const successOrderSelector = (state) => state.order.success; | ||
|
||
export const locationSelector = createSelector( | ||
historyRouterSelector, | ||
(history) => history.location | ||
); | ||
|
||
export const restaurantsLoadingSelector = (state) => state.restaurants.loading; | ||
export const restaurantsLoadedSelector = (state) => state.restaurants.loaded; | ||
|
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.
используйте селекторы