-
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
Conversation
- fix type issues in the redux store - bumped redux adn react-redux versions to latest
- change connect react-redux hoc for hooks - fix some store types issues
@@ -0,0 +1,32 @@ | |||
import React from 'react'; | |||
|
|||
const close = require('../../../../../../../assets/clear-button.svg') as string; |
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
|
||
function Loader({ typing }: Props) { | ||
return ( | ||
<div className={`loader ${typing && 'active'}`}> |
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.
if this is false you'll have a 'false' as a class I think. You'll need to use a ternary: loader ${typing ? 'active' : ''}
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.
import React, { useEffect } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
|
||
import { hideAvatar } from '../../../../../..//store/actions'; |
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.
double /
|
||
let $message: HTMLDivElement | null; | ||
|
||
// useEffect(() => scrollToBottom($message), [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.
should we remove this?
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.
Not yet, I'll fix it in another PR
// } | ||
|
||
return ( | ||
<div id="messages" className="rcw-messages-container" ref={msg => $message = msg}> |
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.
I'd use the more "modern" way to create refs, which is the useRef hook:
const messageRef = useRef(null);
...
return (
<div ... ref={messageRef}>
...
)
Although what you did works, I personally prefer this.
}: Props) { | ||
const input = React.createRef(); | ||
|
||
// componentDidUpdate() { |
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.
should we delete this?
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.
I will fix it in another PR
<form className="rcw-sender" onSubmit={sendMessage}> | ||
<input type="text" className="rcw-new-message" name="message" placeholder={placeholder} disabled={disabledInput} autoFocus={autofocus} autoComplete="off"/> | ||
<button type="submit" className="rcw-send"> | ||
<img src={send} className="rcw-send-icon" alt="send" /> |
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.
this looks like it could be a ::before
|
||
import './style.scss'; | ||
|
||
const openLauncher = require('../../../../../assets/launcher_button.svg') as string; |
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 to import SVGs
<button type="button" className={chatOpened ? 'rcw-launcher rcw-hide-sm' : 'rcw-launcher'} onClick={toggle}> | ||
<Badge badge={badge} /> | ||
{chatOpened ? | ||
<img src={close} className="rcw-close-launcher" alt="" /> : |
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 no alt (next line too)?
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.
Since it's an icon, I don't think it should have an alt
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.
I think it should if it is part of a button without any text
src/components/Widget/index.tsx
Outdated
@@ -54,7 +53,8 @@ function Widget({ | |||
|
|||
const onQuickButtonClicked = (event, value) => { | |||
event.preventDefault(); | |||
if (handleQuickButtonClicked) handleQuickButtonClicked(value); | |||
handleQuickButtonClicked?.(value) | |||
// if (handleQuickButtonClicked) handleQuickButtonClicked(value); |
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.
remove
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.
I didn't test correctly if the line above does really work. Let me try that first 😝
[actionTypes.HIDE_AVATAR]: (state, { index }) => | ||
state.update(index, message => message.set('showAvatar', false)) | ||
[HIDE_AVATAR]: (state: MessagesState, { index }) => | ||
state.messages[index].showAvatar = false |
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.
state should be immutable
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.
I will add seamless-immutable
in another PR
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.
Still, I don't think we should leave it like this. I think it should work with just this:
messages = [...state.messages];
messages[index].showsAvatar = false;
return { ...state, messages };
<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 comment
The 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 comment
The 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
const close = require('../../../../../assets/clear-button.svg') as string; | ||
|
||
type Props = { | ||
toggle: () => {}, |
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.
Shouldn't this be toggle: () => void,
?
src/utils/createReducer.ts
Outdated
export const createReducer = <S>( | ||
reducer: { [key: string]: Function }, | ||
state: { [key: string]: S }, | ||
state: BehaviorState | MessagesState | QuickButtonsState, |
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.
Do you need this union?
Why don't you use S
?
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.
Because I didn't noticed 😝 . Fixed!
- change refs to use useRef hook - fix quick buttons feature, reducer and component - fix indentation issues - add timestamp to messages, now they will display underneath the message
- change the use on launcher of conditional classes - change state type in create reducer
Description
Full migration to TypeScript