From 8887e1b51565b992f34c955c459125eb85b28483 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 31 Oct 2022 22:48:30 +0300 Subject: `useVisitor` hook --- vnext/src/ui/Feeds.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'vnext/src/ui/Feeds.js') diff --git a/vnext/src/ui/Feeds.js b/vnext/src/ui/Feeds.js index 84319c28..75f1800d 100644 --- a/vnext/src/ui/Feeds.js +++ b/vnext/src/ui/Feeds.js @@ -10,6 +10,7 @@ import Spinner from './Spinner'; import UserInfo from './UserInfo'; import { getMessages } from '../api'; +import { useVisitor } from './VisitorContext'; /** * @typedef {object} Query @@ -21,12 +22,12 @@ import { getMessages } from '../api'; /** * @typedef {object} PageProps * @property {string=} search - * @property {import('../api').SecureUser} visitor * @property {import('../api').Message[]=} msgs */ -function RequireAuth({ visitor, children }) { +function RequireAuth({ children }) { let location = useLocation(); + let [ visitor ] = useVisitor(); if (!visitor.hash) { // Redirect them to the /login page, but save the current location they were // trying to go to when they were redirected. This allows us to send them @@ -41,7 +42,7 @@ function RequireAuth({ visitor, children }) { /** * @param {PageProps} props */ -export function Discover({ visitor }) { +export function Discover() { const location = useLocation(); let search = qs.parse(location.search.substring(1)); const query = { @@ -49,24 +50,24 @@ export function Discover({ visitor }) { search: search, pageParam: search.search ? 'page' : 'before_mid' }; - return (); + return (); } /** * @param {PageProps} props */ -export function Discussions({ visitor }) { +export function Discussions() { const query = { baseUrl: '/api/messages/discussions', pageParam: 'to' }; - return (); + return (); } /** * @param {PageProps} props */ -export function Blog({ visitor }) { +export function Blog() { const { user } = useParams(); const location = useLocation(); const search = { @@ -83,7 +84,7 @@ export function Blog({ visitor }) {
- + ); } @@ -91,7 +92,7 @@ export function Blog({ visitor }) { /** * @param {PageProps} props */ -export function Tag({ visitor }) { +export function Tag() { const params = useParams(); const { tag } = params; const query = { @@ -101,27 +102,26 @@ export function Tag({ visitor }) { }, pageParam: 'before_mid' }; - return (); + return (); } /** * @param {PageProps} props */ -export function Home({ visitor }) { +export function Home() { const query = { baseUrl: '/api/home', pageParam: 'before_mid' }; return ( - - + + ); } /** * @typedef {object} FeedState - * @property { import('../api').SecureUser } visitor * @property { import('../api').Message[]= } msgs * @property { Query} query */ @@ -129,8 +129,9 @@ export function Home({ visitor }) { /** * @param {FeedState} props */ -function Feed({ visitor, query }) { +function Feed({ query }) { const location = useLocation(); + const [visitor] = useVisitor(); const [state, setState] = useState({ hash: visitor.hash, msgs: [], -- cgit v1.2.3