Move toolbar functionality from redux to codemirror dispatch (#2083)

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2022-06-08 01:10:49 +02:00 committed by GitHub
parent a8bd22aef3
commit e93607c96e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
99 changed files with 1730 additions and 1721 deletions

View file

@ -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
*/
@ -8,24 +8,10 @@ import { useRendererToEditorCommunicator } from '../../../../editor-page/render-
import { useCallback } from 'react'
import { CommunicationMessageType } from '../../../../render-page/window-post-message-communicator/rendering-message'
import { Logger } from '../../../../../utils/logger'
import { FileContentFormat, readFile } from '../../../../../utils/read-file'
const log = new Logger('useOnImageUpload')
/**
* Converts a {@link File} to a data url.
*
* @param file The file to convert
* @return The file content represented as data url
*/
const readFileAsDataUrl = (file: File): Promise<string> => {
return new Promise((resolve, reject) => {
const reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = () => resolve(reader.result as string)
reader.onerror = (error) => reject(error)
})
}
/**
* Provides a callback that sends a {@link File file} to the editor via iframe communication.
*
@ -40,7 +26,7 @@ export const useOnImageUpload = (
return useCallback(
(file: File) => {
readFileAsDataUrl(file)
readFile(file, FileContentFormat.DATA_URL)
.then((dataUri) => {
communicator.sendMessageToOtherSide({
type: CommunicationMessageType.IMAGE_UPLOAD,