Merge pull request #600 from omnivore-app/fix/subfolder-404s

Better handling of 404 errors
This commit is contained in:
Jackson Harper 2022-05-12 14:57:00 -07:00 committed by GitHub
commit 394a558e45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View file

@ -19,8 +19,8 @@ type ArticleQueryInput = {
type ArticleQueryOutput = {
articleData?: ArticleData
articleFetchError: unknown
isLoading: boolean
articleFetchError: string[] | null
}
type ArticleData = {
@ -113,8 +113,8 @@ export function useGetArticleQuery({
return {
articleData: resultData,
articleFetchError: resultError as unknown,
isLoading: !error && !data,
articleFetchError: resultError ? resultError as string[] : null,
}
}

View file

@ -42,17 +42,15 @@ export default function Home(): JSX.Element {
const scrollRef = useRef<HTMLDivElement | null>(null)
const { slug } = router.query
const [showHighlightsModal, setShowHighlightsModal] = useState(false)
const { viewerData } = useGetViewerQuery()
const readerSettings = useReaderSettings()
const { articleData } = useGetArticleQuery({
const { articleData, articleFetchError } = useGetArticleQuery({
username: router.query.username as string,
slug: router.query.slug as string,
includeFriendsHighlights: false,
})
const article = articleData?.article.article
const [labels, setLabels] = useState<Label[]>([])
useEffect(() => {
if (article?.labels) {
@ -118,6 +116,11 @@ export default function Home(): JSX.Element {
}
}, [article, viewerData])
if (articleFetchError && articleFetchError.indexOf('NOT_FOUND') > -1) {
router.push('/404')
return <LoadingView />
}
return (
<PrimaryLayout
pageTestId="home-page-tag"