Skip to content

Commit d3c6fc1

Browse files
committed
fix: applied requested changes
1 parent 024de7a commit d3c6fc1

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

src/components/Tooltip.tsx

+4-14
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,13 @@ function Tooltip({ text, title, children }: { text: string[], title?: string, ch
77
<span
88
onMouseEnter={() => setVisible(true)}
99
onMouseLeave={() => setVisible(false)}
10-
style={{ position: 'relative', cursor: 'pointer', display: 'flex', alignItems: 'center' }}
10+
className="relative cursor-pointer flex items-center"
1111
>
1212
{children}
1313
{visible && (
14-
<div style={{
15-
position: 'absolute',
16-
left: '50%',
17-
bottom: '100%',
18-
transform: 'translateX(-50%)',
19-
backgroundColor: '#333',
20-
color: '#fff',
21-
padding: '5px',
22-
borderRadius: '3px',
23-
whiteSpace: 'pre-wrap',
24-
zIndex: 1
25-
}}>
26-
{title && <strong>{title + '\n'}</strong>}
14+
<div className="absolute left-1/2 bottom-full transform -translate-x-1/2 bg-gray-800 text-white p-1.5 rounded whitespace-pre-wrap z-10">
15+
{title && <strong>{title}</strong>}
16+
<br />
2717
{text.join('\n')}
2818
</div>
2919
)}

src/share.tsx

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ChangeEvent, useEffect, useState } from 'react'
2-
import { useW3 } from '@w3ui/react'
2+
import { SpaceDID, useW3 } from '@w3ui/react'
33
import { extract } from '@ucanto/core/delegation'
44
import type { PropsWithChildren } from 'react'
55
import type { Delegation } from '@ucanto/interface'
@@ -23,7 +23,7 @@ function isDID(value: string): boolean {
2323
try {
2424
DID.parse(value.trim())
2525
return true
26-
} catch (err) {
26+
} catch {
2727
return false
2828
}
2929
}
@@ -33,22 +33,30 @@ function isEmail(value: string): boolean {
3333
return !isDID(value) && emailRegex.test(value)
3434
}
3535

36-
export function ShareSpace({spaceDID}: {spaceDID: string}): JSX.Element {
36+
export function ShareSpace({ spaceDID }: { spaceDID: SpaceDID }): JSX.Element {
3737
const [{ client }] = useW3()
3838
const [value, setValue] = useState('')
3939
const [downloadUrl, setDownloadUrl] = useState('')
4040
const [sharedEmails, setSharedEmails] = useState<{ email: string, capabilities: string[] }[]>([])
4141

42+
const updateSharedEmails = (delegations: { email: string, capabilities: string[] }[]) => {
43+
setSharedEmails(prev => {
44+
const newEmails = delegations.filter(d => !prev.some(item => item.email === d.email))
45+
return [...prev, ...newEmails]
46+
})
47+
}
48+
4249
useEffect(() => {
4350
if (client && spaceDID) {
44-
// Find all delegations where the spaceDID is present
51+
// Find all delegations via email where the spaceDID is present
4552
const delegations = client.delegations()
4653
.filter(d => d.capabilities.some(c => c.with === spaceDID))
54+
.filter(d => d.audience.did().startsWith('did:mailto:'))
4755
.map(d => ({
4856
email: DIDMailTo.toEmail(DIDMailTo.fromString(d.audience.did())),
4957
capabilities: d.capabilities.map(c => c.can)
5058
}))
51-
setSharedEmails(delegations)
59+
updateSharedEmails(delegations)
5260
}
5361
}, [client, spaceDID])
5462

@@ -67,12 +75,7 @@ export function ShareSpace({spaceDID}: {spaceDID: string}): JSX.Element {
6775
const delegation = await client.shareSpace(delegatedEmail, space.did())
6876

6977
const next = { email: delegatedEmail, capabilities: delegation.capabilities.map(c => c.can) }
70-
setSharedEmails(prev => {
71-
if (prev.some(item => item.email === next.email)) {
72-
return prev
73-
}
74-
return [...prev, next]
75-
})
78+
updateSharedEmails([next])
7679
setValue('')
7780
} catch (err) {
7881
console.error(err)
@@ -85,7 +88,7 @@ export function ShareSpace({spaceDID}: {spaceDID: string}): JSX.Element {
8588
let audience
8689
try {
8790
audience = DID.parse(input.trim())
88-
} catch (err) {
91+
} catch {
8992
setDownloadUrl('')
9093
return
9194
}

0 commit comments

Comments
 (0)