@@ -8,31 +8,31 @@ use yew::HtmlResult;
88use yew:: prelude:: * ;
99use yew:: suspense:: use_future_with;
1010
11- #[ derive( Clone , PartialEq ) ]
12- enum CompileResult {
13- Done ( String ) ,
14- ColdStartTimeout ,
15- }
16-
1711#[ derive( Properties , PartialEq , Eq ) ]
1812pub struct OutputContainerProps {
1913 pub value : Rc < str > ,
2014}
2115
16+ async fn compile ( code : & str ) -> String {
17+ let query = QueryParams :: new ( ) ;
18+ query. append ( "code" , code) ;
19+ let url = format ! ( "{}/run?{}" , BACKEND_URL , query) ;
20+
21+ loop {
22+ match Request :: get ( & url) . send ( ) . await {
23+ Ok ( resp) if resp. status ( ) == 504 => continue ,
24+ Ok ( resp) => return resp. text ( ) . await . unwrap_or_default ( ) ,
25+ Err ( _) => continue ,
26+ }
27+ }
28+ }
29+
2230#[ component]
2331pub fn OutputContainer ( props : & OutputContainerProps ) -> HtmlResult {
2432 let action_button_state = use_context :: < ActionButtonStateContext > ( ) . unwrap ( ) ;
2533
2634 let result = use_future_with ( Rc :: clone ( & props. value ) , |value| async move {
27- let query = QueryParams :: new ( ) ;
28- query. append ( "code" , & value) ;
29- let url = format ! ( "{}/run?{}" , BACKEND_URL , query) ;
30-
31- match Request :: get ( & url) . send ( ) . await {
32- Ok ( resp) if resp. status ( ) == 504 => CompileResult :: ColdStartTimeout ,
33- Ok ( resp) => CompileResult :: Done ( resp. text ( ) . await . unwrap_or_default ( ) ) ,
34- Err ( _) => CompileResult :: ColdStartTimeout ,
35- }
35+ compile ( & value) . await
3636 } ) ?;
3737
3838 {
@@ -42,22 +42,7 @@ pub fn OutputContainer(props: &OutputContainerProps) -> HtmlResult {
4242 } ) ;
4343 }
4444
45- Ok ( match & * result {
46- CompileResult :: Done ( html_content) => {
47- html ! { <iframe srcdoc={ html_content. clone( ) } class="w-full h-full" /> }
48- }
49- CompileResult :: ColdStartTimeout => {
50- html ! {
51- <div class="h-full bg-gray-600 flex items-center justify-center" >
52- <div class="text-gray-200 flex flex-col items-center gap-3 max-w-md text-center" >
53- <span class="text-xl font-semibold" >{ "Backend service is waking up" } </span>
54- <span class="text-gray-400" >{ "The service was asleep and timed out on the first request. It should be ready now." } </span>
55- <span class="text-gray-300" >{ "Hit Run again." } </span>
56- </div>
57- </div>
58- }
59- }
60- } )
45+ Ok ( html ! { <iframe srcdoc={ ( * result) . clone( ) } class="w-full h-full" /> } )
6146}
6247
6348#[ component]
0 commit comments