feat: showing results (just JSON currently) after submitting query
This commit is contained in:
parent
78a5efd8fa
commit
e6fbb1bb1e
|
@ -11,6 +11,8 @@ pub struct App {
|
||||||
pub input: Input,
|
pub input: Input,
|
||||||
/// Is the app running?
|
/// Is the app running?
|
||||||
pub running: bool,
|
pub running: bool,
|
||||||
|
/// Results from the search query
|
||||||
|
pub results: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for App {
|
impl Default for App {
|
||||||
|
@ -18,6 +20,7 @@ impl Default for App {
|
||||||
App {
|
App {
|
||||||
input: Input::default(),
|
input: Input::default(),
|
||||||
running: true,
|
running: true,
|
||||||
|
results: "".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,25 +6,24 @@ use tui_input::backend::crossterm::EventHandler;
|
||||||
|
|
||||||
/// Handles the key events and updates the state of [`App`].
|
/// Handles the key events and updates the state of [`App`].
|
||||||
pub async fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
pub async fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
match key_event.code {
|
match key_event {
|
||||||
// Exit application on `ESC`
|
KeyEvent {
|
||||||
KeyCode::Esc => {
|
code: KeyCode::Char('c'),
|
||||||
|
modifiers: KeyModifiers::CONTROL,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
// Exit application on `Ctrl-C`
|
KeyEvent { code: KeyCode::Esc, .. } => {
|
||||||
KeyCode::Char('c') | KeyCode::Char('C') => {
|
|
||||||
if key_event.modifiers == KeyModifiers::CONTROL {
|
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
}
|
KeyEvent { code: KeyCode::Enter, .. } => {
|
||||||
KeyCode::Enter => {
|
app.results = format!("{:#?}", query_anime(app.input.to_string()).await.unwrap().results);
|
||||||
query_anime(app.input.to_string()).await.unwrap();
|
|
||||||
app.input.reset();
|
app.input.reset();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
app.input.handle_event(&Event::Key(key_event));
|
app.input.handle_event(&Event::Key(key_event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ pub fn render(app: &mut App, frame: &mut Frame) {
|
||||||
chunks[1].y + 1,
|
chunks[1].y + 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
let messages = Paragraph::new("Another placeholder")
|
let messages = Paragraph::new(&*app.results)
|
||||||
.block(Block::default().borders(Borders::ALL).title("Results"));
|
.block(Block::default().borders(Borders::ALL).title("Results"));
|
||||||
frame.render_widget(messages, chunks[2]);
|
frame.render_widget(messages, chunks[2]);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue