mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 22:54:42 -04:00
Note Loading Boundary: Replace redirect with refetch from API (#2275)
This commit is contained in:
parent
fa53bccb03
commit
f2ed9d4453
6 changed files with 54 additions and 28 deletions
|
@ -5,21 +5,24 @@
|
|||
*/
|
||||
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import React, { useCallback } from 'react'
|
||||
import React, { useCallback, useEffect } from 'react'
|
||||
import { Alert, Button } from 'react-bootstrap'
|
||||
import { useSingleStringUrlParameter } from '../../../hooks/common/use-single-string-url-parameter'
|
||||
import { createNoteWithPrimaryAlias } from '../../../api/notes'
|
||||
import { useAsyncFn } from 'react-use'
|
||||
import { ShowIf } from '../show-if/show-if'
|
||||
import { Redirect } from '../redirect'
|
||||
import { ForkAwesomeIcon } from '../fork-awesome/fork-awesome-icon'
|
||||
import { testId } from '../../../utils/test-id'
|
||||
|
||||
export interface CreateNonExistingNoteHintProps {
|
||||
onNoteCreated: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a button that creates an empty note with the alias from the current window URL.
|
||||
* When the button was clicked it also shows the progress.
|
||||
*/
|
||||
export const CreateNonExistingNoteHint: React.FC = () => {
|
||||
export const CreateNonExistingNoteHint: React.FC<CreateNonExistingNoteHintProps> = ({ onNoteCreated }) => {
|
||||
useTranslation()
|
||||
const noteIdFromUrl = useSingleStringUrlParameter('noteId', undefined)
|
||||
|
||||
|
@ -34,10 +37,21 @@ export const CreateNonExistingNoteHint: React.FC = () => {
|
|||
void createNote()
|
||||
}, [createNote])
|
||||
|
||||
useEffect(() => {
|
||||
if (returnState.value !== undefined) {
|
||||
onNoteCreated()
|
||||
}
|
||||
}, [onNoteCreated, returnState.value])
|
||||
|
||||
if (noteIdFromUrl === undefined) {
|
||||
return null
|
||||
} else if (returnState.value) {
|
||||
return <Redirect to={`/n/${returnState.value.metadata.primaryAddress}`} />
|
||||
return (
|
||||
<Alert variant={'info'} {...testId('noteCreated')} className={'mt-5'}>
|
||||
<ForkAwesomeIcon icon={'check-circle'} className={'mr-2'} />
|
||||
<Trans i18nKey={'noteLoadingBoundary.createNote.success'} />
|
||||
</Alert>
|
||||
)
|
||||
} else if (returnState.loading) {
|
||||
return (
|
||||
<Alert variant={'info'} {...testId('loadingMessage')} className={'mt-5'}>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue