@@ -67,23 +67,34 @@ export function HTMLPreview(props: {
67
67
style = { { width : "100%" , height } }
68
68
// src={`data:text/html,${encodeURIComponent(srcDoc)}`}
69
69
srcDoc = { srcDoc }
70
- onLoad = { ( e ) => props ?. onLoad ( title ) }
70
+ onLoad = { ( e ) => props ?. onLoad && props ?. onLoad ( title ) }
71
71
> </ iframe >
72
72
) ;
73
73
}
74
74
75
- export function ArtifactShareButton ( { getCode, id, style, fileName } ) {
75
+ export function ArtifactShareButton ( {
76
+ getCode,
77
+ id,
78
+ style,
79
+ fileName,
80
+ } : {
81
+ getCode : ( ) => string ;
82
+ id ?: string ;
83
+ style ?: any ;
84
+ fileName ?: string ;
85
+ } ) {
76
86
const [ name , setName ] = useState ( id ) ;
77
87
const [ show , setShow ] = useState ( false ) ;
78
- const shareUrl = useMemo ( ( ) =>
79
- [ location . origin , "#" , Path . Artifact , "/" , name ] . join ( "" ) ,
88
+ const shareUrl = useMemo (
89
+ ( ) => [ location . origin , "#" , Path . Artifact , "/" , name ] . join ( "" ) ,
90
+ [ name ] ,
80
91
) ;
81
- const upload = ( code ) =>
92
+ const upload = ( code : string ) =>
82
93
id
83
94
? Promise . resolve ( { id } )
84
95
: fetch ( ApiPath . Artifact , {
85
96
method : "POST" ,
86
- body : getCode ( ) ,
97
+ body : code ,
87
98
} )
88
99
. then ( ( res ) => res . json ( ) )
89
100
. then ( ( { id } ) => {
@@ -103,9 +114,11 @@ export function ArtifactShareButton({ getCode, id, style, fileName }) {
103
114
bordered
104
115
title = { Locale . Export . Artifact . Title }
105
116
onClick = { ( ) => {
106
- upload ( getCode ( ) ) . then ( ( { id } ) => {
107
- setShow ( true ) ;
108
- setName ( id ) ;
117
+ upload ( getCode ( ) ) . then ( ( res ) => {
118
+ if ( res ?. id ) {
119
+ setShow ( true ) ;
120
+ setName ( res ?. id ) ;
121
+ }
109
122
} ) ;
110
123
} }
111
124
/>
@@ -168,7 +181,7 @@ export function Artifact() {
168
181
return (
169
182
< div
170
183
style = { {
171
- disply : "block" ,
184
+ display : "block" ,
172
185
width : "100%" ,
173
186
height : "100%" ,
174
187
position : "relative" ,
@@ -195,7 +208,7 @@ export function Artifact() {
195
208
autoHeight = { false }
196
209
height = { height - 36 }
197
210
onLoad = { ( title ) => {
198
- setFileName ( title ) ;
211
+ setFileName ( title as string ) ;
199
212
setLoading ( false ) ;
200
213
} }
201
214
/>
0 commit comments