Skip to content

186 style scroll chat composer #189

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

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cac2757
first attempt at fixing newline issue from message bodies
gyasi-eco Apr 24, 2023
8754e1b
remove format method call
gyasi-eco Apr 26, 2023
592988b
add changeset and update changeset version
gyasi-eco Apr 26, 2023
78b17ef
adding text area auto size component
gyasi-eco Apr 26, 2023
572d132
add to changeset
gyasi-eco Apr 26, 2023
1912981
remove textarea container
gyasi-eco Apr 26, 2023
ff99ef4
replace custom textarea styling with pasteb textarea component
gyasi-eco May 3, 2023
000b192
remove external resizeable textarea component
gyasi-eco May 3, 2023
3895a09
initial commit of replacing custom messagelog with chatlog
gyasi-eco May 16, 2023
1490940
upgrade paste version to 19.0.0
gyasi-eco May 17, 2023
47c985d
add ChatLog component
gyasi-eco May 23, 2023
78ae115
add editor state and onChange for ChatComposer
gyasi-eco May 23, 2023
ab90920
remove unused imports
gyasi-eco May 23, 2023
673e858
replace onChange event listener with CTA button click for form submis…
gyasi-eco Jun 8, 2023
f038db4
revert to onChange event and remove aria-label placeholder data
gyasi-eco Jun 13, 2023
1697505
upgrade react to 18, icons to 11.1 and locally define async in PhoneN…
gyasi-eco Jun 13, 2023
4010387
revert from paste chatlog to custom messaging component
gyasi-eco Jun 14, 2023
0ef9026
upgrade paste library and add ClearEditorPlugin
gyasi-eco Sep 1, 2023
c05e275
first attempt at fixing newline issue from message bodies
gyasi-eco Apr 24, 2023
0c6bf1f
remove format method call
gyasi-eco Apr 26, 2023
42406a4
adding text area auto size component
gyasi-eco Apr 26, 2023
05ecf19
add to changeset
gyasi-eco Apr 26, 2023
623b60e
remove textarea container
gyasi-eco Apr 26, 2023
5eb5800
replace custom textarea styling with pasteb textarea component
gyasi-eco May 3, 2023
3baf128
remove external resizeable textarea component
gyasi-eco May 3, 2023
671c7ac
add ChatLog component
gyasi-eco May 23, 2023
1a289a3
add editor state and onChange for ChatComposer
gyasi-eco May 23, 2023
9fa63c7
remove unused imports
gyasi-eco May 23, 2023
462fe09
replace onChange event listener with CTA button click for form submis…
gyasi-eco Jun 8, 2023
d1d49ff
revert to onChange event and remove aria-label placeholder data
gyasi-eco Jun 13, 2023
1d4f762
upgrade react to 18, icons to 11.1 and locally define async in PhoneN…
gyasi-eco Jun 13, 2023
2544749
revert from paste chatlog to custom messaging component
gyasi-eco Jun 14, 2023
0b2bf8c
upgrade paste library and add ClearEditorPlugin
gyasi-eco Sep 1, 2023
ad8be78
move dependencies to dev ui package.json
gyasi-eco Sep 7, 2023
0452402
implement clear editor plugin component using editor state
gyasi-eco Oct 5, 2023
95c73b5
resolve merge conflicts
gyasi-eco Oct 10, 2023
8646e83
fix soft phone overflow cutoff and chatcomposer submit button location
gyasi-eco Oct 17, 2023
516695c
Restyle and reorganize components
ayyrickay Nov 3, 2023
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: 6 additions & 0 deletions .changeset/tender-geckos-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-labs/dev-phone-ui": patch
---

Preserve newlines in inbound and outbound sms.
Add react text area auto resize component.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
"packages/dev-phone-ui"
],
"devDependencies": {
"@changesets/cli": "^2.23.0",
"@changesets/cli": "^2.26.1",
"turbo": "^1.2.16"
},
"dependencies": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

These dependencies should be in the UI package, not up at the top - these aren't necessary for the dev-phone-plugin

"react": "^18.2.0",
"react-dom": "^18.2.0",
"redux": "^4.2.1"
}
}
12 changes: 9 additions & 3 deletions packages/dev-phone-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
"webpack": "^5.69.1",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4",
"webpack-license-plugin": "^4.2.2"
"webpack-license-plugin": "^4.2.2",
"@changesets/cli": "^2.26.1",
"turbo": "^1.2.16"
},
"dependencies": {
"@twilio-paste/core": "^19.0.0",
"@twilio-paste/icons": "^11.1.0",
"@twilio-paste/core": "^20.2.0",
"@twilio-paste/icons": "^12.1.0",
"@twilio/conversations": "^2.0.0",
"@twilio/voice-sdk": "^2.1.0",
"date-fns": "^2.28.0",
Expand All @@ -43,6 +45,10 @@
"twilio-sync": "^3.0.6",
"util": "^0.12.4"
},
"overrides": {
"@twilio-paste/core": "^20.2.0",
"@twilio-paste/icons": "^12.1.0"
},
"peerDependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,35 @@ function PhoneNumberPickerContainer({ children }) {
{children}
</Box>
}
const numPicker = async () => {
if (!selectedPn) {
try {
const response = await fetch('/phone-numbers')
const data = await response.json()
data["phone-numbers"].sort(
sortUnconfiguredNumbersFirstThenAlphabetically
)
setTwilioPns(data["phone-numbers"]);
if (data["phone-numbers"].length !== 0) {
setSelectedPn(
getPnDetailsByNumber(
data["phone-numbers"][0].phoneNumber,
data["phone-numbers"]
)
);
}
} catch (error) {
console.error(error)
}
}
}

function PhoneNumberPicker({ configureNumberInUse, phoneNumbers }) {
const [twilioPns, setTwilioPns] = useState(null);
const [selectedPn, setSelectedPn] = useState(null);

useEffect(() => {
numPicker();
useEffect( () => {
const asyncFn = async() => {
if (!selectedPn) {
try {
const response = await fetch('/phone-numbers')
const data = await response.json()
data["phone-numbers"].sort(
sortUnconfiguredNumbersFirstThenAlphabetically
)
setTwilioPns(data["phone-numbers"]);
if (data["phone-numbers"].length !== 0) {
setSelectedPn(
getPnDetailsByNumber(
data["phone-numbers"][0].phoneNumber,
data["phone-numbers"]
)
);
}
} catch (error) {
console.error(error)
}
}
}
asyncFn()
}, [selectedPn]);

if (twilioPns === null) {
Expand Down
13 changes: 5 additions & 8 deletions packages/dev-phone-ui/src/components/SendSmsForm/MessageList.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import {
Box, Flex, SkeletonLoader,
Text, ChatLog, ChatMessage,
ChatBubble, ChatMessageMeta, ChatMessageMetaItem,
Avatar
} from "@twilio-paste/core"
import { UserIcon } from '@twilio-paste/icons/esm/UserIcon';
import { Box, SkeletonLoader } from "@twilio-paste/core"
import { ChatLog, ChatMessage, ChatBubble, ChatMessageMeta, ChatMessageMetaItem } from "@twilio-paste/chat-log";
import { Avatar } from "@twilio-paste/avatar";
import { useSelector } from "react-redux"
import EmptyMessageList from "./EmptyMessageList";



function MessageList({ devPhoneName }) {
const messageList = useSelector(state => state.messageList)
const numberInUse = useSelector(state => state.numberInUse ? state.numberInUse.phoneNumber : "");
Expand All @@ -27,7 +24,7 @@ function MessageList({ devPhoneName }) {
</ChatBubble>
<ChatMessageMeta aria-label={!isFromDevPhone ? "said by outbound user" : "said by dev phone"}>
<ChatMessageMetaItem>
<Avatar size="sizeIcon30" name={message.author} icon={UserIcon} />
<Avatar size="sizeIcon30" name={message.author} />
{message.author}
</ChatMessageMetaItem>
</ChatMessageMeta>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {useLexicalComposerContext, CLEAR_EDITOR_COMMAND } from "@twilio-paste/core/lexical-library";
import { Button } from "@twilio-paste/core";
import {CustomizationProvider} from '@twilio-paste/core/customization';
import { SendIcon } from '@twilio-paste/icons/esm/SendIcon';

// Renders a send button for the Paste Chat Composer
function SendButtonPlugin({ onClick, canSendMessages }) {

const [editor] = useLexicalComposerContext();

const sendIt = (e) => {
onClick(e);
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined);
}

return (
Copy link
Collaborator

Choose a reason for hiding this comment

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

I found the CustomizationProvider (below) which should allow us to do a better job of styling. As-is, I don't think we can ship it, it looks way too odd to me. But maybe we can target the individual elements better to style them in a way that makes more sense.

<CustomizationProvider
elements={{
SMS_SEND_BUTTON: {
float: 'right',
},
}}
>
<Button element="SMS_SEND_BUTTON" onClick={sendIt} type={"submit"} disabled={!canSendMessages}>
<SendIcon decorative />
Send
</Button>
</CustomizationProvider>
)
}

export default SendButtonPlugin;
62 changes: 38 additions & 24 deletions packages/dev-phone-ui/src/components/SendSmsForm/SendSmsForm.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { useContext, useState, useMemo } from "react";
import { Button, Input, Label, Box, Grid, Column } from "@twilio-paste/core";
import { SendIcon } from '@twilio-paste/icons/esm/SendIcon';
import React, { useContext, useState, useMemo } from "react";
import { useSelector } from "react-redux";
import { Label, Box, Grid, HelpText, Column, AutoScrollPlugin } from "@twilio-paste/core";
import { ChatComposer } from "@twilio-paste/core/chat-composer";
import { TwilioConversationsContext } from '../WebsocketManagers/ConversationsManager';
import MessageList from "./MessageList"
import { $getRoot, ClearEditorPlugin } from "@twilio-paste/core/lexical-library";
import SendButtonPlugin from "./SendButtonPlugin";

// Top-level container for Dev Phone SMS
function SendSmsForm({ numberInUse }) {
const [messageBody, setMessageBody] = useState('');

const channelData = useSelector(state => state.channelData)
const destinationNumber = useSelector(state => state.destinationNumber)

const conversationsClient = useContext(TwilioConversationsContext)
const {sendMessage, sendSms} = conversationsClient
const { sendMessage, sendSms } = conversationsClient

const canSendMessages = useMemo(() => {
return destinationNumber && destinationNumber.length > 6;
}, [destinationNumber]);

// Handles the UI state for sending messages
const sendIt = async (e) => {
e.preventDefault()
if (canSendMessages) {
Expand All @@ -30,32 +32,44 @@ function SendSmsForm({ numberInUse }) {
}
};

const myOnChange = (editorState) => {
editorState.read(() => {
const root = $getRoot();
setMessageBody(root.getTextContent());
});
};


return (
<Box width="100%" backgroundColor={"colorBackgroundBody"}>
<Box width="100%" backgroundColor={"default"} overflowX="hidden" overflowY="auto">
<MessageList
devPhoneName={channelData.devPhoneName}
/>
<form onSubmit={(e) => sendIt(e)} method={"GET"}>
<Label htmlFor="sendSmsBody" required>Message</Label>
<Grid gutter={"space20"} marginBottom="space40">
<Column span={10}>
<Input id="sendSmsBody" type="text" value={messageBody} onChange={(e) => setMessageBody(e.target.value)} />
</Column>
<Column span={2}>
<Button type={"submit"} disabled={!canSendMessages}>
<SendIcon decorative />
Send
</Button>
</Column>
</Grid>
</form>
<Label htmlFor="sendSmsBody" required>Message</Label>

<Grid gutter={"space20"} marginBottom="space40">
<Column span={12}>
<ChatComposer
Copy link
Collaborator

@ayyrickay ayyrickay Nov 3, 2023

Choose a reason for hiding this comment

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

I simplified the use of Paste here, I don't think we can componentize our way out of this. I have no idea how lexical manages this - I tried using Flexbox and the button just floats left. But there must be some way to manage it sensibly.

config={{
namespace: "send_sms",
onError: (e) => {
throw e;
}
}}
placeholder="Chat text"
ariaLabel="A basic chat composer"
onChange={myOnChange}
element="SEND_SMS_COMPOSER"
>
<ClearEditorPlugin />
<SendButtonPlugin canSendMessages={canSendMessages} onClick={sendIt} />
</ChatComposer>
<HelpText id="send_sms_help_text">Enter at most 1600 characters</HelpText>
</Column>
</Grid>
</Box>

);
}





export default SendSmsForm;
3 changes: 2 additions & 1 deletion packages/dev-phone-ui/src/components/Softphone/Softphone.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ function Softphone({ numberInUse }) {
return (
<Box
maxWidth={"75%"}
maxHeight={"size80"}
maxHeight={"size90"}
margin={"auto"}
marginY={"space120"}
backgroundColor={"colorBackgroundBody"}
boxShadow={"shadow"}
borderRadius={"borderRadius20"}
overflowY="auto"
>
<Grid>
<Column span={showCallHistory ? 4 : 0}>
Expand Down