Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

[NEW] Message character limit feature #443

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export class App extends Component {
expanded,
alerts,
modal,
config,
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this here, the StoreConsumer is propagating the config prop to the App components.

}, { initialized }) => {
if (!initialized) {
return null;
Expand All @@ -204,6 +205,7 @@ export class App extends Component {
onOpenWindow: this.handleOpenWindow,
onDismissAlert: this.handleDismissAlert,
dismissNotification: this.dismissNotification,
limitTextLength: config.settings.limitTextLength,
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this here, the StoreConsumer is propagating the config prop to the App components.
You need to extract the prop value here:
https://github.com/RocketChat/Rocket.Chat.Livechat/blob/develop/src/routes/Chat/container.js#L338

And then pass it through the components.

};

return (
Expand Down
6 changes: 5 additions & 1 deletion src/components/Composer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class Composer extends Component {
// we only update composer if value length changed from 0 to 1 or 1 to 0
// everything else is managed by this.el
shouldComponentUpdate({ value: nextValue }) {
const { value } = this.props;
const { value, limitTextLength } = this.props;

const nextValueEmpty = !nextValue || nextValue.length === 0;
const valueEmpty = !value || value.length === 0;
Expand All @@ -156,6 +156,10 @@ export class Composer extends Component {
return true;
}

if (nextValue.length === limitTextLength || value.length === limitTextLength) {
return true;
}

return false;
}

Expand Down
10 changes: 10 additions & 0 deletions src/components/Footer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,13 @@ export const FooterOptions = ({ children }) => (
{children}
</PopoverMenu>
);


export const ReminderCharacters = ({ className, style = {}, textLenght, limitTextLength }) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export const ReminderCharacters = ({ className, style = {}, textLenght, limitTextLength }) => (
export const CharCounter = ({ className, style = {}, textLength, limitTextLength }) => (
<span
className={createClassName(styles, 'footer__remainder', { highlight: textLength === limitTextLength }, [className])}
style={style}
>
{textLength} / {limitTextLength}
</span>
);

<span
className={createClassName(styles, `footer__remainder${ textLenght === limitTextLength ? '-alert' : '' }`, {}, [className])}
style={style}
>
{textLenght} / {limitTextLength}
</span>
);
10 changes: 10 additions & 0 deletions src/components/Footer/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@

@include pressable-button(2px);
}

&__remainder, &__remainder-alert {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
&__remainder, &__remainder-alert {
&__remainder {
margin-left: 10px;
min-width: 100px;
font-weight: bold;
&--highlight {
color: $color-red;
transition: color .2s;
}
}

margin-left: 10px;
min-width: 100px;
}

&__remainder-alert {
color: $color-red;
transition: color .2s;
}
}

.powered-by {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Screen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const ScreenContent = ({ children, nopadding }) => (
);


export const ScreenFooter = ({ children, options }) => (
export const ScreenFooter = ({ children, options, limit }) => (
<Footer>
{children && (
<FooterContent>
Expand All @@ -138,6 +138,7 @@ export const ScreenFooter = ({ children, options }) => (
)}
<FooterContent>
{options}
{limit}
<PoweredBy />
</FooterContent>
</Footer>
Expand Down
21 changes: 16 additions & 5 deletions src/routes/Chat/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component } from 'preact';

import { Composer, ComposerAction, ComposerActions } from '../../components/Composer';
import { FilesDropTarget } from '../../components/FilesDropTarget';
import { FooterOptions } from '../../components/Footer';
import { FooterOptions, ReminderCharacters } from '../../components/Footer';
Copy link
Contributor

@renatobecker renatobecker Jul 27, 2020

Choose a reason for hiding this comment

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

Suggested change
import { FooterOptions, ReminderCharacters } from '../../components/Footer';
import { FooterOptions, CharCounter } from '../../components/Footer';

import { Menu } from '../../components/Menu';
import { MessageList } from '../../components/Messages';
import { Screen } from '../../components/Screen';
Expand Down Expand Up @@ -64,9 +64,13 @@ export default class Chat extends Component {
}

handleChangeText = (text) => {
this.setState({ text });
const { onChangeText } = this.props;
onChangeText && onChangeText(text);
let value = text;
const { onChangeText, limitTextLength } = this.props;
if (limitTextLength && limitTextLength < text.length) {
value = value.substring(0, limitTextLength);
}
this.setState({ text: value });
onChangeText && onChangeText(value);
}

render = ({
Expand All @@ -89,6 +93,7 @@ export default class Chat extends Component {
onRemoveUserData,
lastReadMessageId,
queueInfo,
limitTextLength,
...props
}, {
atBottom = true,
Expand Down Expand Up @@ -143,6 +148,11 @@ export default class Chat extends Component {
</Menu.Group>
</FooterOptions>
) : null}
limit={limitTextLength
? <ReminderCharacters
limitTextLength={limitTextLength}
textLenght={text.length}
/> : null}
>
<Composer onUpload={onUpload}
onSubmit={this.handleSubmit}
Expand All @@ -162,14 +172,15 @@ export default class Chat extends Component {
<ComposerAction onClick={this.handleUploadClick}>
<PlusIcon width={20} />
</ComposerAction>
)}
)}1
Copy link
Contributor

Choose a reason for hiding this comment

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

??

Copy link
Contributor

Choose a reason for hiding this comment

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

@oguhpereira what's the reason to add the 1 here?
I didn't get it, was it a mistake?
I noticed you left the 1 here after my review.

{text.length > 0 && (
<ComposerAction onClick={this.handleSendClick}>
<SendIcon width={20} />
</ComposerAction>
)}
</ComposerActions>
)}
limitTextLength={limitTextLength}
/>
</Screen.Footer>
</FilesDropTarget>
Expand Down
5 changes: 5 additions & 0 deletions src/routes/Chat/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
border-radius: 50%;
}
}

.none__action {
opacity: 0.6;
margin: 0 6px;
}
}

@keyframes loader-rotate {
Expand Down