-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
61 lines (56 loc) · 1.51 KB
/
index.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
60
61
import 'bootstrap/dist/css/bootstrap.min.css'
import './style.css'
import './component/AppBar.js'
import './component/CardGroup.js'
import './component/TextLoading.js'
import api from './service'
import axios from 'axios'
const $ = (e) => {
e = document.querySelectorAll(e)
return e.length > 1 ? e : e[0]
}
const newCardGroup = ({title, expand, data}) => {
const cardGroup = document.createElement('card-group')
cardGroup.setAttribute('title', title)
cardGroup.setAttribute('expand', expand)
cardGroup.bind = data
return cardGroup
}
const searchForm = $('form')
const searchInput = $('input')[0]
const view = $('main')
searchForm.onsubmit = (event) => {
event.preventDefault()
searchInput.blur()
if(searchInput.value) {
view.innerHTML = ''
const loading = document.createElement('text-loading')
view.appendChild(loading)
api.search(searchInput.value).then(res => {
const cardGroup = newCardGroup({
title: `Results for "${searchInput.value}"`,
expand: 'vertikal',
data: res.data.data
})
view.appendChild(cardGroup)
$('text-loading').remove()
})
}
}
axios.all([
api.trending,
api.popular,
api.upcoming,
api.best,
api.popular
]).then((res) => {
const groupTitles = ["Trending", "Top Airing", "Top Upcoming", "Highest Rated", "Most Popular"]
groupTitles.forEach((title, index) => {
const cardGroup = newCardGroup({
title,
expand: 'horizontal',
data: res[index].data.data
})
view.appendChild(cardGroup)
})
})