File tree Expand file tree Collapse file tree 3 files changed +120
-10
lines changed Expand file tree Collapse file tree 3 files changed +120
-10
lines changed Original file line number Diff line number Diff line change @@ -115,12 +115,16 @@ JS AMAZONA
115115 1 . get product id from request
116116 2 . implement /api/product/: id api
117117 3 . send Ajax request to product api
118- 4 . create back to result link
119- 5 . create div.details with 3 columns
120- 6 . column 1 for product image
121- 7 . column 2 for product information
122- 8 . column 3 form product action
123- 9 . style .details and all columns
124- 10 . create add to cart button with add-button id
125- 11 . after_render() to add event to the button
126- 12 . redirect user to cart/: product_id
118+ 14 . Product Screen UI
119+ 1 . create back to result link
120+ 2 . create div.details with 3 columns
121+ 3 . column 1 for product image
122+ 4 . column 2 for product information
123+ 5 . column 3 form product action
124+ 6 . style .details and all columns
125+ 7 . create add to cart button with add-button id
126+ 15 . Product Screen Action
127+ 1 . after_render() to add event to the button
128+ 2 . add event handler for the button
129+ 3 . redirect user to cart/: product_id
130+ 4 . implement after_render in index.js
Original file line number Diff line number Diff line change 11import { parseRequestUrl } from '../utils' ;
22import { getProduct } from '../api' ;
3+ import Rating from '../components/Rating' ;
34
45const ProductScreen = {
56 render : async ( ) => {
@@ -8,7 +9,56 @@ const ProductScreen = {
89 if ( product . error ) {
910 return `<div>${ product . error } </div>` ;
1011 }
11- return `<h1>${ product . name } </h1>` ;
12+ return `
13+ <div class="content">
14+ <div class="back-to-result">
15+ <a href="/#/">Back to result </a>
16+ </div>
17+ <div class="details">
18+ <div class="details-image">
19+ <img src="${ product . image } " alt="${ product . name } " />
20+ </div>
21+ <div class="details-info">
22+ <ul>
23+ <li>
24+ <h1>${ product . name } </h1>
25+ </li>
26+ <li>
27+ ${ Rating . render ( {
28+ value : product . rating ,
29+ text : `${ product . numReviews } reviews` ,
30+ } ) }
31+ </li>
32+ <li>
33+ Price: <strong>$${ product . price } </strong>
34+ </li>
35+ <li>
36+ Description:
37+ <div>
38+ ${ product . description }
39+ </div>
40+ </li>
41+ </ul>
42+ </div>
43+ <div class="details-action">
44+ <ul>
45+ <li>
46+ Price: $${ product . price }
47+ </li>
48+ <li>
49+ Status :
50+ ${
51+ product . countInStock > 0
52+ ? `<span class="success">In Stock</span>`
53+ : `<span class="error">Unavailable</span>`
54+ }
55+ </li>
56+ <li>
57+ <button id="add-button" class="fw primary">Add to Cart </div>
58+ </ul>
59+ </div>
60+ </div>
61+ </div>` ;
1262 } ,
1363} ;
1464export default ProductScreen ;
Original file line number Diff line number Diff line change 1616a : hover {
1717 color : # f08040 ;
1818}
19+ button {
20+ font : 1.6rem helvetica;
21+ padding : 1rem ;
22+ border : 0.1rem # 808080 solid;
23+ border-radius : 0.5rem ;
24+ cursor : pointer;
25+ }
26+ button : hover {
27+ border : 0.1rem # 404040 solid;
28+ }
29+ button .primary {
30+ background-color : # f0c040 ;
31+ }
32+ .fw {
33+ width : 100% ;
34+ }
1935.grid-container {
2036 display : grid;
2137 grid-template-areas :
@@ -102,3 +118,43 @@ footer {
102118 color : # 444444 ;
103119 font-size : 1.4rem ;
104120}
121+ .content {
122+ padding : 1rem ;
123+ }
124+ /* Product Details */
125+ .details {
126+ display : flex;
127+ justify-content : space-between;
128+ align-items : flex-start;
129+ flex-wrap : wrap;
130+ }
131+ .details-image {
132+ flex : 2 1 60rem ;
133+ }
134+ .details-image img {
135+ max-width : 60rem ;
136+ width : 100% ;
137+ }
138+ .details-info ,
139+ .details-action {
140+ flex : 1 1 30rem ;
141+ }
142+ .details-info ul ,
143+ .details-action ul {
144+ padding : 0 ;
145+ list-style-type : none;
146+ }
147+ .details-info h1 {
148+ font-size : 2rem ;
149+ margin : 0 ;
150+ }
151+ .details-info li ,
152+ .details-action li {
153+ margin-bottom : 1rem ;
154+ }
155+ .details-action {
156+ border : 0.1rem # 808080 solid;
157+ border-radius : 0.5rem ;
158+ background-color : # f8f8f8 ;
159+ padding : 1rem ;
160+ }
You can’t perform that action at this time.
0 commit comments