blob: 3a4fe494c988837df1519f5aab0ecdca18479dc3 (
plain) (
blame)
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
|
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import Icon from './components/Icon';
import Discover from './components/Discover';
import Post from './components/Post';
import Thread from './components/Thread';
import LoginButton from './components/LoginButton';
import Footer from './components/Footer';
class App extends React.Component {
constructor(props) {
super(props);
this.auth = this.auth.bind(this);
this.state = {
visitor: { uid: 0 }
};
this.auth(window.localStorage.hash || '')
}
render() {
return (
<React.Fragment>
<Router>
<div className="wrapper">
<header>
<div id="header_wrapper">
{this.state.visitor.uid > 0 ?
<div id="ctitle">
<a href={`/${this.state.visitor.uname}`}>
<img src={`//i.juick.com/a/${this.state.visitor.uid}.png`} alt="" />{this.state.visitor.uname}
</a>
</div>
:
<div id="logo"><Link to="/">Juick</Link></div>
}
<div id="search">
<form action="/">
<input name="search" className="text"
placeholder="Search..." />
</form>
</div>
<nav id="global">
<ul>
{this.state.visitor.uid > 0 ?
<li><Link to={{ pathname: '/' }}><Icon name="ei-comment" size="s" />Discuss</Link></li>
:
<li><Link to='/?media=1' rel="nofollow"><Icon name="ei-camera" size="s" />Photos</Link></li>
}
<li><Link to={{ pathname: '/' }} rel="nofollow"><Icon name="ei-search" size="s" />Discover</Link></li>
<li>
{this.state.visitor.uid > 0 ?
<Link to={{ pathname: '/post' }}><Icon name="ei-pencil" size="s" />Post</Link>
:
<LoginButton title="Login" onAuth={this.auth.bind(this)} />
}
</li>
</ul>
</nav>
</div>
</header>
<Route exact path="/" render={(props) => <Discover visitor={this.state.visitor} {...props} />} />
<Route path="/:user/:mid" render={(props) => <Thread visitor={this.state.visitor} {...props} />} />
<Route path="/post" render={(props) => <Post visitor={this.state.visitor} {...props} />} />
</div>
</Router>
<Footer />
</React.Fragment>
)
}
auth(data) {
if (data) {
window.localStorage.hash = data;
fetch(`https://api.juick.com/users?hash=${data}`)
.then(response => {
return response.json()
})
.then(users => {
let visitor = users[0]
visitor.hash = data
this.setState({
visitor: visitor
})
})
}
}
}
ReactDOM.render(<App />, document.getElementById('wrapper'));
|