@tellescope/chat 0.0.57 → 0.0.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tellescope/chat",
3
- "version": "0.0.57",
3
+ "version": "0.0.60",
4
4
  "description": "",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",
@@ -33,13 +33,13 @@
33
33
  "@fontsource/roboto": "^4.5.1",
34
34
  "@mui/icons-material": "^5.0.1",
35
35
  "@mui/material": "^5.0.2",
36
- "@tellescope/constants": "^0.0.57",
37
- "@tellescope/react-components": "^0.0.57",
38
- "@tellescope/sdk": "^0.0.57",
39
- "@tellescope/types-client": "^0.0.57",
40
- "@tellescope/types-models": "^0.0.57",
41
- "@tellescope/types-utilities": "^0.0.57",
42
- "@tellescope/utilities": "^0.0.57",
36
+ "@tellescope/constants": "^0.0.60",
37
+ "@tellescope/react-components": "^0.0.60",
38
+ "@tellescope/sdk": "^0.0.60",
39
+ "@tellescope/types-client": "^0.0.60",
40
+ "@tellescope/types-models": "^0.0.60",
41
+ "@tellescope/types-utilities": "^0.0.60",
42
+ "@tellescope/utilities": "^0.0.60",
43
43
  "@typescript-eslint/eslint-plugin": "^4.33.0",
44
44
  "@typescript-eslint/parser": "^4.33.0",
45
45
  "eslint": "^7.32.0",
@@ -50,7 +50,7 @@
50
50
  "react": "^17.0.2",
51
51
  "react-dom": "^17.0.2"
52
52
  },
53
- "gitHead": "7a830676f46cdc5d10961aa85f79ad669e4acffb",
53
+ "gitHead": "576d65bb0853dd189a81a4a5f463ed9ece05832d",
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  }
package/src/chat.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useState, CSSProperties } from "react"
1
+ import React, { useState, CSSProperties, useEffect } from "react"
2
2
 
3
3
  import {
4
4
  AsyncIconButton,
@@ -172,6 +172,12 @@ export const Message = ({
172
172
  )
173
173
  }
174
174
 
175
+ export const MessageAttachments = ({ message } : { message: ChatMessage }) => {
176
+ return (
177
+ <Typography>Attachments: {JSON.stringify(message.attachments, null, 2)}</Typography>
178
+ )
179
+ }
180
+
175
181
  interface Messages_T extends MessageStyles {
176
182
  resolveSenderName?: (room: ChatRoom) => React.ReactNode;
177
183
  messages: LoadedData<ChatMessage[]>,
@@ -192,7 +198,12 @@ export const Messages = ({
192
198
  <Flex column flex={1}>
193
199
  {Header && <Header {...headerProps}/>}
194
200
  <List reverse style={style} items={messages} render={message => (
195
- <Message key={message.id} message={message} {...messageStyles}/>
201
+ <Flex column>
202
+ {message.message && <Message key={message.id} message={message} {...messageStyles}/>}
203
+ {message.attachments && message.attachments.length > 0 &&
204
+ <MessageAttachments message={message} />
205
+ }
206
+ </Flex>
196
207
  )}/>
197
208
  </Flex>
198
209
  )}/>
@@ -316,6 +327,9 @@ interface SendMessage_T {
316
327
  placeholderText?: string;
317
328
  Icon?: React.ElementType<any>;
318
329
  style?: CSSProperties;
330
+
331
+ // web only
332
+ sendOnEnterPress?: boolean,
319
333
  }
320
334
  export const SendMessage = ({
321
335
  roomId,
@@ -324,22 +338,51 @@ export const SendMessage = ({
324
338
  onNewMessage,
325
339
  placeholderText="Enter a message",
326
340
  style={},
341
+ sendOnEnterPress,
327
342
  }: SendMessage_T) => {
328
343
  const [message, setMessage] = useState('')
329
344
  const [sending, setSending] = useState(false)
345
+
346
+ const [disabled, setDisabled] = useState(false)
347
+ const [chatFocused, setChatFocused] = React.useState(false)
330
348
 
331
349
  const [, { createElement: createMessage }] = useChats(roomId, type)
332
350
 
351
+ useEffect(() => {
352
+ if (!chatFocused) return
353
+ if (!sendOnEnterPress) return
354
+ if (typeof window === 'undefined') return
355
+
356
+ const handleSend = (e: any) => {
357
+ if (e.key !== 'Enter') return
358
+ setDisabled(true)
359
+
360
+ createMessage({ message, roomId })
361
+ .then(m => {
362
+ setMessage('')
363
+ onNewMessage?.(m)
364
+ })
365
+ .catch(console.error)
366
+ .finally(() => setDisabled(false))
367
+ }
368
+
369
+ window.addEventListener('keypress', handleSend)
370
+ return () => { window.removeEventListener('keypress', handleSend) }
371
+ }, [sendOnEnterPress, chatFocused, message, roomId])
372
+
333
373
  return (
334
374
  <Flex row flex={1} alignContent="center" style={style}>
335
375
  <Flex column flex={1}>
336
376
  <TextField variant="outlined" value={message} onChange={setMessage} disabled={sending}
337
377
  aria-label="Enter a message"
338
378
  placeholder={placeholderText}
379
+ onFocus={() => setChatFocused(true)}
380
+ onBlur={() => setChatFocused(false)}
339
381
  />
340
382
  </Flex>
341
383
  <Flex column alignSelf="center">
342
- <AsyncIconButton label="send" Icon={Icon} disabled={message === ''}
384
+ <AsyncIconButton label="send" Icon={Icon}
385
+ disabled={message === '' || disabled}
343
386
  action={() => createMessage({ message, roomId })}
344
387
  onSuccess={m => {
345
388
  setMessage('')