@linktr.ee/messaging-react 1.29.0-rc-1776320021 → 1.29.0-rc-1776402883
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/dist/Visitor-BcyrCpuF.js +196 -0
- package/dist/Visitor-BcyrCpuF.js.map +1 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.js +416 -419
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ChannelList/index.test.tsx +14 -4
- package/src/components/ChannelList/index.tsx +17 -1
- package/src/components/ChannelView.tsx +5 -8
- package/src/components/CustomMessage/CustomMessage.stories.tsx +11 -6
- package/src/components/CustomMessage/index.tsx +1 -1
- package/src/components/LockedAttachment/LockedAttachment.stories.tsx +19 -49
- package/src/components/LockedAttachment/components/Visitor.tsx +21 -71
- package/src/hooks/useRestorePendingMessages.test.ts +15 -47
- package/src/hooks/useRestorePendingMessages.ts +8 -25
- package/dist/Visitor-C4WqnN8H.js +0 -218
- package/dist/Visitor-C4WqnN8H.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
+
import type { Channel } from 'stream-chat'
|
|
2
3
|
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
|
3
4
|
|
|
4
5
|
import { renderWithProviders } from '../../test/utils'
|
|
@@ -77,8 +78,8 @@ describe('ChannelList', () => {
|
|
|
77
78
|
expect(streamProps.onAddedToChannel).toBe(onAddedToChannel)
|
|
78
79
|
})
|
|
79
80
|
|
|
80
|
-
it('
|
|
81
|
-
const filterFn = vi.fn()
|
|
81
|
+
it('wraps channelRenderFilterFn to restore pending messages and delegates to consumer filter', () => {
|
|
82
|
+
const filterFn = vi.fn((channels: Channel[]) => channels)
|
|
82
83
|
|
|
83
84
|
renderWithProviders(
|
|
84
85
|
React.createElement(ChannelList, {
|
|
@@ -89,9 +90,18 @@ describe('ChannelList', () => {
|
|
|
89
90
|
|
|
90
91
|
expect(streamChannelListMock).toHaveBeenCalledOnce()
|
|
91
92
|
const streamProps = streamChannelListMock.mock.calls[0][0] as {
|
|
92
|
-
channelRenderFilterFn?: unknown
|
|
93
|
+
channelRenderFilterFn?: (channels: unknown[]) => unknown[]
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
|
|
96
|
+
// The wrapper should not be the same reference as the original filter
|
|
97
|
+
expect(streamProps.channelRenderFilterFn).not.toBe(filterFn)
|
|
98
|
+
expect(typeof streamProps.channelRenderFilterFn).toBe('function')
|
|
99
|
+
|
|
100
|
+
// When the wrapper is called, it should delegate to the consumer's filter
|
|
101
|
+
const mockChannels = [
|
|
102
|
+
{ cid: 'ch-1', state: { pending_messages: [], addMessageSorted: vi.fn() } },
|
|
103
|
+
]
|
|
104
|
+
streamProps.channelRenderFilterFn!(mockChannels)
|
|
105
|
+
expect(filterFn).toHaveBeenCalledWith(mockChannels)
|
|
96
106
|
})
|
|
97
107
|
})
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import classNames from 'classnames'
|
|
2
2
|
import React from 'react'
|
|
3
|
+
import type { Channel } from 'stream-chat'
|
|
3
4
|
import { ChannelList as StreamChannelList } from 'stream-chat-react'
|
|
4
5
|
|
|
6
|
+
import { restorePendingMessages } from '../../hooks/useRestorePendingMessages'
|
|
5
7
|
import { useMessagingContext } from '../../providers/MessagingProvider'
|
|
6
8
|
import type { ChannelListProps } from '../../types'
|
|
7
9
|
|
|
@@ -34,6 +36,20 @@ export const ChannelList = React.memo<ChannelListProps>(
|
|
|
34
36
|
// Get debug flag from context
|
|
35
37
|
const { debug = false } = useMessagingContext()
|
|
36
38
|
|
|
39
|
+
// Wrap channelRenderFilterFn to restore pending messages for all channels
|
|
40
|
+
// as soon as they are loaded, without waiting for the user to click into each one.
|
|
41
|
+
const wrappedChannelRenderFilterFn = React.useCallback(
|
|
42
|
+
(channels: Channel[]) => {
|
|
43
|
+
for (const channel of channels) {
|
|
44
|
+
restorePendingMessages(channel)
|
|
45
|
+
}
|
|
46
|
+
return channelRenderFilterFn
|
|
47
|
+
? channelRenderFilterFn(channels)
|
|
48
|
+
: channels
|
|
49
|
+
},
|
|
50
|
+
[channelRenderFilterFn]
|
|
51
|
+
)
|
|
52
|
+
|
|
37
53
|
if (debug) {
|
|
38
54
|
console.log('📺 [ChannelList] 🔄 RENDER START', {
|
|
39
55
|
renderCount: renderCountRef.current,
|
|
@@ -72,7 +88,7 @@ export const ChannelList = React.memo<ChannelListProps>(
|
|
|
72
88
|
}
|
|
73
89
|
onMessageNew={onMessageNew}
|
|
74
90
|
onAddedToChannel={onAddedToChannel}
|
|
75
|
-
channelRenderFilterFn={
|
|
91
|
+
channelRenderFilterFn={wrappedChannelRenderFilterFn}
|
|
76
92
|
Preview={CustomChannelPreview}
|
|
77
93
|
EmptyStateIndicator={customEmptyStateIndicator}
|
|
78
94
|
/>
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ArrowLeftIcon,
|
|
3
|
-
DotsThreeIcon,
|
|
4
|
-
StarIcon,
|
|
5
|
-
} from '@phosphor-icons/react'
|
|
1
|
+
import { ArrowLeftIcon, DotsThreeIcon, StarIcon } from '@phosphor-icons/react'
|
|
6
2
|
import classNames from 'classnames'
|
|
7
3
|
import React, { useCallback, useRef } from 'react'
|
|
8
4
|
import { Channel as ChannelType, LocalMessage } from 'stream-chat'
|
|
@@ -17,7 +13,6 @@ import {
|
|
|
17
13
|
} from 'stream-chat-react'
|
|
18
14
|
|
|
19
15
|
import { useChannelStar } from '../hooks/useChannelStar'
|
|
20
|
-
import { useRestorePendingMessages } from '../hooks/useRestorePendingMessages'
|
|
21
16
|
import type { ChannelViewProps, LockedAttachmentSource } from '../types'
|
|
22
17
|
|
|
23
18
|
import { Avatar } from './Avatar'
|
|
@@ -212,7 +207,10 @@ const ChannelViewInner: React.FC<{
|
|
|
212
207
|
onReportParticipantClick?: () => void
|
|
213
208
|
showStarButton?: boolean
|
|
214
209
|
chatbotVotingEnabled?: boolean
|
|
215
|
-
onAttachmentUnlock?: (
|
|
210
|
+
onAttachmentUnlock?: (
|
|
211
|
+
message: LocalMessage,
|
|
212
|
+
channel: ChannelType
|
|
213
|
+
) => Promise<LockedAttachmentSource>
|
|
216
214
|
onAttachmentDownload?: (message: LocalMessage, channel: ChannelType) => void
|
|
217
215
|
renderChannelBanner?: () => React.ReactNode
|
|
218
216
|
customProfileContent?: React.ReactNode
|
|
@@ -242,7 +240,6 @@ const ChannelViewInner: React.FC<{
|
|
|
242
240
|
renderMessage,
|
|
243
241
|
}) => {
|
|
244
242
|
const { channel } = useChannelStateContext()
|
|
245
|
-
useRestorePendingMessages(channel)
|
|
246
243
|
const infoDialogRef = useRef<HTMLDialogElement>(null)
|
|
247
244
|
|
|
248
245
|
// Get participant info for info dialog
|
|
@@ -106,6 +106,11 @@ interface TemplateProps {
|
|
|
106
106
|
| 'MESSAGE_PAID'
|
|
107
107
|
| 'MESSAGE_CHATBOT'
|
|
108
108
|
| 'MESSAGE_ATTACHMENT'
|
|
109
|
+
payment_status?:
|
|
110
|
+
| 'pending'
|
|
111
|
+
| 'paid'
|
|
112
|
+
| 'failed'
|
|
113
|
+
| 'refunded'
|
|
109
114
|
amount_text?: string
|
|
110
115
|
attachment_title?: string
|
|
111
116
|
attachment_mime_type?: string
|
|
@@ -316,7 +321,12 @@ PaidAttachment.args = {
|
|
|
316
321
|
},
|
|
317
322
|
{
|
|
318
323
|
id: 'msg-2',
|
|
319
|
-
text: '
|
|
324
|
+
text: 'Yes, of course!',
|
|
325
|
+
user: storyUsers.creator,
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
id: 'msg-3',
|
|
329
|
+
text: 'let me know if you have any questions!',
|
|
320
330
|
user: storyUsers.creator,
|
|
321
331
|
metadata: {
|
|
322
332
|
custom_type: 'MESSAGE_ATTACHMENT',
|
|
@@ -327,11 +337,6 @@ PaidAttachment.args = {
|
|
|
327
337
|
attachment_detail: '1:20',
|
|
328
338
|
},
|
|
329
339
|
},
|
|
330
|
-
{
|
|
331
|
-
id: 'msg-3',
|
|
332
|
-
text: 'let me know if you have any questions!',
|
|
333
|
-
user: storyUsers.creator,
|
|
334
|
-
},
|
|
335
340
|
{
|
|
336
341
|
id: 'msg-4',
|
|
337
342
|
text: 'Looks amazing, unlocking now!',
|
|
@@ -202,7 +202,7 @@ const CustomMessageWithContext = (props: CustomMessageWithContextProps) => {
|
|
|
202
202
|
}}
|
|
203
203
|
>
|
|
204
204
|
{isAttachment ? (
|
|
205
|
-
<div className="flex flex-col gap-
|
|
205
|
+
<div className={classNames("flex flex-col gap-1", isMine ? "items-end" : "items-start")}>
|
|
206
206
|
<LockedAttachment
|
|
207
207
|
title={message.metadata?.attachment_title}
|
|
208
208
|
mimeType={message.metadata?.attachment_mime_type}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Meta, StoryFn } from '@storybook/react'
|
|
2
|
-
import React
|
|
2
|
+
import React from 'react'
|
|
3
3
|
|
|
4
|
-
import LockedAttachment
|
|
4
|
+
import LockedAttachment from '.'
|
|
5
5
|
|
|
6
6
|
const VIDEO_THUMBNAIL_BLURRED = '/video-thumbnail-blurred.jpg'
|
|
7
7
|
const VIDEO_SOURCE = '/video-source.mp4'
|
|
@@ -22,42 +22,11 @@ const meta: Meta = {
|
|
|
22
22
|
}
|
|
23
23
|
export default meta
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const withDelay = <T,>(fn: () => Promise<T> | T) => async (): Promise<T> => {
|
|
26
|
+
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
27
|
+
return fn()
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
/** Simulates a slow network by withholding the source for 2s, then loading via blob URL. */
|
|
30
|
-
type SlowCreatorPreviewProps = Omit<CreatorCardProps, 'isPreview'> & { sourcePath: string }
|
|
31
|
-
const SlowCreatorPreview = ({ sourcePath, ...props }: SlowCreatorPreviewProps) => {
|
|
32
|
-
const [source, setSource] = useState<string | undefined>(undefined)
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
setSource(undefined)
|
|
35
|
-
let cancelled = false
|
|
36
|
-
const load = async () => {
|
|
37
|
-
await new Promise((resolve) => setTimeout(resolve, 2000))
|
|
38
|
-
const res = await fetch(sourcePath)
|
|
39
|
-
const blob = await res.blob()
|
|
40
|
-
if (!cancelled) setSource(URL.createObjectURL(blob))
|
|
41
|
-
}
|
|
42
|
-
void load()
|
|
43
|
-
return () => { cancelled = true }
|
|
44
|
-
}, [sourcePath])
|
|
45
|
-
return <LockedAttachment isCreator isPreview source={source} {...props} />
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const Interactive = ({ unlockedSource, ...props }: InteractiveProps) => (
|
|
49
|
-
<LockedAttachment
|
|
50
|
-
{...props}
|
|
51
|
-
onUnlock={async () => {
|
|
52
|
-
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
53
|
-
const res = await fetch(unlockedSource)
|
|
54
|
-
const blob = await res.blob()
|
|
55
|
-
return { source: URL.createObjectURL(blob) }
|
|
56
|
-
}}
|
|
57
|
-
onDownload={() => {}}
|
|
58
|
-
/>
|
|
59
|
-
)
|
|
60
|
-
|
|
61
30
|
const VARIANTS = [
|
|
62
31
|
{
|
|
63
32
|
label: 'Video',
|
|
@@ -168,13 +137,14 @@ export const Visitor: StoryFn = () => (
|
|
|
168
137
|
</td>
|
|
169
138
|
{VARIANTS.map(({ title, mimeType, detail, thumbnail, source }) => (
|
|
170
139
|
<td key={mimeType} className="align-top">
|
|
171
|
-
<
|
|
140
|
+
<LockedAttachment
|
|
172
141
|
title={title}
|
|
173
142
|
amountText="AU$9.99"
|
|
174
143
|
thumbnail={thumbnail}
|
|
175
144
|
mimeType={mimeType}
|
|
176
145
|
detail={detail}
|
|
177
|
-
|
|
146
|
+
onUnlock={withDelay(() => ({ source }))}
|
|
147
|
+
onDownload={() => {}}
|
|
178
148
|
/>
|
|
179
149
|
</td>
|
|
180
150
|
))}
|
|
@@ -185,14 +155,15 @@ export const Visitor: StoryFn = () => (
|
|
|
185
155
|
</td>
|
|
186
156
|
{VARIANTS.map(({ title, mimeType, detail, thumbnail, source }) => (
|
|
187
157
|
<td key={mimeType} className="align-top">
|
|
188
|
-
<
|
|
158
|
+
<LockedAttachment
|
|
189
159
|
title={title}
|
|
190
160
|
amountText="AU$9.99"
|
|
191
161
|
thumbnail={thumbnail}
|
|
192
162
|
mimeType={mimeType}
|
|
193
163
|
detail={detail}
|
|
194
|
-
unlockedSource={source}
|
|
195
164
|
paymentStatus="paid"
|
|
165
|
+
onUnlock={withDelay(() => ({ source }))}
|
|
166
|
+
onDownload={() => {}}
|
|
196
167
|
/>
|
|
197
168
|
</td>
|
|
198
169
|
))}
|
|
@@ -211,7 +182,7 @@ export const Visitor: StoryFn = () => (
|
|
|
211
182
|
detail={detail}
|
|
212
183
|
amountText="AU$9.99"
|
|
213
184
|
paymentStatus="paid"
|
|
214
|
-
onDownload={() =>
|
|
185
|
+
onDownload={() => {}}
|
|
215
186
|
/>
|
|
216
187
|
</td>
|
|
217
188
|
))}
|
|
@@ -230,9 +201,10 @@ export const Creator: StoryFn = () => (
|
|
|
230
201
|
</td>
|
|
231
202
|
{VARIANTS.map(({ mimeType, detail, thumbnail, source }) => (
|
|
232
203
|
<td key={mimeType} className="align-top">
|
|
233
|
-
<
|
|
204
|
+
<LockedAttachment
|
|
205
|
+
isPreview
|
|
234
206
|
thumbnail={thumbnail}
|
|
235
|
-
|
|
207
|
+
source={source}
|
|
236
208
|
mimeType={mimeType}
|
|
237
209
|
detail={detail}
|
|
238
210
|
placeholderAmountText="A$0.00"
|
|
@@ -247,7 +219,6 @@ export const Creator: StoryFn = () => (
|
|
|
247
219
|
{VARIANTS.map(({ title, mimeType, detail, thumbnail, source }) => (
|
|
248
220
|
<td key={mimeType} className="align-top">
|
|
249
221
|
<LockedAttachment
|
|
250
|
-
isCreator
|
|
251
222
|
title={title}
|
|
252
223
|
thumbnail={thumbnail}
|
|
253
224
|
source={source}
|
|
@@ -266,7 +237,7 @@ export const Creator: StoryFn = () => (
|
|
|
266
237
|
{VARIANTS.map(({ title, mimeType, detail, thumbnail, source }) => (
|
|
267
238
|
<td key={mimeType} className="align-top">
|
|
268
239
|
<LockedAttachment
|
|
269
|
-
|
|
240
|
+
|
|
270
241
|
title={title}
|
|
271
242
|
thumbnail={thumbnail}
|
|
272
243
|
source={source}
|
|
@@ -284,7 +255,6 @@ export const Creator: StoryFn = () => (
|
|
|
284
255
|
{VARIANTS.map(({ title, mimeType, detail, thumbnail, source }) => (
|
|
285
256
|
<td key={mimeType} className="align-top">
|
|
286
257
|
<LockedAttachment
|
|
287
|
-
isCreator
|
|
288
258
|
title={title}
|
|
289
259
|
thumbnail={thumbnail}
|
|
290
260
|
source={source}
|
|
@@ -311,7 +281,6 @@ export const NoThumbnail: StoryFn = () => (
|
|
|
311
281
|
{NO_THUMBNAIL_VARIANTS.map(({ title, mimeType, detail, source }) => (
|
|
312
282
|
<td key={mimeType} className="align-top">
|
|
313
283
|
<LockedAttachment
|
|
314
|
-
isCreator
|
|
315
284
|
title={title}
|
|
316
285
|
source={source}
|
|
317
286
|
mimeType={mimeType}
|
|
@@ -327,12 +296,13 @@ export const NoThumbnail: StoryFn = () => (
|
|
|
327
296
|
</td>
|
|
328
297
|
{NO_THUMBNAIL_VARIANTS.map(({ title, mimeType, detail, source }) => (
|
|
329
298
|
<td key={mimeType} className="align-top">
|
|
330
|
-
<
|
|
299
|
+
<LockedAttachment
|
|
331
300
|
title={title}
|
|
332
301
|
amountText="AU$9.99"
|
|
333
302
|
mimeType={mimeType}
|
|
334
303
|
detail={detail}
|
|
335
|
-
|
|
304
|
+
onUnlock={withDelay(() => ({ source }))}
|
|
305
|
+
onDownload={() => {}}
|
|
336
306
|
/>
|
|
337
307
|
</td>
|
|
338
308
|
))}
|
|
@@ -24,11 +24,8 @@ export interface VisitorCardProps extends LockedAttachmentBaseProps {
|
|
|
24
24
|
* Omit to hide the Unlock button.
|
|
25
25
|
*/
|
|
26
26
|
onUnlock?: () => Promise<LockedAttachmentSource>
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
* May return a Promise — if so, the component shows a loader until it resolves.
|
|
30
|
-
*/
|
|
31
|
-
onDownload?: () => void | Promise<void>
|
|
27
|
+
/** Called when the visitor clicks Download on an unlocked card. */
|
|
28
|
+
onDownload?: () => void
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
const getLockIcon = (paymentStatus?: PaymentStatus): React.ElementType =>
|
|
@@ -37,23 +34,14 @@ const getLockIcon = (paymentStatus?: PaymentStatus): React.ElementType =>
|
|
|
37
34
|
|
|
38
35
|
interface LockOverlayProps {
|
|
39
36
|
icon: React.ElementType
|
|
40
|
-
loading?: boolean
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
const LockOverlay: React.FC<LockOverlayProps> = (props) => {
|
|
44
|
-
const { icon: Icon
|
|
40
|
+
const { icon: Icon } = props
|
|
45
41
|
return (
|
|
46
42
|
<div className="absolute inset-0 bg-black/30">
|
|
47
43
|
<div className="absolute left-3 top-3 flex size-8 items-center justify-center rounded-full bg-black/60">
|
|
48
|
-
|
|
49
|
-
<span className="flex items-center gap-[2px]">
|
|
50
|
-
<span className="size-1 rounded-full bg-white animate-bounce [animation-delay:-0.3s]" />
|
|
51
|
-
<span className="size-1 rounded-full bg-white animate-bounce [animation-delay:-0.15s]" />
|
|
52
|
-
<span className="size-1 rounded-full bg-white animate-bounce" />
|
|
53
|
-
</span>
|
|
54
|
-
) : (
|
|
55
|
-
<Icon className="size-4 text-white" weight="fill" />
|
|
56
|
-
)}
|
|
44
|
+
<Icon className="size-4 text-white" weight="fill" />
|
|
57
45
|
</div>
|
|
58
46
|
</div>
|
|
59
47
|
)
|
|
@@ -63,11 +51,10 @@ interface LockedPreviewProps {
|
|
|
63
51
|
thumbnail?: string
|
|
64
52
|
mimeType: string
|
|
65
53
|
LockIcon: React.ElementType
|
|
66
|
-
loading?: boolean
|
|
67
54
|
}
|
|
68
55
|
|
|
69
56
|
const LockedPreview: React.FC<LockedPreviewProps> = (props) => {
|
|
70
|
-
const { thumbnail, mimeType, LockIcon
|
|
57
|
+
const { thumbnail, mimeType, LockIcon } = props
|
|
71
58
|
return (
|
|
72
59
|
<div className="relative aspect-video overflow-hidden bg-black/5">
|
|
73
60
|
{thumbnail ? (
|
|
@@ -84,7 +71,7 @@ const LockedPreview: React.FC<LockedPreviewProps> = (props) => {
|
|
|
84
71
|
})}
|
|
85
72
|
</div>
|
|
86
73
|
)}
|
|
87
|
-
<LockOverlay icon={LockIcon}
|
|
74
|
+
<LockOverlay icon={LockIcon} />
|
|
88
75
|
</div>
|
|
89
76
|
)
|
|
90
77
|
}
|
|
@@ -97,11 +84,10 @@ interface ImagePreviewProps {
|
|
|
97
84
|
title?: string
|
|
98
85
|
paymentStatus?: PaymentStatus
|
|
99
86
|
isLocked: boolean
|
|
100
|
-
loading?: boolean
|
|
101
87
|
}
|
|
102
88
|
|
|
103
89
|
const ImagePreview: React.FC<ImagePreviewProps> = (props) => {
|
|
104
|
-
const { source, thumbnail, mimeType, title, paymentStatus, isLocked
|
|
90
|
+
const { source, thumbnail, mimeType, title, paymentStatus, isLocked } = props
|
|
105
91
|
const [sourceReady, setSourceReady] = useState(false)
|
|
106
92
|
|
|
107
93
|
useEffect(() => {
|
|
@@ -114,7 +100,6 @@ const ImagePreview: React.FC<ImagePreviewProps> = (props) => {
|
|
|
114
100
|
thumbnail={thumbnail}
|
|
115
101
|
mimeType={mimeType}
|
|
116
102
|
LockIcon={getLockIcon(paymentStatus)}
|
|
117
|
-
loading={loading}
|
|
118
103
|
/>
|
|
119
104
|
)
|
|
120
105
|
}
|
|
@@ -136,11 +121,10 @@ interface DocumentPreviewProps {
|
|
|
136
121
|
mimeType: string
|
|
137
122
|
paymentStatus?: PaymentStatus
|
|
138
123
|
isLocked: boolean
|
|
139
|
-
loading?: boolean
|
|
140
124
|
}
|
|
141
125
|
|
|
142
126
|
const DocumentPreview: React.FC<DocumentPreviewProps> = (props) => {
|
|
143
|
-
const { thumbnail, mimeType, paymentStatus, isLocked
|
|
127
|
+
const { thumbnail, mimeType, paymentStatus, isLocked } = props
|
|
144
128
|
return (
|
|
145
129
|
<div className="relative aspect-video overflow-hidden bg-black/5">
|
|
146
130
|
{thumbnail ? (
|
|
@@ -157,7 +141,7 @@ const DocumentPreview: React.FC<DocumentPreviewProps> = (props) => {
|
|
|
157
141
|
})}
|
|
158
142
|
</div>
|
|
159
143
|
)}
|
|
160
|
-
{isLocked && <LockOverlay icon={getLockIcon(paymentStatus)}
|
|
144
|
+
{isLocked && <LockOverlay icon={getLockIcon(paymentStatus)} />}
|
|
161
145
|
</div>
|
|
162
146
|
)
|
|
163
147
|
}
|
|
@@ -168,18 +152,16 @@ interface MediaPreviewProps {
|
|
|
168
152
|
mimeType: string
|
|
169
153
|
paymentStatus?: PaymentStatus
|
|
170
154
|
isLocked: boolean
|
|
171
|
-
loading?: boolean
|
|
172
155
|
}
|
|
173
156
|
|
|
174
157
|
const MediaPreview: React.FC<MediaPreviewProps> = (props) => {
|
|
175
|
-
const { source, thumbnail, mimeType, paymentStatus, isLocked
|
|
158
|
+
const { source, thumbnail, mimeType, paymentStatus, isLocked } = props
|
|
176
159
|
if (isLocked) {
|
|
177
160
|
return (
|
|
178
161
|
<LockedPreview
|
|
179
162
|
thumbnail={thumbnail}
|
|
180
163
|
mimeType={mimeType}
|
|
181
164
|
LockIcon={getLockIcon(paymentStatus)}
|
|
182
|
-
loading={loading}
|
|
183
165
|
/>
|
|
184
166
|
)
|
|
185
167
|
}
|
|
@@ -198,16 +180,13 @@ const LoadingDots = () => (
|
|
|
198
180
|
interface CardActionsProps {
|
|
199
181
|
isLocked: boolean
|
|
200
182
|
unlockLoading: boolean
|
|
201
|
-
downloadLoading: boolean
|
|
202
|
-
paymentStatus?: PaymentStatus
|
|
203
183
|
source?: string
|
|
204
184
|
onUnlock?: () => void
|
|
205
185
|
onDownload?: () => void
|
|
206
186
|
}
|
|
207
187
|
|
|
208
188
|
const CardActions: React.FC<CardActionsProps> = (props) => {
|
|
209
|
-
const { isLocked, unlockLoading,
|
|
210
|
-
const LockIcon = getLockIcon(paymentStatus)
|
|
189
|
+
const { isLocked, unlockLoading, source, onUnlock, onDownload } = props
|
|
211
190
|
|
|
212
191
|
if (isLocked && onUnlock) {
|
|
213
192
|
return (
|
|
@@ -215,18 +194,14 @@ const CardActions: React.FC<CardActionsProps> = (props) => {
|
|
|
215
194
|
type="button"
|
|
216
195
|
onClick={onUnlock}
|
|
217
196
|
disabled={unlockLoading}
|
|
218
|
-
className="mt-3 inline-flex h-10 w-full items-center justify-center gap-2 rounded-full bg-[#121110] px-4 text-sm font-medium leading-none text-white disabled:opacity-70"
|
|
197
|
+
className="mt-3 inline-flex h-10 w-full items-center justify-center gap-2 rounded-full bg-[#121110] px-4 text-sm font-medium leading-none text-white hover:bg-[#2a2928] disabled:opacity-70"
|
|
219
198
|
>
|
|
220
199
|
{unlockLoading ? (
|
|
221
200
|
<LoadingDots />
|
|
222
201
|
) : (
|
|
223
202
|
<>
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
) : (
|
|
227
|
-
<LockIcon className="size-4" weight="fill" />
|
|
228
|
-
)}
|
|
229
|
-
{paymentStatus === 'paid' ? 'Open' : 'Unlock'}
|
|
203
|
+
<LockSimpleIcon className="size-4" weight="fill" />
|
|
204
|
+
Unlock
|
|
230
205
|
</>
|
|
231
206
|
)}
|
|
232
207
|
</button>
|
|
@@ -235,21 +210,14 @@ const CardActions: React.FC<CardActionsProps> = (props) => {
|
|
|
235
210
|
|
|
236
211
|
if (!isLocked && onDownload && source) {
|
|
237
212
|
return (
|
|
238
|
-
<
|
|
239
|
-
|
|
213
|
+
<a
|
|
214
|
+
href={source}
|
|
240
215
|
onClick={onDownload}
|
|
241
|
-
|
|
242
|
-
className="mt-3 inline-flex h-10 w-full items-center justify-center gap-2 rounded-full bg-[#121110] px-4 text-sm font-medium leading-none text-white disabled:opacity-70"
|
|
216
|
+
className="mt-3 inline-flex h-10 w-full items-center justify-center gap-2 rounded-full bg-[#121110] px-4 text-sm font-medium leading-none text-white hover:bg-[#2a2928]"
|
|
243
217
|
>
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
<>
|
|
248
|
-
<DownloadSimpleIcon className="size-4" weight="bold" />
|
|
249
|
-
Download
|
|
250
|
-
</>
|
|
251
|
-
)}
|
|
252
|
-
</button>
|
|
218
|
+
<DownloadSimpleIcon className="size-4" weight="bold" />
|
|
219
|
+
Download
|
|
220
|
+
</a>
|
|
253
221
|
)
|
|
254
222
|
}
|
|
255
223
|
|
|
@@ -271,7 +239,6 @@ const VisitorCard: React.FC<VisitorCardProps> = (props) => {
|
|
|
271
239
|
} = props
|
|
272
240
|
const [source, setSource] = useState(sourceProp)
|
|
273
241
|
const [unlockLoading, setUnlockLoading] = useState(false)
|
|
274
|
-
const [downloadLoading, setDownloadLoading] = useState(false)
|
|
275
242
|
|
|
276
243
|
useEffect(() => {
|
|
277
244
|
if (sourceProp !== undefined) setSource(sourceProp)
|
|
@@ -293,18 +260,6 @@ const VisitorCard: React.FC<VisitorCardProps> = (props) => {
|
|
|
293
260
|
}
|
|
294
261
|
}
|
|
295
262
|
|
|
296
|
-
const handleDownload = async () => {
|
|
297
|
-
if (!onDownload) return
|
|
298
|
-
setDownloadLoading(true)
|
|
299
|
-
try {
|
|
300
|
-
await onDownload()
|
|
301
|
-
} catch (err) {
|
|
302
|
-
if (isDevBuild()) console.debug('[LockedAttachment] onDownload failed', err)
|
|
303
|
-
} finally {
|
|
304
|
-
setDownloadLoading(false)
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
263
|
let mediaPreview: React.ReactNode
|
|
309
264
|
if (sourceType === 'image') {
|
|
310
265
|
mediaPreview = (
|
|
@@ -315,7 +270,6 @@ const VisitorCard: React.FC<VisitorCardProps> = (props) => {
|
|
|
315
270
|
title={title}
|
|
316
271
|
paymentStatus={paymentStatus}
|
|
317
272
|
isLocked={isLocked}
|
|
318
|
-
loading={unlockLoading}
|
|
319
273
|
/>
|
|
320
274
|
)
|
|
321
275
|
} else if (sourceType === 'document') {
|
|
@@ -325,7 +279,6 @@ const VisitorCard: React.FC<VisitorCardProps> = (props) => {
|
|
|
325
279
|
mimeType={mimeType}
|
|
326
280
|
paymentStatus={paymentStatus}
|
|
327
281
|
isLocked={isLocked}
|
|
328
|
-
loading={unlockLoading}
|
|
329
282
|
/>
|
|
330
283
|
)
|
|
331
284
|
} else {
|
|
@@ -336,7 +289,6 @@ const VisitorCard: React.FC<VisitorCardProps> = (props) => {
|
|
|
336
289
|
mimeType={mimeType}
|
|
337
290
|
paymentStatus={paymentStatus}
|
|
338
291
|
isLocked={isLocked}
|
|
339
|
-
loading={unlockLoading}
|
|
340
292
|
/>
|
|
341
293
|
)
|
|
342
294
|
}
|
|
@@ -381,11 +333,9 @@ const VisitorCard: React.FC<VisitorCardProps> = (props) => {
|
|
|
381
333
|
<CardActions
|
|
382
334
|
isLocked={isLocked}
|
|
383
335
|
unlockLoading={unlockLoading}
|
|
384
|
-
downloadLoading={downloadLoading}
|
|
385
|
-
paymentStatus={paymentStatus}
|
|
386
336
|
source={source}
|
|
387
337
|
onUnlock={onUnlock ? handleUnlock : undefined}
|
|
388
|
-
onDownload={onDownload
|
|
338
|
+
onDownload={onDownload}
|
|
389
339
|
/>
|
|
390
340
|
</div>
|
|
391
341
|
</div>
|