Skip to content

Commit

Permalink
feat: correct handling of new collections
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed May 23, 2024
1 parent c9c5968 commit 3d0eb8c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tui/src/pages/collection_viewer/collection_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl<'ae> CollectionViewer<'ae> {

CollectionViewer {
collection,
focused_pane: PaneFocus::ReqUri,
focused_pane: PaneFocus::Sidebar,
selected_pane: None,
colors,
config,
Expand Down Expand Up @@ -222,7 +222,7 @@ impl<'ae> CollectionViewer<'ae> {

match key_event.code {
KeyCode::Enter => {
if let Some(ref req) = self.hovered_request {
if let Some(req) = self.hovered_request.clone() {
match req {
RequestKind::Nested(dir) => {
let entry = self.dirs_expanded.entry(dir.clone()).or_insert(false);
Expand Down Expand Up @@ -251,6 +251,8 @@ impl<'ae> CollectionViewer<'ae> {
req,
)
.or(Some(req.clone()));
} else if let Some(requests) = self.collection.requests.as_ref() {
self.hovered_request = requests.first().cloned();
}
}
KeyCode::Char('k') => {
Expand All @@ -264,7 +266,9 @@ impl<'ae> CollectionViewer<'ae> {
id,
)
.or(Some(id.clone()));
};
} else if let Some(requests) = self.collection.requests.as_ref() {
self.hovered_request = requests.first().cloned();
}
}
KeyCode::Char('n') => self.curr_overlay = Overlays::CreateRequest,
_ => {}
Expand Down Expand Up @@ -770,14 +774,18 @@ impl<'ae> CollectionViewer<'ae> {
}),
};

if let RequestKind::Single(ref req) = new_request {
self.selected_request = Some(Rc::new(RefCell::new(req.clone())));
self.hovered_request = Some(new_request.clone());
}

self.collection
.requests
.get_or_insert_with(Vec::new)
.push(new_request);

self.create_req_form_state = CreateReqFormState::default();
self.curr_overlay = Overlays::None;

self.sync_collection_changes();
}

Expand Down

0 comments on commit 3d0eb8c

Please sign in to comment.