mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-07 22:18:33 +00:00
* fix: persist scroll * fix: persist scroll * chore: style * fix: remove persisted variabled from localstorage on boot * fix: persist scroll in request tabs * fix: persist scroll in folder tabs * fix: hooks for container and editor scrolls * fix: persist scroll position in response tabs * fix: persist scroll for different request bodies * fix: persist scroll for collection tabs * fix: test cases * test: scroll persists tests * tests: resolved coderabbit comments for tests * tests: resolved coderabbit comments for tests * fix: remove only * fix: test cases * fix: flaky create collection path as name * move scrollbar tests * test cases * test cases * test cases * test cases * test cases * fix: moved redundant code to common useTrackScroll function * chore: spaces * fix: move usetrackscroll to hook * chore: cleanup un-needed setTimeout * fix: linting issues * chore: example fix * fix: test cases * fix: test cases * fix: flaky scroll tests cases * chore: revert prop name change * chore: blank commit * chore: blank commit --------- Co-authored-by: shubh-bruno <shubh-bruno@shubh-bruno.local> Co-authored-by: Sid <siddharth@usebruno.com>
89 lines
3.2 KiB
JavaScript
89 lines
3.2 KiB
JavaScript
import 'github-markdown-css/github-markdown.css';
|
|
import get from 'lodash/get';
|
|
import find from 'lodash/find';
|
|
import { updateFolderDocs } from 'providers/ReduxStore/slices/collections';
|
|
import { updateDocsEditing } from 'providers/ReduxStore/slices/tabs';
|
|
import { useTheme } from 'providers/Theme';
|
|
import { useRef } 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 Button from 'ui/Button';
|
|
import StyledWrapper from './StyledWrapper';
|
|
import { usePersistedState } from 'hooks/usePersistedState';
|
|
import { useTrackScroll } from 'hooks/useTrackScroll';
|
|
|
|
const Documentation = ({ collection, folder }) => {
|
|
const dispatch = useDispatch();
|
|
const { displayedTheme } = useTheme();
|
|
const preferences = useSelector((state) => state.app.preferences);
|
|
const tabs = useSelector((state) => state.tabs.tabs);
|
|
const activeTabUid = useSelector((state) => state.tabs.activeTabUid);
|
|
const focusedTab = find(tabs, (t) => t.uid === activeTabUid);
|
|
const isEditing = focusedTab?.docsEditing || false;
|
|
const docs = folder.draft ? get(folder, 'draft.docs', '') : get(folder, 'root.docs', '');
|
|
|
|
const wrapperRef = useRef(null);
|
|
const [scroll, setScroll] = usePersistedState({ key: `folder-docs-scroll-${folder.uid}`, default: 0 });
|
|
useTrackScroll({ ref: wrapperRef, selector: '.folder-settings-content', onChange: setScroll, enabled: !isEditing, initialValue: scroll });
|
|
|
|
const toggleViewMode = () => {
|
|
dispatch(updateDocsEditing({ uid: activeTabUid, docsEditing: !isEditing }));
|
|
};
|
|
|
|
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="w-full relative flex flex-col" ref={wrapperRef}>
|
|
<div className="editing-mode flex justify-between items-center flex-shrink-0" role="tab" onClick={toggleViewMode}>
|
|
{isEditing ? 'Preview' : 'Edit'}
|
|
</div>
|
|
|
|
{isEditing ? (
|
|
<div className="flex flex-col flex-1 min-h-0">
|
|
<div className="mt-2 flex-1 overflow-auto min-h-0">
|
|
<CodeEditor
|
|
collection={collection}
|
|
theme={displayedTheme}
|
|
value={docs || ''}
|
|
onEdit={onEdit}
|
|
onSave={onSave}
|
|
font={get(preferences, 'font.codeFont', 'default')}
|
|
fontSize={get(preferences, 'font.codeFontSize')}
|
|
mode="application/text"
|
|
initialScroll={scroll}
|
|
onScroll={setScroll}
|
|
/>
|
|
</div>
|
|
<div className="mt-6 flex-shrink-0">
|
|
<Button type="submit" size="sm" onClick={onSave}>
|
|
Save
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<div className="h-full">
|
|
<Markdown collectionPath={collection.pathname} onDoubleClick={toggleViewMode} content={docs} />
|
|
</div>
|
|
)}
|
|
</StyledWrapper>
|
|
);
|
|
};
|
|
|
|
export default Documentation;
|