Skip to content

Commit

Permalink
hotfix editor main/additional texts (#1113)
Browse files Browse the repository at this point in the history
* hotfix editor main/additional texts

* Cleaned code
  • Loading branch information
KateYatsiuk authored Jan 17, 2024
1 parent 03d6dd3 commit d570075
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/app/common/components/Editor/QEditor.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface EditorProps {
const Editor: React.FC<EditorProps> = ({
qRef, value, onChange, maxChars, initialVal, selectionChange, onCharacterCountChange = () => {},
}) => {
const indentedValue = refactorIndentsHtml(value);
const indentedValue = refactorIndentsHtml(value || '');
const [val, setVal] = useState(indentedValue);
const [rawText, setRawText] = useState(removeHtmlTags(value) ?? '');
const [characterCount, setCharacterCount] = useState(rawText.length ?? 0);
Expand All @@ -39,8 +39,8 @@ const Editor: React.FC<EditorProps> = ({
};

useEffect(() => {
if (value.includes('\n')) {
const preservedIndents = refactorIndentsHtml(value);
if (value?.includes('\n')) {
const preservedIndents = refactorIndentsHtml(value || '');
setVal(preservedIndents);
}
const valueWithoutHtml = removeHtmlTags(value);
Expand Down
16 changes: 11 additions & 5 deletions src/app/common/utils/removeHtmlTags.utility.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export const removeHtmlTags = (content: string) => content.replace(/<[^>]*>|&nbsp;/g, (match) => {
if (match === '&nbsp;') return ' ';
return '';
});
export const removeHtmlTags = (content: string | null) => {
if (!content) {
return '';
}

export const refactorIndentsHtml = (content: string) => content.replace(/\n/g, '<p><br></p>');
return content.replace(/<[^>]*>|&nbsp;/g, (match) => {
if (match === '&nbsp;') return ' ';
return '';
});
};

export const refactorIndentsHtml = (content: string | null) => content?.replace(/\n/g, '<p><br></p>') ?? '';
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import StreetcodeArtApi from '@/app/api/media/streetcode-art.api';
import StreetcodesApi from '@/app/api/streetcode/streetcodes.api';
import TransactionLinksApi from '@/app/api/transactions/transactLinks.api';
import FRONTEND_ROUTES from '@/app/common/constants/frontend-routes.constants';
import removeHtmlTags from '@/app/common/utils/removeHtmlTags.utility';
import { removeHtmlTags } from '@/app/common/utils/removeHtmlTags.utility';
import QUILL_TEXTS_LENGTH from '@/features/AdminPage/NewStreetcode/TextBlock/TextLengthConstants/textMaxLength.constant';
import Subtitle, { SubtitleCreate } from '@/models/additional-content/subtitles.model';
import { StreetcodeTag, StreetcodeTagUpdate } from '@/models/additional-content/tag.model';
Expand Down

0 comments on commit d570075

Please sign in to comment.