Skip to content

Commit

Permalink
fixed a bug when no ETA
Browse files Browse the repository at this point in the history
  • Loading branch information
sverrejb committed Feb 16, 2024
1 parent 26ea02b commit 30cca0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 13 additions & 7 deletions src/food/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::ui::*;
use chrono::Local;
use log::{error, info};
use reqwest::Url;
use slint::Weak;
use slint::{SharedString, Weak};
use std::sync::mpsc::{self, Receiver, TryRecvError};
use std::thread;
use tokio::runtime::Runtime;
Expand All @@ -28,13 +28,12 @@ pub fn setup(main_window: &MainWindow) {
}

async fn food_worker_loop(window: Weak<MainWindow>, rx: Receiver<Url>) {
let mut current_url: Option<Url> = None;
let mut current_url = None;
let mut current_tracking = FoodTracking::default();

loop {
match rx.try_recv() {
Ok(tracking_url) => {
//TODO: Use logging instead of println
info!("Got new tracking url: {}", tracking_url);
current_url = Some(tracking_url);
}
Expand All @@ -49,12 +48,19 @@ async fn food_worker_loop(window: Weak<MainWindow>, rx: Receiver<Url>) {

current_tracking = match tracking_response {
Ok(tracking_response) => {
let remaining_time =
((tracking_response.delivery_eta.unwrap()) - Local::now()).num_minutes();
let minutes_remaining: SharedString = match tracking_response.delivery_eta {
Some(eta) => ((eta) - Local::now()).num_minutes().to_string().into(),
None => "ukjent antall".into(),
};

let active = tracking_response.status != "delivered";
if !active {
current_url = None;
}
FoodTracking {
resturant_name: tracking_response.from_location.name.en.into(),
minutes_remaining: remaining_time.to_string().into(),
active: tracking_response.status != "delivered",
minutes_remaining,
active,
}
}
Err(e) => {
Expand Down
6 changes: 2 additions & 4 deletions src/food/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use reqwest::Url;
use serde::Deserialize;
use tide::Request;

// const WOLT_TRACKING_URL: &str =
// "https://consumer-api.wolt.com/order-tracking-api/v1/details/tracking-code/track/";

const WOLT_TRACKING_URL: &str = "http://localhost:9000/";
const WOLT_TRACKING_URL: &str =
"https://consumer-api.wolt.com/order-tracking-api/v1/details/tracking-code/track/";

pub async fn food_endpoint_server(tx: Sender<Url>) -> tide::Result<()> {
let mut app = tide::new();
Expand Down

0 comments on commit 30cca0e

Please sign in to comment.