New note creation (#1998)

* Add new note page

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Make new note button clickable

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Add CHANGELOG note

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Refactor error messages

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Use features note in mock

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Common Error page should always use i18n

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2022-05-02 17:39:18 +02:00 committed by GitHub
parent 1fa94f9ea6
commit 85eff24be1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 178 additions and 37 deletions

41
src/pages/new.tsx Normal file
View file

@ -0,0 +1,41 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import type { NextPage } from 'next'
import { useSingleStringUrlParameter } from '../hooks/common/use-single-string-url-parameter'
import { useAsync } from 'react-use'
import { createNote } from '../api/notes'
import { AsyncLoadingBoundary } from '../components/common/async-loading-boundary'
import { Redirect } from '../components/common/redirect'
import { CommonErrorPage } from '../components/error-pages/common-error-page'
/**
* Creates a new note, optionally including the passed content and redirects to that note.
*/
export const NewNotePage: NextPage = () => {
const newContent = useSingleStringUrlParameter('content', '')
const { loading, error, value } = useAsync(() => {
return createNote(newContent)
}, [newContent])
return (
<AsyncLoadingBoundary
loading={loading}
componentName={'NewNotePage'}
error={error}
errorComponent={
<CommonErrorPage
titleI18nKey={'errors.noteCreationFailed.title'}
descriptionI18nKey={'errors.noteCreationFailed.description'}
/>
}>
{value ? <Redirect to={`/n/${value.metadata.primaryAddress}`} /> : null}
</AsyncLoadingBoundary>
)
}
export default NewNotePage