Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing small bug conversion from text to DraftJS EditorState #253

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/containers/Chat/ChatMessages/ChatInput/ChatInput.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState } from 'react';
import { EditorState, ContentState } from 'draft-js';
import { Container, Button, ClickAwayListener, Fade, IconButton } from '@material-ui/core';
import { Picker } from 'emoji-mart';
import { EditorState, ContentState, convertFromHTML } from 'draft-js';
import { Container, Button, ClickAwayListener, Fade } from '@material-ui/core';
import 'emoji-mart/css/emoji-mart.css';
import clsx from 'clsx';

Expand All @@ -19,8 +18,6 @@ export interface ChatInputProps {

export const ChatInput: React.SFC<ChatInputProps> = (props) => {
const [editorState, setEditorState] = useState(() => EditorState.createEmpty());

const [message, setMessage] = useState('');
const [selectedTab, setSelectedTab] = useState('');
const [open, setOpen] = React.useState(false);
const [searchVal, setSearchVal] = useState('');
Expand Down Expand Up @@ -54,7 +51,13 @@ export const ChatInput: React.SFC<ChatInputProps> = (props) => {
};

const handleSelectText = (obj: any) => {
setMessage(obj.body);
// Conversion from HTML text to EditorState
const blocksFromHTML = convertFromHTML(obj.body);
const state = ContentState.createFromBlockArray(
blocksFromHTML.contentBlocks,
blocksFromHTML.entityMap
);
setEditorState(EditorState.createWithContent(state));
};

const handleSearch = (e: any) => {
Expand Down