aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vnext/src/App.js14
1 files changed, 7 insertions, 7 deletions
diff --git a/vnext/src/App.js b/vnext/src/App.js
index 51c255a6..483ec73c 100644
--- a/vnext/src/App.js
+++ b/vnext/src/App.js
@@ -12,7 +12,6 @@ import Post from './ui/Post';
import Thread from './ui/Thread';
import LoginButton from './ui/LoginButton';
import { UserLink } from './ui/UserInfo';
-import Header from './ui/Header';
import SearchBox from './ui/SearchBox';
import cookies from 'react-cookies';
@@ -37,16 +36,17 @@ export default function App() {
});
};
- const [es, setEs] = useState({});
+ const [eventSource, setEventSource] = useState({});
useEffect(() => {
const { hash } = visitor;
+ let es;
if (hash) {
me().then(visitor => auth(visitor));
if ('EventSource' in window) {
const eventParams = { hash: hash };
let url = new URL(`https://juick.com/api/events?${qs.stringify(eventParams)}`);
- let es = new EventSource(url);
+ es = new EventSource(url);
es.onopen = () => {
console.log('online');
};
@@ -56,11 +56,11 @@ export default function App() {
};
es.addEventListener('read', updateStatus);
es.addEventListener('msg', updateStatus);
- setEs(es);
+ setEventSource(es);
}
}
return (() => {
- if (es.removeEventListener) {
+ if (es && es.removeEventListener) {
es.removeEventListener('read', updateStatus);
es.removeEventListener('msg', updateStatus);
}
@@ -134,12 +134,12 @@ export default function App() {
} />
<Route exact path="/post" render={(props) => <Post visitor={visitor} {...props} />} />
<Route exact path="/pm" render={(props) => <Contacts visitor={visitor} {...props} />} />
- <Route exact path="/pm/:user" render={(props) => <Chat connection={es} visitor={visitor} {...props} />} />
+ <Route exact path="/pm/:user" render={(props) => <Chat connection={eventSource} visitor={visitor} {...props} />} />
<Route exact path="/:user/friends" render={(props) => <Friends visitor={visitor} {...props} />} />
<Route exact path="/:user/readers" render={(props) => <Readers visitor={visitor} {...props} />} />
<Route exact path="/:user" render={(props) => <Blog visitor={visitor} {...props} />} />
<Route exact path="/tag/:tag" render={(props) => <Tag visitor={visitor} {...props} />} />
- <Route exact path="/:user/:mid" render={(props) => <Thread connection={es} visitor={visitor} {...props} />} />
+ <Route exact path="/:user/:mid" render={(props) => <Thread connection={eventSource} visitor={visitor} {...props} />} />
</Switch>
</section>
{