-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
59 lines (51 loc) · 1.71 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Component } from 'preact'
import { Source } from './source'
export class BookCitation extends Component {
state = {
text: '',
sources: []
}
findBook = () => {
console.log('kek')
let { text } = this.state
let url = 'https://www.googleapis.com/books/v1/volumes?q='
+ encodeURIComponent(text)
fetch(url)
.then(data => data.json())
.then(data => this.setState({sources: data.items}))
}
preventDefault = e => {
e.preventDefault()
}
inputChanged = i => {
this.setState({
text: i.target.value
})
}
render({}, { text, sources }) {
return (
<div class="container">
<br />
<h2>Book Citation</h2>
<form class="multi-input" width="100%" onSubmit={this.preventDefault}>
<input class="input" type="text" onInput={this.inputChanged} value={text} />
<button
type="submit"
class="button input"
onClick={this.findBook}>Search</button>
</form>
<div>
{ sources.map(({volumeInfo}) =>
<Source
title={volumeInfo.title}
author={volumeInfo.authors}
publisher={volumeInfo.publisher}
pubdate={volumeInfo.publishedDate}
thumb={volumeInfo.imageLinks.thumbnail}
preview={volumeInfo.previewLink} />)
}
</div>
</div>
)
}
}