Skip to content

Commit

Permalink
Merge pull request #253 from glific/message-fill-bug
Browse files Browse the repository at this point in the history
Fixing small bug conversion from text to DraftJS EditorState
  • Loading branch information
kurund authored Jul 30, 2020
2 parents bed9c82 + f4e71aa commit aefbe56
Showing 1 changed file with 9 additions and 6 deletions.
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

0 comments on commit aefbe56

Please sign in to comment.