@@ -8,7 +8,7 @@ use fast_qr::{
8
8
QRBuilder , Version , ECL ,
9
9
} ;
10
10
use gloo_net:: http:: Request ;
11
- use log:: info;
11
+ use log:: { error , info} ;
12
12
use reqwest:: Url ;
13
13
14
14
fn main ( ) {
@@ -63,6 +63,8 @@ fn Listing(cx: Scope) -> Element {
63
63
} ) ;
64
64
}
65
65
66
+ let info_state = use_state ( & cx, || None as Option < String > ) ;
67
+
66
68
cx. render ( match fut. value ( ) {
67
69
Some ( Ok ( dir_desc) ) => rsx ! (
68
70
div {
@@ -76,7 +78,9 @@ fn Listing(cx: Scope) -> Element {
76
78
create_dir_state: create_dir_state. clone( ) ,
77
79
}
78
80
79
- ListingTable { dir_desc: dir_desc, cur_url: & url, update_state: update_state } ,
81
+ ListingTable { dir_desc: dir_desc, cur_url: & url, update_state: update_state, info_state: info_state } ,
82
+
83
+ InfoDialog { info_state: info_state }
80
84
) ,
81
85
Some ( Err ( err) ) => rsx ! ( "Error: {err}" ) ,
82
86
_ => rsx ! ( "Loading..." ) ,
@@ -244,6 +248,7 @@ fn ListingTable<'a>(cx: Scope<'a, DirDescProps<'a>>) -> Element {
244
248
entry: entry,
245
249
cur_path: cur_path,
246
250
update_state: cx. props. update_state,
251
+ info_state: cx. props. info_state,
247
252
qrcode_state: qrcode_state,
248
253
} ) )
249
254
@@ -288,6 +293,37 @@ fn TableRow<'a>(cx: Scope<'a, DirEntryProps<'a>>) -> Element {
288
293
img { src: "data:image/x-icon;base64,AAABAAEAEBACAAAAAACwAAAAFgAAACgAAAAQAAAAIAAAAAEAAQAAAAAAQAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAA////AAKnAAB6MgAASlIAAEtCAAB7AAAAAnkAAP/YAACDBQAAUGMAAPy/AAACQAAAel4AAEpSAABK0gAAel4AAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" , alt: "QRCode" }
289
294
}
290
295
296
+ a {
297
+ href: "#" ,
298
+ prevent_default: "onclick" ,
299
+ onclick: move |_| {
300
+ let path = format!( "/api/ffprobe{}/{}" , cx. props. cur_path, entry. file_name) ;
301
+ let info_state = cx. props. info_state. clone( ) ;
302
+ cx. spawn( async move {
303
+ let resp = Request :: get( path. as_str( ) )
304
+ . send( )
305
+ . await ;
306
+
307
+ match resp {
308
+ Ok ( resp) => {
309
+ let text = resp. text( ) . await . unwrap_or( "" . to_string( ) ) ;
310
+ if text. is_empty( ) || text == "\" {\\ n\\ n}\\ n\" " {
311
+ info_state. set( Some ( "Not Available!" . to_string( ) ) ) ;
312
+ } else {
313
+ let json_resp: serde_json:: Value = serde_json:: from_str( text. as_str( ) ) . unwrap_or( serde_json:: Value :: default ( ) ) ;
314
+ let json_str = json_resp. to_string( ) . replace( "\\ n" , "\n " ) . replace( "\\ " , "" ) ;
315
+ info_state. set( Some ( json_str) ) ;
316
+ }
317
+ }
318
+ Err ( err) => {
319
+ error!( "failed: {}" , err) ;
320
+ }
321
+ }
322
+ } ) ;
323
+ } ,
324
+ "ℹ️ " ,
325
+ }
326
+
291
327
a {
292
328
href: "{api_link}" ,
293
329
if entry. file_type == common:: FileType :: Directory {
@@ -398,6 +434,61 @@ fn Tooltip<'a>(cx: Scope<'a, TooltipProps<'a>>) -> Element {
398
434
// }))
399
435
// }
400
436
437
+ #[ inline_props]
438
+ fn InfoDialog < ' a > ( cx : Scope < ' a > , info_state : & ' a UseState < Option < String > > ) -> Element {
439
+ cx. render ( if let Some ( str_info) = info_state. get ( ) {
440
+ rsx ! ( div {
441
+ style: "
442
+ position: fixed;
443
+ width: 860px;
444
+ height: 640px;
445
+ left: 50%;
446
+ margin-left: -430px;
447
+ top: 50%;
448
+ margin-top: -320px;
449
+ z-index: 20;
450
+ border-radius: 5px;
451
+ border: 2px solid #ccc;
452
+ background: #eee;
453
+ overflow: scroll;
454
+ " ,
455
+ textarea {
456
+ style: "
457
+ width:850px;
458
+ height: 580px;
459
+ margin:5px;
460
+ border: none;
461
+ box-sizing:border-box;
462
+ resize: none;
463
+ border-bottom: 2px solid #ccc;
464
+ " ,
465
+ disabled: "true" ,
466
+ value: "{str_info}" ,
467
+ }
468
+ p {
469
+ style: "
470
+ text-align: center;
471
+ width: 100%;
472
+ position: absolute;
473
+ bottom: 0px;
474
+ margin:0px;
475
+ box-sizing:border-box;
476
+ padding: 10px;
477
+ " ,
478
+ input {
479
+ style: "width: 200px; height: 30px" ,
480
+ prevent_default: "onclick" ,
481
+ r#type: "button" ,
482
+ value: "Close" ,
483
+ onclick: |_| info_state. set( None ) ,
484
+ }
485
+ }
486
+ } )
487
+ } else {
488
+ rsx ! ( "" )
489
+ } )
490
+ }
491
+
401
492
#[ derive( Props ) ]
402
493
struct TooltipProps < ' a > {
403
494
w : i32 ,
@@ -412,6 +503,7 @@ pub struct DirDescProps<'a> {
412
503
cur_url : & ' a Url ,
413
504
dir_desc : & ' a DirDesc ,
414
505
update_state : & ' a UseState < bool > ,
506
+ info_state : & ' a UseState < Option < String > > ,
415
507
}
416
508
417
509
#[ derive( Props ) ]
@@ -421,6 +513,7 @@ struct DirEntryProps<'a> {
421
513
cur_path : & ' a str ,
422
514
update_state : & ' a UseState < bool > ,
423
515
qrcode_state : & ' a UseState < Option < QRCodeParams > > ,
516
+ info_state : & ' a UseState < Option < String > > ,
424
517
}
425
518
426
519
struct QRCodeParams {
0 commit comments