-
Notifications
You must be signed in to change notification settings - Fork 459
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
TypeScript migration #163
TypeScript migration #163
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module "*.svg" { | ||
const content: any; | ||
export default content; | ||
} |
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
|
||
const close = require('../../../../../../../assets/clear-button.svg') as string; | ||
|
||
import './style.scss'; | ||
|
||
type Props = { | ||
title: string; | ||
subtitle: string; | ||
toggleChat: () => void; | ||
showCloseButton: boolean; | ||
titleAvatar?: string; | ||
} | ||
|
||
function Header({ title, subtitle, toggleChat, showCloseButton, titleAvatar }: Props) { | ||
return ( | ||
<div className="rcw-header"> | ||
{showCloseButton && | ||
<button className="rcw-close-button" onClick={toggleChat}> | ||
<img src={close} className="rcw-close" alt="close" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not related to this pull request, but the alt text should be translated. Do you have a way of passing locales or texts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I can add a prop to manage that, but I think I'll need to add i18next and translate all alts to some extent 🤔 . Let me see if I can do it in another PR |
||
</button> | ||
} | ||
<h4 className="rcw-title"> | ||
{titleAvatar && <img src={titleAvatar} className="avatar" alt="profile" />} | ||
{title} | ||
</h4> | ||
<span>{subtitle}</span> | ||
</div> | ||
); | ||
} | ||
|
||
export default Header; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import cn from 'classnames'; | ||
|
||
import './styles.scss'; | ||
|
||
type Props = { | ||
typing: boolean; | ||
} | ||
|
||
function Loader({ typing }: Props) { | ||
return ( | ||
<div className={cn('loader', { active: typing })}> | ||
<div className="loader-container"> | ||
<span className="loader-dots"></span> | ||
<span className="loader-dots"></span> | ||
<span className="loader-dots"></span> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default Loader; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
|
||
import { scrollToBottom } from '../../../../../../utils/messages'; | ||
import { Message, Link, CustomCompMessage, GlobalState } from '../../../../../../store/types'; | ||
|
||
import Loader from './components/Loader'; | ||
import './styles.scss'; | ||
|
||
type Props = { | ||
profileAvatar?: string; | ||
} | ||
|
||
function Messages({ profileAvatar }: Props) { | ||
const messages = useSelector((state: GlobalState) => state.messages.messages); | ||
const typing = useSelector((state: GlobalState) => state.behavior.messageLoader); | ||
const dispatch = useDispatch(); | ||
|
||
const messageRef = useRef(null); | ||
useEffect(() => scrollToBottom(messageRef.current), [messages]); | ||
|
||
const getComponentToRender = (message: Message | Link | CustomCompMessage) => { | ||
const ComponentToRender = message.component; | ||
if (message.type === 'component') { | ||
return <ComponentToRender {...message.props} />; | ||
} | ||
return <ComponentToRender message={message} />; | ||
}; | ||
|
||
// TODO: Fix this function or change to move the avatar to last message from response | ||
// const shouldRenderAvatar = (message: Message, index: number) => { | ||
// const previousMessage = messages[index - 1]; | ||
// if (message.showAvatar && previousMessage.showAvatar) { | ||
// dispatch(hideAvatar(index)); | ||
// } | ||
// } | ||
|
||
return ( | ||
<div id="messages" className="rcw-messages-container" ref={messageRef}> | ||
{messages?.map(message => | ||
<div className="rcw-message" key={message.timestamp.toString()}> | ||
{profileAvatar && | ||
message.showAvatar && | ||
<img src={profileAvatar} className="rcw-avatar" alt="profile" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idk if you're using i18n, if you are I'd use it in the alt text too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No i18n. We don't actually need it |
||
} | ||
{getComponentToRender(message)} | ||
</div> | ||
)} | ||
<Loader typing={typing} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default Messages; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why require?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeScript needs it to be imported that way, or at least that's the simplest way I found