@@ -2,9 +2,14 @@ import React, { Component } from "react";
2
2
import { Button } from "react-bootstrap" ;
3
3
import books from "../BooksPage/books.json" ;
4
4
5
+ import axios from "axios" ;
6
+
5
7
import Navbar from "../Navbar" ;
6
8
import Review from "./Review" ;
7
9
10
+ import Rater from "react-rater" ;
11
+ import "react-rater/lib/react-rater.css" ;
12
+
8
13
export default class BookDetails extends Component {
9
14
constructor ( props ) {
10
15
super ( props ) ;
@@ -16,12 +21,28 @@ export default class BookDetails extends Component {
16
21
17
22
this . handleChange = this . handleChange . bind ( this ) ;
18
23
this . handleSubmit = this . handleSubmit . bind ( this ) ;
24
+ this . handleChangeBuy = this . handleChangeBuy . bind ( this ) ;
25
+ this . handleRatingChange = this . handleRatingChange . bind ( this ) ;
19
26
20
- this . state = { review_list : [ ] , value : "" , item : books [ reqId - 1 ] } ;
27
+ this . state = {
28
+ review_list : [ ] ,
29
+ value : "" ,
30
+ value2 : "" ,
31
+ item : books [ reqId - 1 ] ,
32
+ rating : 0
33
+ } ;
21
34
22
35
//console.log(this.state.value);
23
36
}
24
37
38
+ handleRatingChange ( ) {
39
+ this . setState ( { rating : this . state . rating } ) ;
40
+
41
+ console . log ( this . state . rating ) ;
42
+
43
+ axios . get ( `http://localhost:5000/rate/${ this . reqId } /${ this . state . rating } ` ) ;
44
+ }
45
+
25
46
handleChange ( event ) {
26
47
this . setState ( { value : event . target . value } ) ;
27
48
}
@@ -33,6 +54,19 @@ export default class BookDetails extends Component {
33
54
this . setState ( { review_list : this . state . review_list } ) ;
34
55
}
35
56
57
+ handleChangeBuy ( event ) {
58
+ this . setState ( { value2 : event . target . value } ) ;
59
+ //console.log(this.state.value2);
60
+ }
61
+
62
+ handleSubmitBuy ( event ) {
63
+ event . preventDefault ( ) ;
64
+
65
+ axios . get (
66
+ `http://localhost:5000/addbook/${ this . reqId } /${ this . state . value2 } `
67
+ ) ;
68
+ }
69
+
36
70
render ( ) {
37
71
const reviews = this . state . review_list . map ( rev => {
38
72
return < Review data = { rev } /> ;
@@ -60,14 +94,37 @@ export default class BookDetails extends Component {
60
94
< h2 > - { this . state . item . author } </ h2 >
61
95
</ div >
62
96
< center style = { { marginTop : "12em" } } >
63
- < Button size = "lg" className = "outline-dark" >
64
- Buy for { this . state . item . price }
65
- </ Button >
97
+ < form onSubmit = { this . handleOnBuy } >
98
+ < label style = { { paddingRight : "5px" } } >
99
+ Enter your private key :
100
+ </ label >
101
+ < input
102
+ type = "text"
103
+ placeholder = "enter your key"
104
+ value2 = { this . state . value2 }
105
+ onChange = { this . handleChangeBuy }
106
+ > </ input >
107
+
108
+ < Button type = "Submit" size = "lg" className = "outline-dark" >
109
+ Buy for { this . state . item . price }
110
+ </ Button >
111
+ </ form >
66
112
</ center >
67
113
</ div >
68
114
</ div >
69
115
< div className = "review-add-container" >
70
116
< h2 > Book Review</ h2 >
117
+ < div >
118
+ < h4 > Provide star rating</ h4 >
119
+ < Rater
120
+ total = { 10 }
121
+ name = "rating"
122
+ rating = { this . state . rating }
123
+ interactive = { true }
124
+ value = { this . state . rating }
125
+ onChange = { this . handleRatingChange }
126
+ > </ Rater >
127
+ </ div >
71
128
< div >
72
129
< form onSubmit = { this . handleSubmit } >
73
130
< label > Add you review here..</ label >
0 commit comments