diff --git a/rust/src/main.rs b/rust/src/main.rs index 4e35992..f292f62 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -1,6 +1,7 @@ mod sports; use iced::Center; use iced::Element; +use iced::Fill; use iced::widget::{column, image, pane_grid, row, text}; use sports::Game; pub fn main() -> iced::Result { @@ -50,11 +51,21 @@ impl State { let content: Element<'_, Message> = match pane_state { PaneType::NbaPane => { let games = &state.scores; - column![ - text("NBA").size(50), - text(format!("{} vs {}", games[0].team1, games[0].team2)).size(20), - text(format!("{} - {}", games[0].score1, games[0].score2)).size(20), - ] + column(games.iter().map(|game| { + column![ + row![ + text(&game.team1).size(20).width(Fill), + text(&game.team2).size(20).width(Fill), + ], + row![ + text(&game.score1).size(20).width(Fill), + text(&game.score2).size(20).width(Fill), + ], + text(format!("Period: {}", game.period)).size(14), + ] + .padding(10) + .into() + })) .padding(5) .into() } @@ -96,10 +107,7 @@ impl Default for State { news: Vec::new(), weather: text, location: "Sacramento".to_string(), - scores: { - sports::update_nba(); - sports::sports() - }, + scores: { sports::update_nba() }, panes: { let (mut panes, nba) = pane_grid::State::new(PaneType::NbaPane); let (weather, _) = panes diff --git a/rust/src/sports.rs b/rust/src/sports.rs index 294f1c6..ccca945 100644 --- a/rust/src/sports.rs +++ b/rust/src/sports.rs @@ -49,7 +49,7 @@ pub fn sports() -> Vec { ] } -pub fn update_nba() { +pub fn update_nba() -> Vec { let nba_games = ureq::get("https://cdn.nba.com/static/json/liveData/scoreboard/todaysScoreboard_00.json") .header("User-Agent", "deathclock-app/1.0") @@ -61,6 +61,7 @@ pub fn update_nba() { let json: serde_json::Value = serde_json::from_slice(&nba_games).unwrap(); let games = json["scoreboard"]["games"].as_array().unwrap(); + let mut updated_games: Vec = Vec::new(); for game in games { let game_id = game["gameId"].as_str().unwrap(); @@ -79,6 +80,7 @@ pub fn update_nba() { period, ); game.update(&home_score, &away_score, period); + updated_games.push(game); println!("Game ID: {}", game_id); println!("Home Team: {}", home_team); println!("Away Team: {}", away_team); @@ -86,4 +88,5 @@ pub fn update_nba() { println!("Away Score: {}", away_score); println!("Period: {}", period); } + updated_games }