Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Rasoul Madani
سایت آمازون با مانگو دی بی - ری اکت - نود جی اس - اکسپرس جی اس - الله
Commits
e59b6c68
Commit
e59b6c68
authored
May 03, 2021
by
Rasoul Madani
Browse files
فیلم15
parent
4314326c
Changes
6
Hide whitespace changes
Inline
Side-by-side
frontend/src/App.js
View file @
e59b6c68
import
"
./App.css
"
;
import
HomeScreen
from
"
./screens/HomeScreen
"
;
import
ProductScreen
from
"
./screens/ProductScreen
"
;
import
{
BrowserRouter
,
Route
}
from
"
react-router-dom
"
;
function
App
()
{
...
...
@@ -17,6 +18,7 @@ function App() {
<
/header
>
<
main
>
<
Route
path
=
"
/
"
component
=
{
HomeScreen
}
exact
><
/Route
>
<
Route
path
=
"
/product/:id
"
component
=
{
ProductScreen
}
><
/Route
>
<
/main
>
<
footer
className
=
"
row center
"
>
©
2020
All
right
reserved
.
<
/footer
>
<
/div
>
...
...
frontend/src/actions/productActions.js
View file @
e59b6c68
import
{
PRODUCT_LIST_REQUEST
,
PRODUCT_LIST_SUCCESS
,
PRODUCT_LIST_FAIL
PRODUCT_LIST_FAIL
,
PRODUCT_DETAILS_REQUEST
,
PRODUCT_DETAILS_SUCCESS
,
PRODUCT_DETAILS_FAIL
,
}
from
"
../constants/productConstants
"
;
import
Axios
from
"
axios
"
;
...
...
@@ -11,15 +14,19 @@ export const listProducts = () => async (dispatch) => {
});
try
{
const
{
data
}
=
await
Axios
.
get
(
"
/api/products
"
);
dispatch
({
type
:
PRODUCT_LIST_SUCCESS
,
payload
:
data
,
});
}
catch
(
khata
)
{
dispatch
({
type
:
PRODUCT_LIST_FAIL
,
payload
:
khata
.
message
})
dispatch
({
type
:
PRODUCT_LIST_FAIL
,
payload
:
khata
.
message
,
})
;
}
};
export
const
detailsProduct
=
(
productId
)
=>
(
dispatch
)
=>
{
dispatch
({
type
:
PRODUCT_DETAILS_REQUEST
});
};
frontend/src/constants/productConstants.js
View file @
e59b6c68
export
const
PRODUCT_LIST_REQUEST
=
"
PRODUCT_LIST_REQUEST
"
;
export
const
PRODUCT_LIST_SUCCESS
=
"
PRODUCT_LIST_SUCCESS
"
;
export
const
PRODUCT_LIST_FAIL
=
"
PRODUCT_LIST_FAIL
"
;
export
const
PRODUCT_DETAILS_REQUEST
=
"
PRODUCT_DETAILS_REQUEST
"
;
export
const
PRODUCT_DETAILS_SUCCESS
=
"
PRODUCT_DETAILS_SUCCESS
"
;
export
const
PRODUCT_DETAILS_FAIL
=
"
PRODUCT_DETAILS_FAIL
"
;
frontend/src/index.css
View file @
e59b6c68
...
...
@@ -8,6 +8,9 @@ body {
font-size
:
1.6rem
;
font-family
:
Helvetica
,
Arial
,
sans-serif
;
}
#root
{
height
:
100%
;
}
.grid-container
{
display
:
grid
;
grid-template-areas
:
...
...
frontend/src/reducers/productReducers.js
View file @
e59b6c68
import
{
PRODUCT_LIST_REQUEST
,
PRODUCT_LIST_SUCCESS
,
PRODUCT_LIST_FAIL
PRODUCT_LIST_FAIL
,
PRODUCT_DETAILS_REQUEST
}
from
"
../constants/productConstants
"
;
export
const
productListReducer
=
(
...
...
@@ -19,3 +20,15 @@ export const productListReducer = (
return
state
;
}
};
export
const
productDetailsReducer
=
(
state
=
{
product
:
{},
loading
:
true
},
action
)
=>
{
switch
(
action
.
type
){
case
PRODUCT_DETAILS_REQUEST
:
return
{
loading
:
true
}
default
:
return
state
}
};
frontend/src/screens/ProductScreen.js
0 → 100644
View file @
e59b6c68
import
{
useDispatch
}
from
"
react-redux
"
;
import
{
useEffect
}
from
"
react
"
;
import
{
detailsProduct
}
from
"
../actions/productActions
"
;
export
default
function
ProductScreen
(
props
)
{
const
productId
=
props
.
match
.
params
.
id
;
const
dispatch
=
useDispatch
();
useEffect
(()
=>
{
dispatch
(
detailsProduct
(
productId
));
},
[
dispatch
,
productId
]);
return
(
<
div
>
<
div
>
به
نام
ابر
برنامه
نویس
عالم
<
/div
>
<
div
>
{
productId
}
<
/div
>
<
/div
>
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment