diff --git a/src/components/single-post.jsx b/src/components/single-post.jsx index 240bf54a..d5ce7af3 100644 --- a/src/components/single-post.jsx +++ b/src/components/single-post.jsx @@ -1,5 +1,5 @@ /* global CONFIG */ -import { Component, useMemo } from 'react'; +import { useEffect, useMemo } from 'react'; import { Link } from 'react-router'; import { connect } from 'react-redux'; import { Helmet } from 'react-helmet'; @@ -12,9 +12,11 @@ import Post from './post/post'; import { SignInLink } from './sign-in-link'; import { PostContextProvider } from './post/post-context'; -class SinglePostHandler extends Component { - UNSAFE_componentWillReceiveProps(nextProps) { - const { post, router, routeLoadingState } = nextProps; +function SinglePostHandler(props) { + const { post, router, routeLoadingState } = props; + + // Replace URL to the canonical one, if necessary + useEffect(() => { if (!post || routeLoadingState) { return; } @@ -23,63 +25,58 @@ class SinglePostHandler extends Component { if (pathname !== canonicalPostURI) { router.replace(canonicalPostURI + search + hash); } + }, [post, routeLoadingState, router]); + + let postBody =
; + + if (props.errorString?.includes('You can not see this post')) { + return ; + } else if (props.errorString?.includes('Please sign in to view this post')) { + return ; + } else if (props.errorString?.startsWith('404:')) { + return ; + } else if (props.errorString) { + postBody =

{props.errorString}

; } - render() { - const { props } = this; - const { post } = props; - - let postBody =
; - - if (props.errorString?.includes('You can not see this post')) { - return ; - } else if (props.errorString?.includes('Please sign in to view this post')) { - return ; - } else if (props.errorString?.startsWith('404:')) { - return ; - } else if (props.errorString) { - postBody =

{props.errorString}

; - } - - if (post) { - postBody = ( - - - - ); - } - - return ( -
-
- {props.boxHeader} -
-
{postBody}
-
-
+ if (props.post) { + postBody = ( + + + ); } + + return ( +
+
+ {props.boxHeader} +
+
{postBody}
+
+
+ ); } function selectState(state) {