added "/post" route render

This commit is contained in:
plebbitor
2023-03-06 14:33:31 +01:00
parent 4b9a1a8ed5
commit 55f9461ad2
3 changed files with 50 additions and 11 deletions
+14 -1
View File
@@ -1,5 +1,5 @@
import React, { useState, useEffect, useContext } from 'react';
import { Link, useNavigate, useParams } from 'react-router-dom';
import { Link, useNavigate, useParams, useLocation } from 'react-router-dom';
import { Container, NavBar, Header, Break, PostForm, PostFormLink, PostFormTable } from './styles/Board.styled';
import { TopBar } from './styles/Thread.styled';
import { Threads } from './styles/Catalog.styled';
@@ -18,6 +18,7 @@ const Catalog = ({ setBodyStyle }) => {
const [subject, setSubject] = useState('');
const [comment, setComment] = useState('');
const navigate = useNavigate();
const location = useLocation();
const [prevScrollPos, setPrevScrollPos] = useState(0);
const [visible, setVisible] = useState(true);
const { publishComment } = useAccountsActions();
@@ -66,6 +67,18 @@ const Catalog = ({ setBodyStyle }) => {
return () => window.removeEventListener('scroll', handleScroll);
}, [prevScrollPos, visible]);
// post route handling
useEffect(() => {
const path = location.pathname;
if (path.endsWith('/post')) {
setShowPostFormLink(false);
setShowPostForm(true);
} else {
setShowPostFormLink(true);
setShowPostForm(false);
}
}, [location.pathname]);
const tryLoadMore = async () => {