redux fix

main
Stepan Pilipenko 1 month ago
parent 76153eede8
commit d76e86ca32

@ -2,15 +2,19 @@ import { Container, CssBaseline, ThemeProvider } from '@mui/material'
import { Shop } from './pages/shop' import { Shop } from './pages/shop'
import { blue } from '@mui/material/colors' import { blue } from '@mui/material/colors'
import { theme } from './theme' import { theme } from './theme'
import { Provider } from 'react-redux'
import { store } from './store'
export const App = () => { export const App = () => {
return ( return (
<> <>
<CssBaseline /> <CssBaseline />
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
<Container maxWidth="md" sx={{ bgcolor: blue }}> <Provider store={store}>
<Shop /> <Container maxWidth="md" sx={{ bgcolor: blue }}>
</Container> <Shop />
</Container>
</Provider>
</ThemeProvider> </ThemeProvider>
</> </>
) )

@ -21,9 +21,10 @@ export const shopSlice = createSlice({
name: 'shop', name: 'shop',
initialState, initialState,
reducers: { reducers: {
// TODO: дописать action.payload.id
addToBasket: (state, action: PayloadAction<AddBasketAction>) => { addToBasket: (state, action: PayloadAction<AddBasketAction>) => {
state.products[action.payload.id].count -= action.payload.count state.products[0].count -= action.payload.count
state.products[action.payload.id].reserved += action.payload.count state.products[0].reserved += action.payload.count
}, },
}, },
extraReducers: builder => { extraReducers: builder => {

@ -1,4 +1,4 @@
import { memo, useCallback, useEffect, type JSX } from 'react' import { memo, useCallback, useEffect } from 'react'
import styles from './shop.module.css' import styles from './shop.module.css'
import { Box, Button } from '@mui/material' import { Box, Button } from '@mui/material'
import { useAppDispatch, useAppSelector } from '../../hooks' import { useAppDispatch, useAppSelector } from '../../hooks'
@ -22,7 +22,7 @@ export const Shop = memo(() => {
<Button variant="contained" onClick={handleClick}> <Button variant="contained" onClick={handleClick}>
{'Добавить в корзину'} {'Добавить в корзину'}
</Button> </Button>
<span className={styles.shop}>{String(products)}</span> <span className={styles.shop}>{JSON.stringify(products)}</span>
</Box> </Box>
) )
}) })

Loading…
Cancel
Save