Skip to content

Commit

Permalink
add text to file logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshun-01 committed Jan 12, 2024
1 parent 03676b6 commit fed04d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
27 changes: 15 additions & 12 deletions packages/react/src/components/ChatInput/ChatInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const ChatInput = ({ scrollToBottom }) => {
const setIsLoginModalOpen = loginModalStore(
(state) => state.setIsLoginModalOpen
);
const [errorModal, setErrorModal] = useState(null);
const [errorModal, setErrorModal] = useState("Message too long");
const [isAttachmentMode, setIsAttachmentMode] = useState(false);


Expand Down Expand Up @@ -127,6 +127,10 @@ const ChatInput = ({ scrollToBottom }) => {
const closeErrorModal = () => {
setErrorModal(null);
};

useEffect(() => {
if(isAttachmentMode) sendMessage();
}, [isAttachmentMode]);
const handleConvertToAttachment = () => {
setIsAttachmentMode(true);
closeErrorModal();
Expand Down Expand Up @@ -154,20 +158,19 @@ const ChatInput = ({ scrollToBottom }) => {
scrollToBottom();
messageRef.current.style.height = '44px';
const message = messageRef.current.value.trim();

if(isAttachmentMode){
const blob = new Blob([message], { type: 'text/plain' });
const formData = new FormData();
formData.append('file', blob, 'message.txt');
try {
sendAttachment(formData);
console.log('Message sent as attachment:', formData);
} catch (error) {
console.error('Error sending attachment:', error);
}
const messageBlob = new Blob([message], { type: 'text/plain' });
const file = new File([messageBlob], 'message.txt', {
type:'text/plain',
lastModified: Date.now(),
});

// file upload logic
toggle();
setData(file);

messageRef.current.value = '';
setDisableButton(true);
setEditMessage({});
setIsAttachmentMode(false);
return;
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/ChatInput/ErrorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ const ErrorModal = ({ message, onClose, onConfirm }) => {
<>
<Box css={outerContainerCss} onClick={onClose}/>
<Box css={containerCss}>
<h2> ⚠️ {message} </h2>
<h2> <span css={css`opacity:60%;`}> ⚠︎ </span> {message} </h2>
<p>Send it as attachment instead?</p>
<Button css={css`position:absolute; right:1em;`} onClick={onConfirm}>Ok</Button>
<span css={css`position:absolute; top:1em; right:1em;cursor:pointer;`} onClick={onClose}> </span>
<span css={css`position:absolute; top:1em; right:1em;cursor:pointer;scale:1.5;`} onClick={onClose}> </span>
</Box>
</>
);
Expand Down

0 comments on commit fed04d5

Please sign in to comment.