diff options
Diffstat (limited to 'vnext/src/ui')
-rw-r--r-- | vnext/src/ui/Feeds.js | 1 | ||||
-rw-r--r-- | vnext/src/ui/Login.js | 4 | ||||
-rw-r--r-- | vnext/src/ui/Message.js | 8 | ||||
-rw-r--r-- | vnext/src/ui/VisitorContext.js | 17 |
4 files changed, 13 insertions, 17 deletions
diff --git a/vnext/src/ui/Feeds.js b/vnext/src/ui/Feeds.js index bb386e5a..16b6b534 100644 --- a/vnext/src/ui/Feeds.js +++ b/vnext/src/ui/Feeds.js @@ -160,7 +160,6 @@ function Feed({ query }) { const location = useLocation() const [visitor] = useVisitor() const [state, setState] = useState({ - hash: visitor.hash, msgs: [], nextpage: null, error: false, diff --git a/vnext/src/ui/Login.js b/vnext/src/ui/Login.js index 5d9908cb..ed0e990c 100644 --- a/vnext/src/ui/Login.js +++ b/vnext/src/ui/Login.js @@ -23,8 +23,8 @@ function Login({ onAuth }) { const navigate = useNavigate() const [visitor] = useVisitor() useEffect(() => { - if (visitor.hash) { - const {retpath } = location.state || '/' + if (visitor && visitor.hash) { + const retpath = location.state?.retpath || '/' console.log(retpath) navigate(retpath) } diff --git a/vnext/src/ui/Message.js b/vnext/src/ui/Message.js index e4135700..eba0f327 100644 --- a/vnext/src/ui/Message.js +++ b/vnext/src/ui/Message.js @@ -53,7 +53,7 @@ export default function Message({ data, isThread, onToggleSubscription, children } } }, []) - const canComment = data.user && visitor.uid === data.user.uid || !data.ReadOnly && visitor.uid > 0 + const canComment = data.user && visitor && visitor.uid === data.user.uid || !data.ReadOnly && visitor && visitor.uid > 0 || !data.ReadOnly && !isThread return ( <div className="msg-cont"> @@ -70,7 +70,7 @@ export default function Message({ data, isThread, onToggleSubscription, children </time> </Link> { - visitor.uid == data.user.uid && + visitor && visitor.uid == data.user.uid && <> <span> · </span> <Link to={{ @@ -100,13 +100,13 @@ export default function Message({ data, isThread, onToggleSubscription, children <div className="embedContainer" ref={embedRef} /> {canComment && <nav className="l"> - {data.user && visitor.uid === data.user.uid ? ( + {data.user && visitor && visitor.uid === data.user.uid ? ( <Link to={`/${data.user.uname}/${data.mid}`} className="a-like msg-button" state={{ data: data }}> <Icon name="ei-heart" size="s" /> <span>{likesSummary}</span> </Link> - ) : visitor.uid > 0 ? ( + ) : visitor && visitor.uid > 0 ? ( <Link to={'/post'} className="a-like msg-button"> <Icon name="ei-heart" size="s" /> <span>{likesSummary}</span> diff --git a/vnext/src/ui/VisitorContext.js b/vnext/src/ui/VisitorContext.js index 9740f9ca..a95090e5 100644 --- a/vnext/src/ui/VisitorContext.js +++ b/vnext/src/ui/VisitorContext.js @@ -2,23 +2,20 @@ import { createContext, useContext, useState } from 'react' const Visitor = createContext() -/** @type {import('../api').SecureUser} */ -const unknownUser = { - uid: -1 -} - /** - * @param { import('react').PropsWithChildren<{}> } props + * @param { import('react').PropsWithChildren<{}> & { + * auth?: import('../api').SecureUser + * }} props */ -export function VisitorProvider({ children }) { - const state = useState(unknownUser) +export function VisitorProvider({ auth, children }) { + const state = useState(auth) return <Visitor.Provider value={state}>{children}</Visitor.Provider> } /** * Visitor hook * @returns {[ - * import('../api').SecureUser, + * (import('../api').SecureUser|undefined), * import('react').Dispatch<import('react').SetStateAction<import('../api').SecureUser>> * ]} visitor hook */ @@ -28,4 +25,4 @@ export function useVisitor() { throw new Error('useVisitor must be used within a VisitorProvider') } return visitor -}
\ No newline at end of file +} |