aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/index.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-06-27 14:33:34 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:53 +0300
commit40b8cd9853dd87deb90afdda0f5af78faa414f2b (patch)
treef4beb12efd422f178cfe168367ef91b17f6131b8 /vnext/src/index.js
parent8307e220c4fdddbc0a9740ad4b43fc2e205864bd (diff)
fetch -> axios
Diffstat (limited to 'vnext/src/index.js')
-rw-r--r--vnext/src/index.js34
1 files changed, 8 insertions, 26 deletions
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 {
</Router>
)
}
- 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
+ })
}
}