@linktr.ee/messaging-react 1.9.2 → 1.9.3

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": "@linktr.ee/messaging-react",
3
- "version": "1.9.2",
3
+ "version": "1.9.3",
4
4
  "description": "React messaging components built on messaging-core for web applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,97 @@
1
+ import { XIcon } from '@phosphor-icons/react'
2
+ import React from 'react'
3
+ import {
4
+ LinkPreview,
5
+ LinkPreviewsManager,
6
+ LinkPreviewsManagerState,
7
+ } from 'stream-chat'
8
+ import { useMessageComposer, useStateStore } from 'stream-chat-react'
9
+
10
+ const linkPreviewsManagerStateSelector = (state: LinkPreviewsManagerState) => ({
11
+ linkPreviews: Array.from(state.previews.values()).filter(
12
+ (preview) =>
13
+ LinkPreviewsManager.previewIsLoaded(preview) ||
14
+ LinkPreviewsManager.previewIsLoading(preview)
15
+ ),
16
+ })
17
+
18
+ interface CustomLinkPreviewCardProps {
19
+ link: LinkPreview
20
+ onDismiss: (url: string) => void
21
+ }
22
+
23
+ const CustomLinkPreviewCard: React.FC<CustomLinkPreviewCardProps> = ({
24
+ link,
25
+ onDismiss,
26
+ }) => {
27
+ const { og_scrape_url, title, image_url } = link
28
+
29
+ const handleDismissLink = (e: React.MouseEvent) => {
30
+ e.preventDefault()
31
+ onDismiss(og_scrape_url)
32
+ }
33
+
34
+ return (
35
+ <a
36
+ href={og_scrape_url}
37
+ target="_blank"
38
+ rel="noopener noreferrer"
39
+ className="relative w-full block rounded-[24px] bg-[#121110] p-2 no-underline transition-opacity hover:opacity-90"
40
+ >
41
+ {image_url && (
42
+ <img
43
+ src={image_url}
44
+ alt={title || ''}
45
+ className="h-[148px] w-full rounded-[20px] object-cover"
46
+ />
47
+ )}
48
+ <button
49
+ type="button"
50
+ onClick={handleDismissLink}
51
+ className="absolute right-4 top-4 flex size-6 items-center justify-center rounded-full border border-white/40 bg-white/70 backdrop-blur-2xl"
52
+ aria-label="Close link preview"
53
+ >
54
+ <XIcon className="size-4 text-black/90" />
55
+ </button>
56
+ <div className="p-2">
57
+ {title && (
58
+ <div className="text-[14px] font-medium leading-5 text-white">
59
+ {title}
60
+ </div>
61
+ )}
62
+ <div className="text-[12px] leading-4 text-white/55">
63
+ {og_scrape_url}
64
+ </div>
65
+ </div>
66
+ </a>
67
+ )
68
+ }
69
+
70
+ export const CustomLinkPreviewList = () => {
71
+ const { linkPreviewsManager } = useMessageComposer()
72
+
73
+ const { linkPreviews: stateLinkPreviews } = useStateStore(
74
+ linkPreviewsManager.state,
75
+ linkPreviewsManagerStateSelector
76
+ )
77
+
78
+ const handleDismiss = (url: string) => {
79
+ linkPreviewsManager.dismissPreview(url)
80
+ }
81
+
82
+ const showLinkPreviews = stateLinkPreviews.length > 0
83
+
84
+ if (!showLinkPreviews) return null
85
+
86
+ return (
87
+ <div className="str-chat__link-preview-list p-0 gap-2 mb-4">
88
+ {stateLinkPreviews.map((linkPreview) => (
89
+ <CustomLinkPreviewCard
90
+ key={linkPreview.og_scrape_url}
91
+ link={linkPreview}
92
+ onDismiss={handleDismiss}
93
+ />
94
+ ))}
95
+ </div>
96
+ )
97
+ }
@@ -2,7 +2,6 @@ import { ArrowUpIcon } from '@phosphor-icons/react'
2
2
  import React from 'react'
3
3
  import {
4
4
  AttachmentPreviewList,
5
- LinkPreviewList,
6
5
  MessageInput,
7
6
  QuotedMessagePreview,
8
7
  SimpleAttachmentSelector,
@@ -11,6 +10,8 @@ import {
11
10
  useMessageInputContext,
12
11
  } from 'stream-chat-react'
13
12
 
13
+ import { CustomLinkPreviewList } from '../CustomLinkPreviewList'
14
+
14
15
  const CustomMessageInputInner: React.FC = () => {
15
16
  const { handleSubmit } = useMessageInputContext()
16
17
  const hasSendableData = useMessageComposerHasSendableData()
@@ -20,9 +21,9 @@ const CustomMessageInputInner: React.FC = () => {
20
21
  <div className="left-container">
21
22
  <SimpleAttachmentSelector />
22
23
  </div>
23
- <div className="central-container w-full p-2 bg-white rounded-lg shadow-[0_4px_16px_0_rgba(0,0,0,0.08),0_1px_2px_0_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.04)]">
24
+ <div className="central-container min-w-0 w-full p-2 bg-white rounded-lg shadow-[0_4px_16px_0_rgba(0,0,0,0.08),0_1px_2px_0_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.04)]">
24
25
  <QuotedMessagePreview />
25
- <LinkPreviewList />
26
+ <CustomLinkPreviewList />
26
27
  <AttachmentPreviewList />
27
28
  <div className="flex">
28
29
  <div className="w-full ml-2 mr-4">