diff options
Diffstat (limited to 'vnext/src/index.js')
-rw-r--r-- | vnext/src/index.js | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/vnext/src/index.js b/vnext/src/index.js index 963aa968..3a4fe494 100644 --- a/vnext/src/index.js +++ b/vnext/src/index.js @@ -11,9 +11,11 @@ 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 ( @@ -24,8 +26,8 @@ class App extends React.Component { <div id="header_wrapper"> {this.state.visitor.uid > 0 ? <div id="ctitle"> - <a href="/{this.state.visitor.name}"> - <img src="//i.juick.com/a/{this.state.visitor.uid}.png" alt="" />{this.state.visitor.name} + <a href={`/${this.state.visitor.uname}`}> + <img src={`//i.juick.com/a/${this.state.visitor.uid}.png`} alt="" />{this.state.visitor.uname} </a> </div> : @@ -56,9 +58,9 @@ class App extends React.Component { </nav> </div> </header> - <Route exact path="/" component={Discover} /> - <Route path="/:user/:mid" component={Thread} /> - <Route path="/post" component={Post} /> + <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 /> @@ -66,7 +68,20 @@ class App extends React.Component { ) } auth(data) { - console.log(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 + }) + }) + } } } |