mirror of
https://github.com/usebruno/bruno.git
synced 2025-08-02 14:32:59 +02:00
* add docs, save not working yet * working folder docs * revert unrelated changes * prettier fix * allow save folder with command * include folder docs in `bruno-collection` json export * docs --------- Co-authored-by: Filip Gala <filip.gala@student.tuke.sk> Co-authored-by: lohit <lohxt.space@gmail.com>
64 lines
1.9 KiB
JavaScript
64 lines
1.9 KiB
JavaScript
import 'github-markdown-css/github-markdown.css';
|
|
import get from 'lodash/get';
|
|
import { updateFolderDocs } from 'providers/ReduxStore/slices/collections';
|
|
import { useTheme } from 'providers/Theme';
|
|
import { useState } from 'react';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import { saveFolderRoot } from 'providers/ReduxStore/slices/collections/actions';
|
|
import Markdown from 'components/MarkDown';
|
|
import CodeEditor from 'components/CodeEditor';
|
|
import StyledWrapper from './StyledWrapper';
|
|
|
|
const Documentation = ({ collection, folder }) => {
|
|
const dispatch = useDispatch();
|
|
const { displayedTheme } = useTheme();
|
|
const preferences = useSelector((state) => state.app.preferences);
|
|
const [isEditing, setIsEditing] = useState(false);
|
|
const docs = get(folder, 'root.docs', '');
|
|
|
|
const toggleViewMode = () => {
|
|
setIsEditing((prev) => !prev);
|
|
};
|
|
|
|
const onEdit = (value) => {
|
|
dispatch(
|
|
updateFolderDocs({
|
|
folderUid: folder.uid,
|
|
collectionUid: collection.uid,
|
|
docs: value
|
|
})
|
|
);
|
|
};
|
|
|
|
const onSave = () => dispatch(saveFolderRoot(collection.uid, folder.uid));
|
|
|
|
if (!folder) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<StyledWrapper className="flex flex-col gap-y-1 h-full w-full relative">
|
|
<div className="editing-mode" role="tab" onClick={toggleViewMode}>
|
|
{isEditing ? 'Preview' : 'Edit'}
|
|
</div>
|
|
|
|
{isEditing ? (
|
|
<CodeEditor
|
|
collection={collection}
|
|
theme={displayedTheme}
|
|
font={get(preferences, 'font.codeFont', 'default')}
|
|
fontSize={get(preferences, 'font.codeFontSize')}
|
|
value={docs || ''}
|
|
onEdit={onEdit}
|
|
onSave={onSave}
|
|
mode="application/text"
|
|
/>
|
|
) : (
|
|
<Markdown collectionPath={collection.pathname} onDoubleClick={toggleViewMode} content={docs} />
|
|
)}
|
|
</StyledWrapper>
|
|
);
|
|
};
|
|
|
|
export default Documentation;
|