feat: showing results (just JSON currently) after submitting query

This commit is contained in:
Muhammad Nauman Raza 2024-05-28 17:33:56 +01:00
parent 78a5efd8fa
commit e6fbb1bb1e
Signed by: devraza
GPG key ID: 91EAD6081011574B
3 changed files with 14 additions and 12 deletions

View file

@ -11,6 +11,8 @@ pub struct App {
pub input: Input,
/// Is the app running?
pub running: bool,
/// Results from the search query
pub results: String,
}
impl Default for App {
@ -18,6 +20,7 @@ impl Default for App {
App {
input: Input::default(),
running: true,
results: "".to_string(),
}
}
}

View file

@ -6,25 +6,24 @@ use tui_input::backend::crossterm::EventHandler;
/// Handles the key events and updates the state of [`App`].
pub async fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
match key_event.code {
// Exit application on `ESC`
KeyCode::Esc => {
match key_event {
KeyEvent {
code: KeyCode::Char('c'),
modifiers: KeyModifiers::CONTROL,
..
} => {
app.quit();
}
// Exit application on `Ctrl-C`
KeyCode::Char('c') | KeyCode::Char('C') => {
if key_event.modifiers == KeyModifiers::CONTROL {
app.quit();
}
KeyEvent { code: KeyCode::Esc, .. } => {
app.quit();
}
KeyCode::Enter => {
query_anime(app.input.to_string()).await.unwrap();
KeyEvent { code: KeyCode::Enter, .. } => {
app.results = format!("{:#?}", query_anime(app.input.to_string()).await.unwrap().results);
app.input.reset();
}
_ => {
app.input.handle_event(&Event::Key(key_event));
}
}
Ok(())
}

View file

@ -51,7 +51,7 @@ pub fn render(app: &mut App, frame: &mut Frame) {
chunks[1].y + 1,
);
let messages = Paragraph::new("Another placeholder")
let messages = Paragraph::new(&*app.results)
.block(Block::default().borders(Borders::ALL).title("Results"));
frame.render_widget(messages, chunks[2]);
}