Don't show error if no intro.md was found (#1221)

This commit is contained in:
Tilman Vatteroth 2021-05-03 21:56:44 +02:00 committed by GitHub
parent fcefb32f1b
commit e1d096ba1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 19 deletions

View file

@ -11,11 +11,20 @@ describe('Intro page', () => {
cy.visit('/') cy.visit('/')
}) })
describe('content', () => { describe('customizable content', () => {
it('fetches and shows the correct intro page content', () => { it('fetches and shows the correct intro page content', () => {
cy.getMarkdownBody() cy.getMarkdownBody()
.contains('test content') .contains('test content')
}) })
it('won\'t show anything if no content was found', () => {
cy.intercept('/mock-backend/public/intro.md', {
statusCode: 404
})
cy.get(`iframe[data-cy="documentIframe"]`)
.should('not.exist')
})
}) })
describe('features button', () => { describe('features button', () => {

View file

@ -9,20 +9,15 @@ import { useTranslation } from 'react-i18next'
import { fetchFrontPageContent } from '../requests' import { fetchFrontPageContent } from '../requests'
import { useCustomizeAssetsUrl } from '../../../hooks/common/use-customize-assets-url' import { useCustomizeAssetsUrl } from '../../../hooks/common/use-customize-assets-url'
const MARKDOWN_WHILE_LOADING = ':zzz: {message}' export const useIntroPageContent = (): string | undefined => {
const MARKDOWN_IF_ERROR = ':::danger\n' +
'{message}\n' +
':::'
export const useIntroPageContent = (): string => {
const { t } = useTranslation() const { t } = useTranslation()
const [content, setContent] = useState<string>(() => MARKDOWN_WHILE_LOADING.replace('{message}', t('landing.intro.markdownWhileLoading'))) const [content, setContent] = useState<string | undefined>(undefined)
const customizeAssetsUrl = useCustomizeAssetsUrl() const customizeAssetsUrl = useCustomizeAssetsUrl()
useEffect(() => { useEffect(() => {
fetchFrontPageContent(customizeAssetsUrl) fetchFrontPageContent(customizeAssetsUrl)
.then((content) => setContent(content)) .then((content) => setContent(content))
.catch(() => setContent(MARKDOWN_IF_ERROR.replace('{message}', t('landing.intro.markdownLoadingError')))) .catch(() => setContent(undefined))
}, [customizeAssetsUrl, t]) }, [customizeAssetsUrl, t])
return content return content

View file

@ -22,12 +22,12 @@ import { WaitSpinner } from '../common/wait-spinner/wait-spinner'
export const IntroPage: React.FC = () => { export const IntroPage: React.FC = () => {
const introPageContent = useIntroPageContent() const introPageContent = useIntroPageContent()
const [showSpinner, setShowSpinner] = useState<boolean>(true) const [rendererReady, setRendererReady] = useState<boolean>(true)
return ( return (
<Fragment> <Fragment>
<div className={ 'flex-fill mt-3' }> <div className={ 'flex-fill mt-3' }>
<h1 dir='auto' className={ 'align-items-center d-flex justify-content-center flex-column' }> <h1 dir="auto" className={ 'align-items-center d-flex justify-content-center flex-column' }>
<HedgeDocLogoWithText logoType={ HedgeDocLogoType.COLOR_VERTICAL } size={ HedgeDocLogoSize.BIG }/> <HedgeDocLogoWithText logoType={ HedgeDocLogoType.COLOR_VERTICAL } size={ HedgeDocLogoSize.BIG }/>
</h1> </h1>
<p className="lead"> <p className="lead">
@ -37,16 +37,18 @@ export const IntroPage: React.FC = () => {
<Branding delimiter={ false }/> <Branding delimiter={ false }/>
</div> </div>
<CoverButtons/> <CoverButtons/>
<ShowIf condition={ showSpinner }> <ShowIf condition={ !rendererReady && introPageContent !== undefined }>
<WaitSpinner/> <WaitSpinner/>
</ShowIf> </ShowIf>
<ShowIf condition={ !!introPageContent }>
<RenderIframe <RenderIframe
frameClasses={ 'w-100 overflow-y-hidden' } frameClasses={ 'w-100 overflow-y-hidden' }
markdownContent={ introPageContent } markdownContent={ introPageContent as string }
disableToc={ true } disableToc={ true }
onRendererReadyChange={ (rendererReady => setShowSpinner(!rendererReady)) } onRendererReadyChange={ (rendererReady => setRendererReady(!rendererReady)) }
rendererType={ RendererType.INTRO } rendererType={ RendererType.INTRO }
forcedDarkMode={ true }/> forcedDarkMode={ true }/>
</ShowIf>
<hr className={ 'mb-5' }/> <hr className={ 'mb-5' }/>
</div> </div>
<FeatureLinks/> <FeatureLinks/>