Browse Source

Redirect to home on invalid topic url

develop
Apostolos Fanakis 4 years ago
parent
commit
4e372974c4
  1. 9
      packages/concordia-app/src/views/Topic/TopicView/index.jsx

9
packages/concordia-app/src/views/Topic/TopicView/index.jsx

@ -6,6 +6,7 @@ import {
} from 'semantic-ui-react'; } from 'semantic-ui-react';
import moment from 'moment'; import moment from 'moment';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { useHistory } from 'react-router';
import { breeze, drizzle } from '../../../redux/store'; import { breeze, drizzle } from '../../../redux/store';
import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions';
import './styles.css'; import './styles.css';
@ -37,6 +38,7 @@ const TopicView = (props) => {
const [timestamp, setTimestamp] = useState(initialTimestamp || null); const [timestamp, setTimestamp] = useState(initialTimestamp || null);
const [postIds, setPostIds] = useState(initialPostIds || null); const [postIds, setPostIds] = useState(initialPostIds || null);
const [topicSubject, setTopicSubject] = useState(null); const [topicSubject, setTopicSubject] = useState(null);
const history = useHistory();
const dispatch = useDispatch(); const dispatch = useDispatch();
useEffect(() => { useEffect(() => {
@ -54,6 +56,11 @@ const TopicView = (props) => {
useEffect(() => { useEffect(() => {
if (getTopicCallHash && getTopicResults && getTopicResults[getTopicCallHash]) { if (getTopicCallHash && getTopicResults && getTopicResults[getTopicCallHash]) {
if (getTopicResults[getTopicCallHash].value == null) {
history.push('/');
return;
}
setTopicAuthorAddress(getTopicResults[getTopicCallHash].value[0]); setTopicAuthorAddress(getTopicResults[getTopicCallHash].value[0]);
setTopicAuthor(getTopicResults[getTopicCallHash].value[1]); setTopicAuthor(getTopicResults[getTopicCallHash].value[1]);
setTimestamp(getTopicResults[getTopicCallHash].value[2]); setTimestamp(getTopicResults[getTopicCallHash].value[2]);
@ -71,7 +78,7 @@ const TopicView = (props) => {
}); });
} }
} }
}, [dispatch, getTopicCallHash, getTopicResults, topicId, topics, userAddress]); }, [dispatch, getTopicCallHash, getTopicResults, history, topicId, topics, userAddress]);
useEffect(() => { useEffect(() => {
if (topicAuthorAddress !== null) { if (topicAuthorAddress !== null) {

Loading…
Cancel
Save