Skip to content

Commit

Permalink
feat: properly syncing and allowing further edits
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed May 22, 2024
1 parent 86b02d7 commit f667183
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tui/src/components/api_explorer/api_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,30 +783,28 @@ impl<'ae> ApiExplorer<'ae> {
if let Some(request) = self.selected_request.as_ref() {
let mut request = request.borrow().clone();
let body = self.editor.body().to_string();
// this is not the best idea for when we start implementing other kinds of
// body types like GraphQL
if !body.is_empty() {
request.body = Some(body);
request.body_type = Some("application/json".into());
}

// we might later on decide to keep track of the actual dir/request index
// so we dont have to go over all the possible requests, this might be a
// problem for huge collections, but I haven't tested
schema
.requests
.as_mut()
.expect("no requests on schema, but we have a selected request")
.iter_mut()
.for_each(|other| match other {
RequestKind::Single(inner) => {
tracing::debug!("inner: {}, request: {}", inner.id, request.id);
request
.id
.eq(&inner.id)
.then(|| std::mem::swap(inner, &mut request));
request.id.eq(&inner.id).then(|| *inner = request.clone());
}
RequestKind::Nested(dir) => dir.requests.iter_mut().for_each(|other| {
if let RequestKind::Single(inner) = other {
request
.id
.eq(&inner.id)
.then(|| std::mem::swap(inner, &mut request));
request.id.eq(&inner.id).then(|| *inner = request.clone());
}
}),
});
Expand Down

0 comments on commit f667183

Please sign in to comment.