From 40b8cd9853dd87deb90afdda0f5af78faa414f2b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 27 Jun 2018 14:33:34 +0300 Subject: fetch -> axios --- vnext/src/index.js | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'vnext/src/index.js') diff --git a/vnext/src/index.js b/vnext/src/index.js index aeb5357f..9527178e 100644 --- a/vnext/src/index.js +++ b/vnext/src/index.js @@ -20,19 +20,16 @@ class App extends React.Component { super(props); let params = qs.parse(window.location.search) if (params.hash) { - window.localStorage.hash = params.hash window.history.replaceState({}, document.title, `${window.location.protocol}//${window.location.host}${window.location.pathname}`) } this.state = { - visitor: { - uid: Number(window.localStorage.uid) || 0, - hash: window.localStorage.hash || params.hash || '' + visitor: localStorage.visitor ? JSON.parse(localStorage.visitor) : { + uid: 0, + hash: params.hash || '' } }; } - componentDidMount() { - this.auth(this.state.visitor.hash) - } + render() { const user = this.state.visitor; return ( @@ -156,25 +153,10 @@ class App extends React.Component { ) } - 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; - window.localStorage.uid = visitor.uid; - this.setState({ - visitor: visitor - }) - }).catch(reason => { - window.localStorage.clear() - window.location.reload() - }) - } + auth = (visitor) => { + this.setState({ + visitor: visitor + }) } } -- cgit v1.2.3