From 4e372974c4f51244f904d61fcb109d9d50a656ed Mon Sep 17 00:00:00 2001 From: Apostolof Date: Thu, 19 Nov 2020 22:28:16 +0200 Subject: [PATCH] Redirect to home on invalid topic url --- .../concordia-app/src/views/Topic/TopicView/index.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/concordia-app/src/views/Topic/TopicView/index.jsx b/packages/concordia-app/src/views/Topic/TopicView/index.jsx index 885fb82..79a6109 100644 --- a/packages/concordia-app/src/views/Topic/TopicView/index.jsx +++ b/packages/concordia-app/src/views/Topic/TopicView/index.jsx @@ -6,6 +6,7 @@ import { } from 'semantic-ui-react'; import moment from 'moment'; import { Link } from 'react-router-dom'; +import { useHistory } from 'react-router'; import { breeze, drizzle } from '../../../redux/store'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import './styles.css'; @@ -37,6 +38,7 @@ const TopicView = (props) => { const [timestamp, setTimestamp] = useState(initialTimestamp || null); const [postIds, setPostIds] = useState(initialPostIds || null); const [topicSubject, setTopicSubject] = useState(null); + const history = useHistory(); const dispatch = useDispatch(); useEffect(() => { @@ -54,6 +56,11 @@ const TopicView = (props) => { useEffect(() => { if (getTopicCallHash && getTopicResults && getTopicResults[getTopicCallHash]) { + if (getTopicResults[getTopicCallHash].value == null) { + history.push('/'); + return; + } + setTopicAuthorAddress(getTopicResults[getTopicCallHash].value[0]); setTopicAuthor(getTopicResults[getTopicCallHash].value[1]); 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(() => { if (topicAuthorAddress !== null) {