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

TypeScript migration #163

Merged
merged 5 commits into from
Apr 3, 2020
Merged

TypeScript migration #163

merged 5 commits into from
Apr 3, 2020

Conversation

mcallegari10
Copy link
Contributor

Description

Full migration to TypeScript

  • bumped redux and react-redux versions to latest
  • migrate all the components to typescript
  • change connect react-redux hoc for hooks
  • add missing type for svgs to compile

mcallegari10 added 2 commits March 31, 2020 14:12
- 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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why require?

Copy link
Contributor Author

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'}`}>

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' : ''}

Copy link
Contributor

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';

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]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove this?

Copy link
Contributor Author

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}>

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() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we delete this?

Copy link
Contributor Author

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" />

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why require?

Copy link
Contributor Author

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="" /> :

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)?

Copy link
Contributor Author

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

Copy link
Contributor

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

@@ -54,7 +53,8 @@ function Widget({

const onQuickButtonClicked = (event, value) => {
event.preventDefault();
if (handleQuickButtonClicked) handleQuickButtonClicked(value);
handleQuickButtonClicked?.(value)
// if (handleQuickButtonClicked) handleQuickButtonClicked(value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Contributor Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state should be immutable

Copy link
Contributor Author

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

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" />
Copy link
Contributor

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?

Copy link
Contributor Author

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: () => {},
Copy link
Contributor

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,?

export const createReducer = <S>(
reducer: { [key: string]: Function },
state: { [key: string]: S },
state: BehaviorState | MessagesState | QuickButtonsState,
Copy link
Contributor

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?

Copy link
Contributor Author

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!

mcallegari10 added 3 commits April 3, 2020 12:52
- 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
@mcallegari10 mcallegari10 merged commit 04d2953 into react-update Apr 3, 2020
@mcallegari10 mcallegari10 deleted the ts-migration branch April 3, 2020 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants