aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/App.js
diff options
context:
space:
mode:
Diffstat (limited to 'vnext/src/App.js')
-rw-r--r--vnext/src/App.js18
1 files changed, 11 insertions, 7 deletions
diff --git a/vnext/src/App.js b/vnext/src/App.js
index 483ec73c..bad57fc4 100644
--- a/vnext/src/App.js
+++ b/vnext/src/App.js
@@ -14,19 +14,18 @@ import LoginButton from './ui/LoginButton';
import { UserLink } from './ui/UserInfo';
import SearchBox from './ui/SearchBox';
-import cookies from 'react-cookies';
+import cookie from 'react-cookies';
import { me } from './api';
export default function App() {
let params = qs.parse(window.location.search.substring(1));
if (params.hash) {
- cookies.save('hash', params.hash, { path: '/' });
+ cookie.save('hash', params.hash, { path: '/' });
window.history.replaceState({}, document.title, `${window.location.protocol}//${window.location.host}${window.location.pathname}`);
}
const [visitor, setVisitor] = useState({
- uid: 0,
- hash: cookies.load('hash')
+ uid: 0
});
let updateStatus = () => {
@@ -36,10 +35,10 @@ export default function App() {
});
};
+ const [hash, setHash] = useState(cookie.load('hash'));
const [eventSource, setEventSource] = useState({});
useEffect(() => {
- const { hash } = visitor;
let es;
if (hash) {
me().then(visitor => auth(visitor));
@@ -65,7 +64,7 @@ export default function App() {
es.removeEventListener('msg', updateStatus);
}
});
- }, [visitor.hash]);
+ }, [hash]);
let search = (history, pathname, searchString) => {
let location = {};
@@ -74,7 +73,12 @@ export default function App() {
history.push(location);
};
let auth = (visitor) => {
- setVisitor(visitor);
+ setVisitor(prevState => {
+ if (visitor.hash != prevState.hash) {
+ setHash(visitor.hash);
+ }
+ return visitor;
+ });
};
return (
<Router>