mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 19:53:59 -05:00
fix(note-deletion): Add required keepMedia property and redirect
The backend requires a property "keepMedia" that states whether uploaded media should be kept around or not. This property was missing in our API call. Additionally, after deleting a note, the user is now redirected to the history page. Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
d57b2f27fd
commit
6cc11d07e3
3 changed files with 25 additions and 5 deletions
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import type { Note } from './types'
|
import type { Note, NoteDeletionOptions } from './types'
|
||||||
import type { MediaUpload } from '../media/types'
|
import type { MediaUpload } from '../media/types'
|
||||||
import { GetApiRequestBuilder } from '../common/api-request-builder/get-api-request-builder'
|
import { GetApiRequestBuilder } from '../common/api-request-builder/get-api-request-builder'
|
||||||
import { PostApiRequestBuilder } from '../common/api-request-builder/post-api-request-builder'
|
import { PostApiRequestBuilder } from '../common/api-request-builder/post-api-request-builder'
|
||||||
|
@ -73,5 +73,11 @@ export const createNoteWithPrimaryAlias = async (markdown: string, primaryAlias:
|
||||||
* @throws {Error} when the api request wasn't successful.
|
* @throws {Error} when the api request wasn't successful.
|
||||||
*/
|
*/
|
||||||
export const deleteNote = async (noteIdOrAlias: string): Promise<void> => {
|
export const deleteNote = async (noteIdOrAlias: string): Promise<void> => {
|
||||||
await new DeleteApiRequestBuilder('notes/' + noteIdOrAlias).sendRequest()
|
await new DeleteApiRequestBuilder<void, NoteDeletionOptions>('notes/' + noteIdOrAlias)
|
||||||
|
.withJsonBody({
|
||||||
|
keepMedia: false
|
||||||
|
// TODO Ask whether the user wants to keep the media uploaded to the note.
|
||||||
|
// https://github.com/hedgedoc/react-client/issues/2288
|
||||||
|
})
|
||||||
|
.sendRequest()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
@ -50,3 +50,7 @@ export interface NoteGroupPermissionEntry {
|
||||||
groupName: string
|
groupName: string
|
||||||
canEdit: boolean
|
canEdit: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface NoteDeletionOptions {
|
||||||
|
keepMedia: boolean
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,10 @@ import { showErrorNotification } from '../../../../redux/ui-notifications/method
|
||||||
import { deleteNote } from '../../../../api/notes'
|
import { deleteNote } from '../../../../api/notes'
|
||||||
import { DeleteNoteModal } from './delete-note-modal'
|
import { DeleteNoteModal } from './delete-note-modal'
|
||||||
import { useBooleanState } from '../../../../hooks/common/use-boolean-state'
|
import { useBooleanState } from '../../../../hooks/common/use-boolean-state'
|
||||||
|
import { useRouter } from 'next/router'
|
||||||
|
import { Logger } from '../../../../utils/logger'
|
||||||
|
|
||||||
|
const logger = new Logger('note-deletion')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sidebar entry that can be used to delete the current note.
|
* Sidebar entry that can be used to delete the current note.
|
||||||
|
@ -24,11 +28,17 @@ import { useBooleanState } from '../../../../hooks/common/use-boolean-state'
|
||||||
*/
|
*/
|
||||||
export const DeleteNoteSidebarEntry: React.FC<PropsWithChildren<SpecificSidebarEntryProps>> = ({ hide, className }) => {
|
export const DeleteNoteSidebarEntry: React.FC<PropsWithChildren<SpecificSidebarEntryProps>> = ({ hide, className }) => {
|
||||||
useTranslation()
|
useTranslation()
|
||||||
|
const router = useRouter()
|
||||||
const noteId = useApplicationState((state) => state.noteDetails.id)
|
const noteId = useApplicationState((state) => state.noteDetails.id)
|
||||||
const [modalVisibility, showModal, closeModal] = useBooleanState()
|
const [modalVisibility, showModal, closeModal] = useBooleanState()
|
||||||
const deleteNoteAndCloseDialog = useCallback(() => {
|
const deleteNoteAndCloseDialog = useCallback(() => {
|
||||||
deleteNote(noteId).catch(showErrorNotification('landing.history.error.deleteNote.text')).finally(closeModal)
|
deleteNote(noteId)
|
||||||
}, [closeModal, noteId])
|
.then(() => {
|
||||||
|
router.push('/history').catch((reason) => logger.error('Error while redirecting to /history', reason))
|
||||||
|
})
|
||||||
|
.catch(showErrorNotification('landing.history.error.deleteNote.text'))
|
||||||
|
.finally(closeModal)
|
||||||
|
}, [closeModal, noteId, router])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
|
|
Loading…
Reference in a new issue