-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
155 lines (135 loc) · 6.88 KB
/
index.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Løftelikhet</title>
<script src="https://unpkg.com/react@latest/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@latest/dist/react-dom.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/4.0.2/bootstrap-material-design.css" />
<style>
.hdo-card {
background-color: #fff;
box-shadow: 0 -1px 0 #e5e5e5, 0 0 2px rgba(0,0,0,.12), 0 2px 4px rgba(0,0,0,.24);
margin-top: 2rem;
}
.hdo-card .hdo-card-header {
background-color: #fcfcfc;
margin-left: 0;
margin-right: 0;
padding: 1rem;
box-shadow: 0 1px rgba(0,0,0,.12);
height: 100%;
}
.hdo-card a {
color: inherit;
}
.pull-right { float: right; }
.nowrap { white-space: nowrap; }
</style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class PromiseFetcher extends React.Component {
state = { data: null };
static propTypes = {
children: React.PropTypes.func.isRequired
};
componentDidMount() {
fetch(`https://data.holderdeord.no/api/promises/${this.props.id}`)
.then(res => res.json())
.then(data => this.setState({data}))
}
render() {
if (!this.state.data) {
return null;
}
return this.props.children(this.state.data);
}
}
class App extends React.Component {
state = { min: 0, max: 30, data: null }
componentDidMount() {
fetch('data/result.json')
.then(res => res.json())
.then(data => this.setState({data: data}));
}
render() {
const { data } = this.state;
if (!data) {
return <p style={{padding: '3rem', margin: '0 auto', width: '100px'}}>Laster…</p>;
}
return (
<div style={{paddingBottom: '3rem'}}>
<nav className="navbar fixed-top navbar-light bg-faded">
<div className="container">
<div className="navbar-brand">
Løftelikhet
</div>
</div>
</nav>
<div className="container p-t-1">
{data.slice(this.state.min, this.state.max).map(p => (
<PromiseFetcher key={p.id} id={p.id}>
{promise => (
<div className="row hdo-card">
<div className="col-md-3">
<div className="hdo-card-header">
<em><a href={`//data.holderdeord.no/promises/${p.id}`}>{promise.body}</a></em>
<div><small className="text-muted">{promise.promisor_name}, {promise.parliament_period_name}</small></div>
</div>
</div>
<div className="col-md-9">
<small className="p-a-3">
{p.related.length ? (
<table className="table table-sm">
<thead>
<tr>
<th>Likhet</th>
<th>Løfte</th>
<th>Hvem</th>
<th>Når</th>
</tr>
</thead>
<tbody>
{p.related.map(r => (
<PromiseFetcher key={r.id} id={r.id}>
{relatedPromise => (
<tr>
<th>{(r.score * 100).toFixed(2)} %</th>
<td><em><a href={`//data.holderdeord.no/promises/${r.id}`}>{relatedPromise.body}</a></em></td>
<td className="nowrap">{relatedPromise.promisor_name}</td>
<td className="nowrap">{relatedPromise.parliament_period_name}</td>
</tr>
)}
</PromiseFetcher>
))}
</tbody>
</table>
) : null}
</small>
</div>
</div>
)}
</PromiseFetcher>
))}
<div className="row">
<div className="col-sm-12">
<div className="m-x-auto" style={{width: '200px'}}>
<div className="btn btn-primary" onClick={() => this.setState({max: this.state.max + 20})}>Last inn flere</div>
</div>
</div>
</div>
</div>
</div>
);
}
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
</script>
</body>
</html>