mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-01 16:44:16 +00:00
* add font-size setting for code editor * add code font size to remaining editors * align font-size after font-family * changed default font size to 14 * fixed className typo * set inherit mode if unset * add code font size schema validation * add font size to folder settings --------- Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
import 'github-markdown-css/github-markdown.css';
|
|
import get from 'lodash/get';
|
|
import { updateCollectionDocs } from 'providers/ReduxStore/slices/collections';
|
|
import { useTheme } from 'providers/Theme';
|
|
import { useState } from 'react';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import { saveCollectionRoot } from 'providers/ReduxStore/slices/collections/actions';
|
|
import Markdown from 'components/MarkDown';
|
|
import CodeEditor from 'components/CodeEditor';
|
|
import StyledWrapper from './StyledWrapper';
|
|
|
|
const Docs = ({ collection }) => {
|
|
const dispatch = useDispatch();
|
|
const { displayedTheme } = useTheme();
|
|
const [isEditing, setIsEditing] = useState(false);
|
|
const docs = get(collection, 'root.docs', '');
|
|
const preferences = useSelector((state) => state.app.preferences);
|
|
|
|
const toggleViewMode = () => {
|
|
setIsEditing((prev) => !prev);
|
|
};
|
|
|
|
const onEdit = (value) => {
|
|
dispatch(
|
|
updateCollectionDocs({
|
|
collectionUid: collection.uid,
|
|
docs: value
|
|
})
|
|
);
|
|
};
|
|
|
|
const onSave = () => dispatch(saveCollectionRoot(collection.uid));
|
|
|
|
return (
|
|
<StyledWrapper className="mt-1 h-full w-full relative">
|
|
<div className="editing-mode mb-2" role="tab" onClick={toggleViewMode}>
|
|
{isEditing ? 'Preview' : 'Edit'}
|
|
</div>
|
|
|
|
{isEditing ? (
|
|
<CodeEditor
|
|
collection={collection}
|
|
theme={displayedTheme}
|
|
value={docs || ''}
|
|
onEdit={onEdit}
|
|
onSave={onSave}
|
|
mode="application/text"
|
|
font={get(preferences, 'font.codeFont', 'default')}
|
|
fontSize={get(preferences, 'font.codeFontSize')}
|
|
/>
|
|
) : (
|
|
<Markdown collectionPath={collection.pathname} onDoubleClick={toggleViewMode} content={docs} />
|
|
)}
|
|
</StyledWrapper>
|
|
);
|
|
};
|
|
|
|
export default Docs;
|