6
6
//!
7
7
//! This example is interesting because it's mixing filesystem operations and GUI, which is typically hard for UI to do.
8
8
9
-
10
9
use dioxus:: prelude:: * ;
11
10
use log:: LevelFilter ;
12
11
13
-
14
12
fn main ( ) {
15
13
// Init debug
16
14
dioxus_logger:: init ( LevelFilter :: Info ) . expect ( "failed to init logger" ) ;
@@ -29,7 +27,7 @@ fn App() -> Element {
29
27
link { rel: "stylesheet" , href: "main.css" }
30
28
header {
31
29
i { class: "material-icons icon-menu" , "menu" }
32
- h1 { "Files: " " {files.read().current()}" }
30
+ h1 { "Files: {files.read().current()}" }
33
31
span { }
34
32
i { class: "material-icons" , onclick: move |_| files. write( ) . go_up( ) , "logout" }
35
33
}
@@ -47,22 +45,17 @@ fn App() -> Element {
47
45
h1 { "{path.name}" }
48
46
}
49
47
}
50
- {
51
- files. read( ) . err. as_ref( ) . map( |err| {
52
- rsx! (
53
- div {
54
- code { "{err}" }
55
- button { onclick: move |_| files. write( ) . clear_err( ) , "x" }
56
- }
57
- )
58
- } )
48
+ if let Some ( err) = files. read( ) . err. as_ref( ) {
49
+ div {
50
+ code { "{err}" }
51
+ button { onclick: move |_| files. write( ) . clear_err( ) , "x" }
52
+ }
59
53
}
60
54
}
61
55
}
62
56
}
63
57
}
64
58
65
-
66
59
struct File {
67
60
is_directory : bool ,
68
61
name : String ,
@@ -92,7 +85,8 @@ impl Files {
92
85
log:: info!( "Reloading path list for {:?}" , cur_path) ;
93
86
let paths = match std:: fs:: read_dir ( & cur_path) {
94
87
Ok ( e) => e,
95
- Err ( err) => { // Likely we're trying to open a file, so let's open it!
88
+ Err ( err) => {
89
+ // Likely we're trying to open a file, so let's open it!
96
90
if let Ok ( _) = open:: that ( cur_path) {
97
91
log:: info!( "Opened file" ) ;
98
92
return ;
@@ -114,13 +108,10 @@ impl Files {
114
108
115
109
for path in collected {
116
110
let file = path. unwrap ( ) ;
117
- self . path_names
118
- . push (
119
- File {
120
- name : file. file_name ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ,
121
- is_directory : file. file_type ( ) . unwrap ( ) . is_dir ( ) ,
122
- }
123
- ) ;
111
+ self . path_names . push ( File {
112
+ name : file. file_name ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ,
113
+ is_directory : file. file_type ( ) . unwrap ( ) . is_dir ( ) ,
114
+ } ) ;
124
115
}
125
116
log:: info!( "path names are {:#?}" , self . path_names) ;
126
117
}
0 commit comments