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.js124
1 files changed, 62 insertions, 62 deletions
diff --git a/vnext/src/App.js b/vnext/src/App.js
index 125b6fda..e723fe9c 100644
--- a/vnext/src/App.js
+++ b/vnext/src/App.js
@@ -1,25 +1,25 @@
-import { useState, useEffect, useRef, Fragment, useCallback } from 'react';
-import { Route, Link, Routes, useSearchParams } from 'react-router-dom';
+import { useState, useEffect, useRef, Fragment, useCallback } from 'react'
+import { Route, Link, Routes, useSearchParams } from 'react-router-dom'
-import svg4everybody from 'svg4everybody';
+import svg4everybody from 'svg4everybody'
-import Icon from './ui/Icon';
-import { Discover, Discussions, Blog, Tag, Home } from './ui/Feeds';
-import { Friends, Readers } from './ui/Users';
-import Settings from './ui/Settings';
-import Contacts from './ui/Contacts';
-import Chat from './ui/Chat';
-import Header from './ui/Header';
-import Post from './ui/Post';
-import Thread from './ui/Thread';
-import Login from './ui/Login';
+import Icon from './ui/Icon'
+import { Discover, Discussions, Blog, Tag, Home } from './ui/Feeds'
+import { Friends, Readers } from './ui/Users'
+import Settings from './ui/Settings'
+import Contacts from './ui/Contacts'
+import Chat from './ui/Chat'
+import Header from './ui/Header'
+import Post from './ui/Post'
+import Thread from './ui/Thread'
+import Login from './ui/Login'
-import { useCookies } from 'react-cookie';
+import { useCookies } from 'react-cookie'
-import { me, trends } from './api';
-import { useVisitor } from './ui/VisitorContext';
-import Avatar from './ui/Avatar';
-import { Toaster } from 'react-hot-toast';
+import { me, trends } from './api'
+import { useVisitor } from './ui/VisitorContext'
+import Avatar from './ui/Avatar'
+import { Toaster } from 'react-hot-toast'
/**
*
@@ -29,34 +29,34 @@ import { Toaster } from 'react-hot-toast';
*/
export default function App({ footer }) {
- let contentRef = useRef(null);
- const [cookie, setCookie] = useCookies(['hash']);
+ let contentRef = useRef(null)
+ const [cookie, setCookie] = useCookies(['hash'])
- const [allTrends, setAllTrends] = useState([]);
+ const [allTrends, setAllTrends] = useState([])
- const [visitor, setVisitor] = useVisitor();
+ const [visitor, setVisitor] = useVisitor()
- const params = useSearchParams();
+ const params = useSearchParams()
useEffect(() => {
- svg4everybody();
+ svg4everybody()
if (params['hash']) {
- setCookie('hash', params['hash'], { path: '/' });
- let retpath = params['retpath'] || `${window.location.protocol}//${window.location.host}${window.location.pathname}`;
- window.history.replaceState({}, document.title, retpath);
+ setCookie('hash', params['hash'], { path: '/' })
+ let retpath = params['retpath'] || `${window.location.protocol}//${window.location.host}${window.location.pathname}`
+ window.history.replaceState({}, document.title, retpath)
}
- }, [setCookie, footer, params]);
+ }, [setCookie, footer, params])
let updateStatus = useCallback(() => {
// refresh server visitor state (unread counters)
me().then(visitor => {
- setVisitor(visitor);
- }).catch(console.error);
- }, [setVisitor]);
+ setVisitor(visitor)
+ }).catch(console.error)
+ }, [setVisitor])
- const [hash, setHash] = useState(cookie.hash);
+ const [hash, setHash] = useState(cookie.hash)
- const [eventSource, setEventSource] = /** @param EventSource? */ useState({});
+ const [eventSource, setEventSource] = /** @param EventSource? */ useState({})
/**
* @param {import("./api").SecureUser} visitor
@@ -64,53 +64,53 @@ export default function App({ footer }) {
let auth = useCallback((visitor) => {
setVisitor(prevState => {
if (visitor.hash != prevState.hash) {
- setHash(visitor.hash);
+ setHash(visitor.hash)
}
- return visitor;
- });
- }, [setVisitor]);
+ return visitor
+ })
+ }, [setVisitor])
useEffect(() => {
- let es;
+ let es
const anonymousUser = {
uid: 0
- };
+ }
if (hash) {
me().then(visitor => auth(visitor))
- .catch(() => setVisitor(anonymousUser));
+ .catch(() => setVisitor(anonymousUser))
if ('EventSource' in window) {
- const eventParams = new URLSearchParams({ hash: hash });
- let url = new URL(`https://juick.com/api/events?${eventParams.toString()}`);
- console.log(url.toString());
- es = new EventSource(url.toString());
+ const eventParams = new URLSearchParams({ hash: hash })
+ let url = new URL(`https://juick.com/api/events?${eventParams.toString()}`)
+ console.log(url.toString())
+ es = new EventSource(url.toString())
es.onopen = () => {
- console.log('online');
- };
+ console.log('online')
+ }
es.onerror = () => {
- es.removeEventListener('read', updateStatus);
- es.removeEventListener('msg', updateStatus);
- };
- es.addEventListener('read', updateStatus);
- es.addEventListener('msg', updateStatus);
- setEventSource(es);
+ es.removeEventListener('read', updateStatus)
+ es.removeEventListener('msg', updateStatus)
+ }
+ es.addEventListener('read', updateStatus)
+ es.addEventListener('msg', updateStatus)
+ setEventSource(es)
}
} else {
- setVisitor(anonymousUser);
+ setVisitor(anonymousUser)
}
return (() => {
if (es && es.removeEventListener) {
- es.removeEventListener('read', updateStatus);
- es.removeEventListener('msg', updateStatus);
+ es.removeEventListener('read', updateStatus)
+ es.removeEventListener('msg', updateStatus)
}
- });
- }, [auth, hash, setVisitor, updateStatus]);
+ })
+ }, [auth, hash, setVisitor, updateStatus])
useEffect(() => {
const getTrends = async () => {
- setAllTrends(await trends());
- };
- getTrends().catch(console.error);
- }, []);
+ setAllTrends(await trends())
+ }
+ getTrends().catch(console.error)
+ }, [])
return (
<>
@@ -200,5 +200,5 @@ export default function App({ footer }) {
</Routes>
</section>
</>
- );
+ )
}