mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-22 19:25:18 -04:00
Move and rename files (2/4) (#987)
Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
parent
1b7abf9f27
commit
123f959fb3
145 changed files with 586 additions and 301 deletions
32
src/components/editor-page/hooks/useLoadNoteFromServer.ts
Normal file
32
src/components/editor-page/hooks/useLoadNoteFromServer.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useParams } from 'react-router'
|
||||
import { getNote } from '../../../api/notes'
|
||||
import { setNoteDataFromServer } from '../../../redux/note-details/methods'
|
||||
import { EditorPagePathParams } from '../editor-page'
|
||||
|
||||
export const useLoadNoteFromServer = (): [boolean, boolean] => {
|
||||
const { id } = useParams<EditorPagePathParams>()
|
||||
|
||||
const [error, setError] = useState(false)
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
getNote(id)
|
||||
.then(note => {
|
||||
setNoteDataFromServer(note)
|
||||
})
|
||||
.catch((e) => {
|
||||
setError(true)
|
||||
console.error(e)
|
||||
})
|
||||
.finally(() => setLoading(false))
|
||||
}, [id])
|
||||
|
||||
return [error, loading]
|
||||
}
|
35
src/components/editor-page/hooks/useViewModeShortcuts.ts
Normal file
35
src/components/editor-page/hooks/useViewModeShortcuts.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import { setEditorMode } from '../../../redux/editor/methods'
|
||||
import { EditorMode } from '../app-bar/editor-view-mode'
|
||||
|
||||
const shortcutHandler = (event: KeyboardEvent): void => {
|
||||
if (event.ctrlKey && event.altKey && event.key === 'b') {
|
||||
setEditorMode(EditorMode.BOTH)
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
if (event.ctrlKey && event.altKey && event.key === 'v') {
|
||||
setEditorMode(EditorMode.PREVIEW)
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
if (event.ctrlKey && event.altKey && (event.key === 'e' || event.key === '€')) {
|
||||
setEditorMode(EditorMode.EDITOR)
|
||||
event.preventDefault()
|
||||
}
|
||||
}
|
||||
|
||||
export const useViewModeShortcuts = ():void => {
|
||||
useEffect(() => {
|
||||
document.addEventListener('keydown', shortcutHandler, false)
|
||||
return () => {
|
||||
document.removeEventListener('keydown', shortcutHandler, false)
|
||||
}
|
||||
}, [])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue