Skip to content

Commit 213e535

Browse files
committed
final last moment changes..XD
1 parent 5c63c94 commit 213e535

File tree

10 files changed

+163
-12
lines changed

10 files changed

+163
-12
lines changed

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
"react-bootstrap": "^1.0.0-beta.14",
1111
"react-dom": "^16.10.2",
1212
"react-particles-js": "^2.7.0",
13+
"react-rater": "^5.1.1",
1314
"react-router-dom": "^5.1.2",
1415
"react-scripts": "3.2.0",
16+
"react-star-ratings": "^2.3.0",
1517
"web3": "^1.0.0-beta.55",
1618
"web3-eth": "^1.2.1"
1719
},

src/components/BookDetails/index.js

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import React, { Component } from "react";
22
import { Button } from "react-bootstrap";
33
import books from "../BooksPage/books.json";
44

5+
import axios from "axios";
6+
57
import Navbar from "../Navbar";
68
import Review from "./Review";
79

10+
import Rater from "react-rater";
11+
import "react-rater/lib/react-rater.css";
12+
813
export default class BookDetails extends Component {
914
constructor(props) {
1015
super(props);
@@ -16,12 +21,28 @@ export default class BookDetails extends Component {
1621

1722
this.handleChange = this.handleChange.bind(this);
1823
this.handleSubmit = this.handleSubmit.bind(this);
24+
this.handleChangeBuy = this.handleChangeBuy.bind(this);
25+
this.handleRatingChange = this.handleRatingChange.bind(this);
1926

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+
};
2134

2235
//console.log(this.state.value);
2336
}
2437

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+
2546
handleChange(event) {
2647
this.setState({ value: event.target.value });
2748
}
@@ -33,6 +54,19 @@ export default class BookDetails extends Component {
3354
this.setState({ review_list: this.state.review_list });
3455
}
3556

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+
3670
render() {
3771
const reviews = this.state.review_list.map(rev => {
3872
return <Review data={rev} />;
@@ -60,14 +94,37 @@ export default class BookDetails extends Component {
6094
<h2>- {this.state.item.author}</h2>
6195
</div>
6296
<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>
66112
</center>
67113
</div>
68114
</div>
69115
<div className="review-add-container">
70116
<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>
71128
<div>
72129
<form onSubmit={this.handleSubmit}>
73130
<label>Add you review here..</label>

src/components/BooksPage/AddBook/index.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export default class AddBook extends Component {
1313
account: "",
1414
booknameValue: "",
1515
bookpriceValue: 0,
16-
bookcoverValue: ""
16+
bookcoverValue: "",
17+
authoraddr: ""
1718
};
1819
}
1920

@@ -29,19 +30,21 @@ export default class AddBook extends Component {
2930
account,
3031
booknameValue,
3132
bookpriceValue,
32-
bookcoverValue
33+
bookcoverValue,
34+
authoraddr
3335
} = this.state;
3436
const book = {
3537
account,
3638
booknameValue,
3739
bookpriceValue,
38-
bookcoverValue
40+
bookcoverValue,
41+
authoraddr
3942
};
4043

4144
console.log(book);
4245

4346
axios.get(
44-
`http://localhost:5000/${book.bookpriceValue}/${book.booknameValue}/${book.bookcoverValue}`
47+
`http://localhost:5000/createbook/${book.authoraddr}/${book.bookpriceValue}/${book.booknameValue}/${book.bookcoverValue}`
4548
);
4649

4750
//snail adding to db here
@@ -50,7 +53,8 @@ export default class AddBook extends Component {
5053
bookpublisherValue: "",
5154
booknameValue: "",
5255
bookpriceValue: 0,
53-
bookcoverValue: ""
56+
bookcoverValue: "",
57+
authoraddr: ""
5458
});
5559
};
5660

@@ -96,6 +100,16 @@ export default class AddBook extends Component {
96100
onChange={this.onChange}
97101
/>
98102
</Form.Group>
103+
<Form.Group>
104+
<Form.Label>Author Address</Form.Label>
105+
<Form.Control
106+
type="text"
107+
name="authoraddr"
108+
placeholder="add the address of the author"
109+
value={this.state.authoraddr}
110+
onChange={this.onChange}
111+
/>
112+
</Form.Group>
99113
<Button variant="dark" type="submit">
100114
Submit
101115
</Button>

src/components/BooksPage/BookListItem/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default class BookListItem extends Component {
1010
<div className="row">
1111
<div className="col-md-8">
1212
<p style={{ fontWeight: "bold" }}>{this.props.item.title}</p>
13-
<p>copies sold : 24</p>
13+
<p>copies sold : {this.props.item.nBuys}</p>
1414
</div>
1515
<div className="col-md-4">
1616
<Button

src/components/HomePage/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default class HomePage extends Component {
1919
>
2020
<div className="home-title">
2121
<center style={{ marginTop: "20%" }}>
22-
<h1>HeadOut Book Store</h1>
22+
<h1>HackOut Book Store</h1>
2323
<h2>
2424
<a href="/books">Go to Store</a>
2525
</h2>

src/components/Navbar/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class Navbar1 extends Component {
3434
<Nav.Link href="/books">Store</Nav.Link>
3535
</Nav>
3636
<Nav>
37-
<Nav.Link>{this.state.account}</Nav.Link>
37+
<Nav.Link href="/user">{this.state.account}</Nav.Link>
3838
</Nav>
3939
</Navbar.Collapse>
4040
</Navbar>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, { Component } from "react";
2+
3+
export default class UserBookItem extends Component {
4+
render() {
5+
return (
6+
<tr>
7+
<td>{this.props.item.bookid}</td>
8+
<td>{this.props.item.title}</td>
9+
<td>{this.props.item.rating}</td>
10+
<td>{this.props.item.price}</td>
11+
</tr>
12+
);
13+
}
14+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, { Component } from "react";
2+
3+
import Navbar from "../Navbar";
4+
import axios from "axios";
5+
import UserBookItem from "./UserBookItem";
6+
7+
import { Table } from "react-bootstrap";
8+
9+
export default class UserBookList extends Component {
10+
render() {
11+
var bookItem = [];
12+
axios.get("http://localhost:5000/getuserbooks").then(response => {
13+
bookItem = response.data.map(item => {
14+
return <UserBookItem item={item} />;
15+
});
16+
});
17+
18+
return (
19+
<div>
20+
<div className="nav-bar">
21+
<Navbar />
22+
</div>
23+
24+
<div className="main-content container" style={{ paddingTop: "40px" }}>
25+
<h1>List of Books user has bought</h1>
26+
<Table striped bordered hover>
27+
<thead>
28+
<tr>
29+
<th>#</th>
30+
<th>Book Name</th>
31+
<th>Author</th>
32+
<th>Rating</th>
33+
<th>Price</th>
34+
</tr>
35+
</thead>
36+
<tbody>{bookItem}</tbody>
37+
</Table>
38+
</div>
39+
</div>
40+
);
41+
}
42+
}

src/routes/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Page404 from "../components/Page404";
66
import BookDetails from "../components/BookDetails";
77
import AddBook from "../components/BooksPage/AddBook";
88
import HomePage from "../components/HomePage";
9+
import UserBookList from "../components/UserBookList";
910

1011
const IndexRoutes = () => {
1112
return (
@@ -14,6 +15,7 @@ const IndexRoutes = () => {
1415
<Route path="/books" component={BooksPage} />
1516
<Route path="/book/:id" component={BookDetails} />
1617
<Route path="/add" component={AddBook} />
18+
<Route path="/user" component={UserBookList} />
1719
<Route component={Page404} />
1820
</Switch>
1921
);

0 commit comments

Comments
 (0)