1
1
import * as React from 'react' ;
2
2
import TimeAgo from 'react-timeago' ;
3
3
4
- import { Button , Card , Input , Stack , Tooltip , Typography } from '@mui/joy' ;
4
+ import { Box , Button , Card , IconButton , Input , Stack , Tooltip , Typography } from '@mui/joy' ;
5
+ import ContentCopyIcon from '@mui/icons-material/ContentCopy' ;
5
6
import DeleteForeverIcon from '@mui/icons-material/DeleteForever' ;
6
7
import DoneIcon from '@mui/icons-material/Done' ;
8
+ import EditIcon from '@mui/icons-material/Edit' ;
7
9
import IosShareIcon from '@mui/icons-material/IosShare' ;
8
10
import LaunchIcon from '@mui/icons-material/Launch' ;
9
11
import LinkIcon from '@mui/icons-material/Link' ;
@@ -12,6 +14,7 @@ import { Brand } from '~/common/app.config';
12
14
import { ConfirmationModal } from '~/common/components/ConfirmationModal' ;
13
15
import { GoodModal } from '~/common/components/GoodModal' ;
14
16
import { InlineError } from '~/common/components/InlineError' ;
17
+ import { InlineTextarea } from '~/common/components/InlineTextarea' ;
15
18
import { Link } from '~/common/components/Link' ;
16
19
import { apiAsyncNode } from '~/common/util/trpc.client' ;
17
20
import { copyToClipboard } from '~/common/util/clipboardUtils' ;
@@ -23,12 +26,18 @@ import type { StorageDeleteSchema, StoragePutSchema } from '../server/link';
23
26
import { forgetChatLinkItem } from './store-chatlink' ;
24
27
25
28
26
- export function ChatLinkDetails ( props : { onClose : ( ) => void , storageItem : StoragePutSchema , open : boolean } ) {
29
+ export function ChatLinkDetails ( props : {
30
+ open : boolean ,
31
+ onClose : ( ) => void ,
32
+ storageItem : StoragePutSchema ,
33
+ onChangeDeletionKey : ( deletionKey : string ) => void ,
34
+ } ) {
27
35
28
36
// state
29
37
const [ opened , setOpened ] = React . useState ( false ) ;
30
38
const [ copied , setCopied ] = React . useState ( false ) ;
31
39
const [ native , setNative ] = React . useState ( false ) ;
40
+ const [ isEditingDeletionKey , setIsEditingDeletionKey ] = React . useState ( false ) ;
32
41
const [ confirmDeletion , setConfirmDeletion ] = React . useState ( false ) ;
33
42
const [ deletionResponse , setDeletionResponse ] = React . useState < StorageDeleteSchema | null > ( null ) ;
34
43
@@ -47,6 +56,26 @@ export function ChatLinkDetails(props: { onClose: () => void, storageItem: Stora
47
56
const fullUrl = getOriginUrl ( ) + relativeUrl ;
48
57
49
58
59
+ // Deletion Key Edit
60
+
61
+ const handleKeyEditBegin = ( ) => setIsEditingDeletionKey ( true ) ;
62
+
63
+ const handleKeyEditCancel = ( ) => setIsEditingDeletionKey ( false ) ;
64
+
65
+ const handleKeyEditChange = ( text : string ) => {
66
+ if ( text ) {
67
+ setIsEditingDeletionKey ( false ) ;
68
+ props . onChangeDeletionKey ( text . trim ( ) ) ;
69
+ }
70
+ } ;
71
+
72
+ // Deletion Key Copy
73
+
74
+ const handleKeyCopy = ( ) => {
75
+ copyToClipboard ( deletionKey , 'Link Deletion Key' ) ;
76
+ } ;
77
+
78
+
50
79
const onOpen = ( ) => setOpened ( true ) ;
51
80
52
81
const onCopy = ( ) => {
@@ -138,7 +167,50 @@ export function ChatLinkDetails(props: { onClose: () => void, storageItem: Stora
138
167
Deletion Key
139
168
</ Typography >
140
169
141
- < Input readOnly variant = 'plain' value = { deletionKey } sx = { { flexGrow : 1 } } />
170
+ < Box sx = { { display : 'flex' , alignItems : 'center' , gap : 1 } } >
171
+ { isEditingDeletionKey ? (
172
+ < InlineTextarea
173
+ invertedColors
174
+ initialText = { deletionKey }
175
+ onEdit = { handleKeyEditChange }
176
+ onCancel = { handleKeyEditCancel }
177
+ sx = { {
178
+ flexGrow : 1 ,
179
+ ml : - 1.5 , mr : - 0.5 ,
180
+ } }
181
+ />
182
+ ) : (
183
+ < Input
184
+ readOnly
185
+ variant = 'plain'
186
+ value = { deletionKey }
187
+ endDecorator = {
188
+ < Box sx = { { display : 'flex' , gap : 2 } } >
189
+ < Tooltip title = 'Edit Deletion Key' >
190
+ < IconButton
191
+ variant = 'soft'
192
+ color = 'primary'
193
+ disabled = { isEditingDeletionKey }
194
+ onClick = { handleKeyEditBegin }
195
+ >
196
+ < EditIcon />
197
+ </ IconButton >
198
+ </ Tooltip >
199
+ < IconButton
200
+ variant = 'soft'
201
+ color = 'primary'
202
+ disabled = { isEditingDeletionKey }
203
+ onClick = { handleKeyCopy }
204
+ >
205
+ < ContentCopyIcon />
206
+ </ IconButton >
207
+ </ Box >
208
+ }
209
+ sx = { { flexGrow : 1 } }
210
+ />
211
+ ) }
212
+ </ Box >
213
+
142
214
143
215
< Typography level = 'body-sm' >
144
216
IMPORTANT - < b > keep this key safe</ b > , you will need it if you decide to delete the link at a later time,
0 commit comments