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 5 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
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 CharCounter = ({ className, style = {}, textLength, limitTextLength }) => (
<span
className={createClassName(styles, 'footer__remainder', { highlight: textLength === limitTextLength }, [className])}
style={style}
>
{textLength} / {limitTextLength}
</span>
);
11 changes: 11 additions & 0 deletions src/components/Footer/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@

@include pressable-button(2px);
}

&__remainder {
margin-left: 10px;
min-width: 100px;
font-weight: bold;
&--highlight {
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, 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
? <CharCounter
limitTextLength={limitTextLength}
textLength={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
3 changes: 2 additions & 1 deletion src/routes/Chat/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ export const ChatConnector = ({ ref, ...props }) => (
allowSwitchingDepartments,
forceAcceptDataProcessingConsent: allowRemoveUserData,
showConnecting,
limitTextLength,
} = {},
messages: {
conversationFinishedMessage,
Expand Down Expand Up @@ -426,7 +427,7 @@ export const ChatConnector = ({ ref, ...props }) => (
estimatedWaitTimeSeconds: queueInfo.estimatedWaitTimeSeconds,
message: queueInfo.message,
} : undefined}

limitTextLength={limitTextLength}
/>
)}
</Consumer>
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