Skip to content

Commit 1730202

Browse files
committed
using refs for updating app state
1 parent 305c2ad commit 1730202

11 files changed

+38
-35
lines changed

src/app/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl App {
227227

228228
// Update App components dependent on the received Action
229229
for component in self.components.iter_mut() {
230-
if let Some(action) = component.update(action.clone()).await? {
230+
if let Some(action) = component.update(&action).await? {
231231
component_tx.send(action)?
232232
};
233233
}

src/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub trait Component {
130130
///
131131
/// * `Result<Option<Action>>` - An action to be processed or none.
132132
#[allow(unused_variables)]
133-
async fn update(&mut self, action: Action) -> Result<Option<Action>> {
133+
async fn update(&mut self, action: &Action) -> Result<Option<Action>> {
134134
Ok(None)
135135
}
136136

src/ui/about_widget.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ impl Component for AboutPage {
185185
self.is_active
186186
}
187187

188-
async fn update(&mut self, action: Action) -> Result<Option<Action>> {
188+
async fn update(&mut self, action: &Action) -> Result<Option<Action>> {
189189
if let Action::ShowAbout(caller_context) = action {
190-
self.caller_context = caller_context;
190+
self.caller_context = *caller_context;
191191
self.is_active = true;
192192
}
193193

src/ui/explorer_widget.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,14 @@ impl Component for ExplorerWidget {
428428
}
429429
}
430430

431-
async fn update(&mut self, action: Action) -> Result<Option<Action>> {
431+
async fn update(&mut self, action: &Action) -> Result<Option<Action>> {
432432
match action {
433433
Action::SwitchAppContext(context) => {
434-
self.app_context = context;
434+
self.app_context = *context;
435435
}
436436
Action::LoadDirDone(explorer) => {
437437
self.is_working = false;
438-
self.explorer = explorer;
438+
self.explorer = explorer.clone();
439439
self.filtered_entries.reset();
440440
self.list_state.select(self.explorer.selected().into());
441441
self.explorer.set_terminal_height(self.terminal_height);
@@ -446,7 +446,7 @@ impl Component for ExplorerWidget {
446446
match metadata {
447447
Some(metadata) => {
448448
self.is_metadata_pop_up = true;
449-
return Ok(Action::ShowDirMetadata(metadata).into());
449+
return Ok(Action::ShowDirMetadata(metadata.clone()).into());
450450
}
451451
None => {
452452
self.send_app_action(Action::UpdateAppState(AppState::Failure(
@@ -461,7 +461,7 @@ impl Component for ExplorerWidget {
461461
self.filtered_entries.reset();
462462

463463
// update the terminal height
464-
self.terminal_height = h;
464+
self.terminal_height = *h;
465465
self.explorer.set_terminal_height(self.terminal_height);
466466
// reset the start index and selected index to ensure that the selected object is no longer in the field of view
467467
self.explorer.reset_state();
@@ -473,7 +473,7 @@ impl Component for ExplorerWidget {
473473
}
474474
}
475475
Action::ToggleTheme(theme) => {
476-
self.theme = theme;
476+
self.theme = *theme;
477477
}
478478
Action::HideOrShowSystemOverview => {
479479
self.use_whole_draw_area = !self.use_whole_draw_area;

src/ui/footer_widget.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ impl Component for Footer {
102102
true
103103
}
104104

105-
async fn update(&mut self, action: Action) -> Result<Option<Action>> {
105+
async fn update(&mut self, action: &Action) -> Result<Option<Action>> {
106106
match action {
107107
Action::UpdateAppState(state) => {
108-
self.app_state = state;
108+
self.app_state = state.clone();
109109
self.app_state_hint_length =
110110
utils::compute_text_length(&self.app_state.to_string()) + 2;
111111
}
@@ -123,10 +123,10 @@ impl Component for Footer {
123123
self.command_desc_length = utils::compute_text_length(&self.command_description);
124124
}
125125
Action::SwitchAppContext(context) => {
126-
self.app_context = context;
126+
self.app_context = *context;
127127
}
128128
Action::ToggleTheme(theme) => {
129-
self.theme = theme;
129+
self.theme = *theme;
130130
}
131131
_ => {}
132132
}

src/ui/help_widget.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ impl Component for HelpPage {
142142
self.is_active
143143
}
144144

145-
async fn update(&mut self, action: Action) -> Result<Option<Action>> {
145+
async fn update(&mut self, action: &Action) -> Result<Option<Action>> {
146146
if let Action::ShowHelp(caller_context) = action {
147-
self.caller_context = caller_context;
147+
self.caller_context = *caller_context;
148148
self.is_active = true;
149149
}
150150

src/ui/info_widget.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,15 @@ impl Component for SystemOverview {
333333
self.is_active
334334
}
335335

336-
async fn update(&mut self, action: Action) -> Result<Option<Action>> {
336+
async fn update(&mut self, action: &Action) -> Result<Option<Action>> {
337337
match action {
338338
Action::Tick => {
339339
if self.is_active {
340340
self.refresh_system_details()
341341
}
342342
}
343343
Action::ToggleTheme(theme) => {
344-
self.theme = theme;
344+
self.theme = *theme;
345345
}
346346
Action::HideOrShowSystemOverview => {
347347
self.is_active = !self.is_active;

src/ui/metadata_widget.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Component for MetadataPage {
139139
self.is_active
140140
}
141141

142-
async fn update(&mut self, action: Action) -> Result<Option<Action>> {
142+
async fn update(&mut self, action: &Action) -> Result<Option<Action>> {
143143
match action {
144144
Action::ShowFileMetadata(file_path, metadata) => {
145145
self.send_app_action(Action::UpdateAppState(AppState::Done("Done".to_string())))?;
@@ -158,7 +158,7 @@ impl Component for MetadataPage {
158158
self.send_app_action(Action::UpdateAppState(AppState::Done("Done".to_string())))?;
159159
self.metadata.set_items(metadata.get_metadata_rows());
160160
self.metadata.state.select(Some(0));
161-
self.object_name = metadata.dir_name;
161+
self.object_name = metadata.dir_name.clone();
162162
self.scrollbar_state = ScrollbarState::new(self.metadata.items.len()).position(0);
163163
self.is_active = true;
164164
}

src/ui/result_widget.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ impl Component for ResultWidget {
474474
let json_value = entry.build_as_json();
475475
// Send to writer
476476
if let Err(err) = tx_clone.send(json_value).await {
477-
log::error!("Failed to send JSON value to writer task - Details {:?}", err);
477+
log::error!(
478+
"Failed to send JSON value to writer task - Details {:?}",
479+
err
480+
);
478481
break;
479482
}
480483
}
@@ -496,14 +499,14 @@ impl Component for ResultWidget {
496499
Ok(None)
497500
}
498501

499-
async fn update(&mut self, action: Action) -> Result<Option<Action>> {
502+
async fn update(&mut self, action: &Action) -> Result<Option<Action>> {
500503
match action {
501504
Action::SwitchAppContext(context) => {
502-
self.app_context = context;
505+
self.app_context = *context;
503506
}
504507
Action::ShowResultsPage(result, mode) => {
505-
self.applied_search_mode = mode;
506-
self.search_result = result;
508+
self.applied_search_mode = *mode;
509+
self.search_result = result.clone();
507510
self.search_result.set_terminal_height(self.terminal_height);
508511
self.table_state
509512
.select(self.search_result.selected().into());
@@ -516,7 +519,7 @@ impl Component for ResultWidget {
516519
match metadata {
517520
Some(metadata) => {
518521
self.is_metadata_pop_up = true;
519-
return Ok(Action::ShowDirMetadata(metadata).into());
522+
return Ok(Action::ShowDirMetadata(metadata.clone()).into());
520523
}
521524
None => {
522525
self.send_app_action(Action::UpdateAppState(AppState::Failure(
@@ -533,12 +536,12 @@ impl Component for ResultWidget {
533536
}
534537
Action::ExportFailure(msg) => {
535538
self.is_working = false;
536-
return Ok(Action::UpdateAppState(AppState::Failure(msg)).into());
539+
return Ok(Action::UpdateAppState(AppState::Failure(msg.clone())).into());
537540
}
538541
Action::CloseMetadata => self.is_metadata_pop_up = false,
539542
Action::Resize(_, h) => {
540543
// update the terminal height
541-
self.terminal_height = h;
544+
self.terminal_height = *h;
542545
self.search_result.set_terminal_height(self.terminal_height);
543546
// reset the start index and selected index to ensure that the selected object is no longer in the field of view
544547
self.search_result.reset_state();
@@ -552,7 +555,7 @@ impl Component for ResultWidget {
552555
}
553556
}
554557
Action::ToggleTheme(theme) => {
555-
self.theme = theme;
558+
self.theme = *theme;
556559
}
557560
Action::HideOrShowSystemOverview => {
558561
self.use_whole_draw_area = !self.use_whole_draw_area;

src/ui/search_widget.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,20 +420,20 @@ impl Component for SearchWidget {
420420
self.app_context == AppContext::Search
421421
}
422422

423-
async fn update(&mut self, action: Action) -> Result<Option<Action>> {
423+
async fn update(&mut self, action: &Action) -> Result<Option<Action>> {
424424
match action {
425425
Action::SwitchAppContext(context) => {
426-
self.app_context = context;
426+
self.app_context = *context;
427427
}
428428
Action::ShowSearchPage(cwd) => {
429-
self.cwd = cwd;
429+
self.cwd = cwd.to_path_buf();
430430
self.cwd_display_name = utils::format_path_for_display(&self.cwd);
431431
}
432432
Action::SearchDone(search_result) => {
433433
self.is_working = false;
434434
if let Some(result) = search_result {
435435
self.reset();
436-
self.send_app_action(Action::ShowResultsPage(result, self.mode))?;
436+
self.send_app_action(Action::ShowResultsPage(result.clone(), self.mode))?;
437437

438438
return Ok(Action::SwitchAppContext(AppContext::Results).into());
439439
} else {
@@ -444,7 +444,7 @@ impl Component for SearchWidget {
444444
}
445445
}
446446
Action::ToggleTheme(theme) => {
447-
self.theme = theme;
447+
self.theme = *theme;
448448
}
449449
Action::HideOrShowSystemOverview => {
450450
self.use_whole_draw_area = !self.use_whole_draw_area;

0 commit comments

Comments
 (0)