Skip to content

Commit

Permalink
fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmadom committed May 13, 2024
1 parent 915fb90 commit 2e638ad
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/ui/components/MarkdownControl/MarkdownControl.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.markdown-control {
&__textarea {
max-height: 40vh;
}
}
16 changes: 15 additions & 1 deletion src/ui/components/MarkdownControl/MarkdownControl.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import React from 'react';

import {TextArea} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';

import {MarkdownControlProps} from '../../registry/units/common/types/components/MarkdownControl';

import './MarkdownControl.scss';

const b = block('markdown-control');

export const MarkdownControl = (props: MarkdownControlProps) => {
const {value, onChange, disabled} = props;

return <TextArea value={value} onUpdate={onChange} hasClear={true} disabled={disabled} />;
return (
<TextArea
className={b()}
value={value}
onUpdate={onChange}
hasClear={true}
disabled={disabled}
controlProps={{className: b('textarea')}}
/>
);
};
12 changes: 9 additions & 3 deletions src/ui/hooks/useMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ type Props = {
value: string;
};

const MD_COLLECTION_MAX_SIZE = 1000;
const MarkdownCollection = new Map();
async function renderMarkdown(value: string) {
if (!MarkdownCollection.has(value)) {
try {
if (MarkdownCollection.size > MD_COLLECTION_MAX_SIZE) {
const firstKey = MarkdownCollection.keys().next().value;
MarkdownCollection.delete(firstKey);
}

const response = await getSdk().mix.renderMarkdown({text: value, lang: DL.USER_LANG});
const yfmString = response.result;
MarkdownCollection.set(value, yfmString);
Expand All @@ -25,7 +31,7 @@ async function renderMarkdown(value: string) {

export const useMarkdown = (props: Props) => {
const {value} = props;
const [markdown, setMarkdown] = React.useState<React.ReactNode>('');
const [markdown, setMarkdown] = React.useState('');
const [isLoading, setIsLoading] = React.useState<boolean>(true);

React.useEffect(() => {
Expand All @@ -34,10 +40,10 @@ export const useMarkdown = (props: Props) => {
}

renderMarkdown(value).then((val) => {
setMarkdown(<YfmWrapper content={val} setByInnerHtml={true} />);
setMarkdown(val);
setIsLoading(false);
});
}, [value]);

return {markdown, isLoading};
return {markdown: <YfmWrapper content={markdown} setByInnerHtml={true} />, isLoading};
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import {I18n} from 'i18n';

import {Feature} from '../../../../../../../../shared';
import {Utils} from '../../../../../../../../ui';
import Utils from '../../../../../../../../ui/utils';
import {SectionWrapper} from '../../../../../../../components/SectionWrapper/SectionWrapper';

import {HintRow} from './Rows/HintRow/HintRow';
Expand Down

0 comments on commit 2e638ad

Please sign in to comment.