Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 81243d1

Browse files
committed
use an if statement instead of an iterator to show the error
1 parent 0456d74 commit 81243d1

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

file-explorer/src/main.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
//!
77
//! This example is interesting because it's mixing filesystem operations and GUI, which is typically hard for UI to do.
88
9-
109
use dioxus::prelude::*;
1110
use log::LevelFilter;
1211

13-
1412
fn main() {
1513
// Init debug
1614
dioxus_logger::init(LevelFilter::Info).expect("failed to init logger");
@@ -29,7 +27,7 @@ fn App() -> Element {
2927
link { rel: "stylesheet", href: "main.css" }
3028
header {
3129
i { class: "material-icons icon-menu", "menu" }
32-
h1 { "Files: " "{files.read().current()}" }
30+
h1 { "Files: {files.read().current()}" }
3331
span { }
3432
i { class: "material-icons", onclick: move |_| files.write().go_up(), "logout" }
3533
}
@@ -47,22 +45,17 @@ fn App() -> Element {
4745
h1 { "{path.name}" }
4846
}
4947
}
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+
}
5953
}
6054
}
6155
}
6256
}
6357
}
6458

65-
6659
struct File {
6760
is_directory: bool,
6861
name: String,
@@ -92,7 +85,8 @@ impl Files {
9285
log::info!("Reloading path list for {:?}", cur_path);
9386
let paths = match std::fs::read_dir(&cur_path) {
9487
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!
9690
if let Ok(_) = open::that(cur_path) {
9791
log::info!("Opened file");
9892
return;
@@ -114,13 +108,10 @@ impl Files {
114108

115109
for path in collected {
116110
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+
});
124115
}
125116
log::info!("path names are {:#?}", self.path_names);
126117
}

0 commit comments

Comments
 (0)