mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 03:27:05 -04:00
Add editor split component (#198)
Add split and split divider component
This commit is contained in:
parent
c679f5524c
commit
f298d1469b
9 changed files with 130 additions and 13 deletions
|
@ -1,7 +1,9 @@
|
|||
import React from 'react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { useSelector } from 'react-redux'
|
||||
import useMedia from 'use-media'
|
||||
import { ApplicationState } from '../../redux'
|
||||
import { ShowIf } from '../common/show-if/show-if'
|
||||
import { setEditorModeConfig } from '../../redux/editor/methods'
|
||||
import { Splitter } from '../common/splitter/splitter'
|
||||
import { EditorWindow } from './editor-window/editor-window'
|
||||
import { MarkdownPreview } from './markdown-preview/markdown-preview'
|
||||
import { EditorMode } from './task-bar/editor-view-mode'
|
||||
|
@ -13,18 +15,28 @@ interface RouteParameters {
|
|||
|
||||
const Editor: React.FC = () => {
|
||||
const editorMode: EditorMode = useSelector((state: ApplicationState) => state.editorConfig.editorMode)
|
||||
const isWide = useMedia({ minWidth: 576 })
|
||||
const [firstDraw, setFirstDraw] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
setFirstDraw(false)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!firstDraw && !isWide && editorMode === EditorMode.BOTH) {
|
||||
setEditorModeConfig(EditorMode.PREVIEW)
|
||||
}
|
||||
}, [editorMode, firstDraw, isWide])
|
||||
|
||||
return (
|
||||
<div className={'d-flex flex-column vh-100'}>
|
||||
<TaskBar/>
|
||||
<div className={'flex-fill flex-row d-flex'}>
|
||||
<ShowIf condition={editorMode === EditorMode.EDITOR || editorMode === EditorMode.BOTH}>
|
||||
<EditorWindow/>
|
||||
</ShowIf>
|
||||
<ShowIf condition={editorMode === EditorMode.PREVIEW || editorMode === EditorMode.BOTH}>
|
||||
<MarkdownPreview/>
|
||||
</ShowIf>
|
||||
</div>
|
||||
<Splitter
|
||||
showLeft={editorMode === EditorMode.EDITOR || editorMode === EditorMode.BOTH}
|
||||
left={<EditorWindow/>}
|
||||
showRight={editorMode === EditorMode.PREVIEW || (editorMode === EditorMode.BOTH)}
|
||||
right={<MarkdownPreview/>}
|
||||
containerClassName={'overflow-hidden'}/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue