-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
159 lines (141 loc) · 4.29 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
156
157
158
159
<!DOCTYPE html>
<html lang="en">
<title>WWWRPG DEBUGGER</title>
<!-- Load React API -->
<script src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<!-- Load React DOM-->
<script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<!-- Load Babel Compiler -->
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<!-- First time bootstrap user, yo! -->
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous"
/>
<style>
.url-form {
width: 100%;
display: block;
}
</style>
<body>
<div id="root"></div>
<script type="text/babel">
class SearchForm extends React.Component {
constructor(props) {
super(props);
this.state = {
value: window.location.pathname.replace('/debug/', ''),
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(e) {
this.setState({
value: e.target.value,
});
}
handleSubmit(e) {
e.preventDefault();
window.location.href = `/debug/${this.state.value}`;
}
render() {
const { value } = this.state;
return (
<form onSubmit={this.handleSubmit} className="url-form">
<div className="input-group">
<div className="input-group-prepend">
<span
className="input-group-text"
id="basic-addon1"
>
URL to crawl
</span>
</div>
<input
className="form-control"
value={value}
onChange={this.handleChange}
placeholder="https://yoursite.com"
/>
</div>
</form>
);
}
}
class Welcome extends React.Component {
constructor(props) {
super(props);
this.state = {
data: {},
path: window.location.pathname.replace('/debug/', ''),
hasSearched: false,
isLoading: true,
};
}
componentDidMount() {
this.setState({ isLoading: true });
if (this.state.path) {
fetch(`/crawl/${this.state.path}`)
.then(response => response.json())
.then(data =>
this.setState({
data,
isLoading: false,
hasSearched: true,
}),
)
.catch(error =>
this.setState({
error,
isLoading: false,
hasSearched: true,
}),
);
} else {
this.setState({ isLoading: false });
}
}
render() {
const { data, hasSearched, isLoading } = this.state;
const { title = '', navigation = [] } = data;
if (isLoading) {
return <p>Loading ...</p>;
}
return (
<section>
<div class="input-group">
<SearchForm />
</div>
{hasSearched && (
<div>
<div className="jumbotron">
<h1 className="display-4">{title}</h1>
<p className="lead">Description here</p>
</div>
<p>Doors:</p>
<ul>
{navigation.map((n, i) => (
<li key={`${i}-${n.url}`}>
🚪 <a href={`/debug/${n.url}`}>{n.text}</a>
</li>
))}
</ul>
</div>
)}
</section>
);
}
}
ReactDOM.render(<Welcome />, document.getElementById('root'));
</script>
</body>
</html>