@@ -19,6 +19,66 @@ import { showToast } from "./ui/toast";
1919
2020const MAX_SHAREABLE_LINK_LENGTH = 32_000 ;
2121
22+ function ShareStateAsFile ( { state } : { state : string } ) {
23+ const downloadUrl = createMemo ( ( ) => {
24+ return URL . createObjectURL (
25+ new Blob ( [ decodeURI ( state ) ] , {
26+ type : "application/json" ,
27+ } ) ,
28+ ) ;
29+ } ) ;
30+ onCleanup ( ( ) => {
31+ URL . revokeObjectURL ( downloadUrl ( ) ) ;
32+ } ) ;
33+
34+ const filename = createMemo ( ( ) => {
35+ const names = experiments . map ( ( e ) => e . config . reference . name ) . join ( "-" ) ;
36+ return `class-${ names . slice ( 0 , 120 ) } .json` ;
37+ } ) ;
38+
39+ return (
40+ < >
41+ < p >
42+ Alternatively you can create your own shareable link by hosting the
43+ state remotely:
44+ </ p >
45+ < ol class = "list-inside list-decimal space-y-1" >
46+ < li >
47+ < a
48+ class = "underline"
49+ href = { downloadUrl ( ) }
50+ download = { filename ( ) }
51+ type = "application/json"
52+ >
53+ Download state
54+ </ a > { " " }
55+ as file
56+ </ li >
57+ < li >
58+ Upload the state file to some static hosting service like your own web
59+ server or an AWS S3 bucket.
60+ </ li >
61+ < li >
62+ Open the CLASS web application with
63+ "https://classmodel.github.io/class-web?s=<your remote url>".
64+ </ li >
65+ </ ol >
66+ < p >
67+ Make sure the CLASS web application is{ " " }
68+ < a
69+ href = "https://enable-cors.org/server.html"
70+ target = "_blank"
71+ rel = "noreferrer"
72+ class = "underline"
73+ >
74+ allowed to download from remote location
75+ </ a >
76+ .
77+ </ p >
78+ </ >
79+ ) ;
80+ }
81+
2282export function ShareButton ( ) {
2383 const [ open , setOpen ] = createSignal ( false ) ;
2484 const [ isCopied , setIsCopied ] = createSignal ( false ) ;
@@ -36,21 +96,6 @@ export function ShareButton() {
3696 const url = `${ window . location . origin } ${ basePath } #${ encodedAppState ( ) } ` ;
3797 return url ;
3898 } ) ;
39- const downloadUrl = createMemo ( ( ) => {
40- return URL . createObjectURL (
41- new Blob ( [ decodeURI ( encodedAppState ( ) ) ] , {
42- type : "application/json" ,
43- } ) ,
44- ) ;
45- } ) ;
46- onCleanup ( ( ) => {
47- URL . revokeObjectURL ( downloadUrl ( ) ) ;
48- } ) ;
49-
50- const filename = createMemo ( ( ) => {
51- const names = experiments . map ( ( e ) => e . config . reference . name ) . join ( "-" ) ;
52- return `class-${ names . slice ( 0 , 120 ) } .json` ;
53- } ) ;
5499
55100 async function copyToClipboard ( ) {
56101 try {
@@ -93,44 +138,7 @@ export function ShareButton() {
93138 Cannot embed application state in shareable link, it is too
94139 large.
95140 </ p >
96- < p >
97- Alternatively you can create your own shareable link by hosting
98- the state remotely:
99- </ p >
100- < ol class = "list-inside list-decimal space-y-1" >
101- < li >
102- < a
103- class = "underline"
104- href = { downloadUrl ( ) }
105- download = { filename ( ) }
106- type = "application/json"
107- >
108- Download state
109- </ a > { " " }
110- as file
111- </ li >
112- < li >
113- Upload the state file to some static hosting service like your
114- own web server or an AWS S3 bucket.
115- </ li >
116- < li >
117- Open the CLASS web application with
118- "https://classmodel.github.io/class-web?s=<your remote
119- url>".
120- </ li >
121- </ ol >
122- < p >
123- Make sure the CLASS web application is{ " " }
124- < a
125- href = "https://enable-cors.org/server.html"
126- target = "_blank"
127- rel = "noreferrer"
128- class = "underline"
129- >
130- allowed to download from remote location
131- </ a >
132- .
133- </ p >
141+ < ShareStateAsFile state = { encodedAppState ( ) } />
134142 </ >
135143 }
136144 >
@@ -177,6 +185,7 @@ export function ShareButton() {
177185 </ Show >
178186 </ Button >
179187 </ div >
188+ < ShareStateAsFile state = { encodedAppState ( ) } />
180189 </ Show >
181190 </ Show >
182191 < div aria-live = "polite" class = "sr-only" >
0 commit comments