Skip to content

Commit

Permalink
(wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
pnmadelaine committed Sep 26, 2023
1 parent 50cb830 commit 53c24bb
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sha256 = "1.1"
stderrlog = "0.5"
substring = "1.4"
surf = "2.3"
time = "0.3"
tokio = { version = "1.22", features = ["full"] }
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = ["Navigator", "Clipboard", "ReadableStream", "Response"] }
1 change: 1 addition & 0 deletions typhon-webapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ seed.workspace = true
serde-wasm-bindgen.workspace = true
serde.workspace = true
serde_json.workspace = true
time.workspace = true
wasm-bindgen-futures.workspace = true
web-sys.workspace = true
13 changes: 11 additions & 2 deletions typhon-webapp/src/jobset.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::timestamp;
use crate::{appurl::AppUrl, perform_request, view_error};

use seed::{prelude::*, *};
use typhon_types::*;

#[derive(Clone)]
pub struct Model {
error: Option<responses::ResponseError>,
evaluations: Vec<(i32, timestamp::Model)>,
handle: handles::Jobset,
info: Option<responses::JobsetInfo>,
}
Expand All @@ -29,6 +32,7 @@ pub fn init(orders: &mut impl Orders<Msg>, handle: handles::Jobset) -> Model {
orders.send_msg(Msg::FetchInfo);
Model {
error: None,
evaluations: Vec::new(),
handle: handle.clone(),
info: None,
}
Expand Down Expand Up @@ -66,6 +70,11 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
);
}
Msg::GetInfo(info) => {
model.evaluations = info
.evaluations
.iter()
.map(|(id, time)| (id.clone(), timestamp::init(time)))
.collect();
model.info = Some(info);
}
Msg::Noop => (),
Expand All @@ -91,8 +100,8 @@ fn view_jobset(model: &Model) -> Node<Msg> {
Some(info) => div![div![
format!("Flake: {}", info.flake),
h3!["Evaluations"],
ul![info.evaluations.iter().map(|(id, time)| li![a![
format!("{}", time), // TODO: format timestamp properly
ul![model.evaluations.iter().map(|(id, time)| li![a![
timestamp::view(time).map_msg(|_| Msg::Noop),
attrs! { At::Href => crate::Urls::evaluation(
&handles::Evaluation{
jobset: model.handle.clone(),
Expand Down
1 change: 1 addition & 0 deletions typhon-webapp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod job;
mod jobset;
mod login;
mod project;
mod timestamp;

use appurl::AppUrl;
use once_cell::sync::OnceCell;
Expand Down
41 changes: 41 additions & 0 deletions typhon-webapp/src/timestamp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use seed::{prelude::*, *};
use time;

#[derive(Clone)]
pub struct Model {
date_time: time::OffsetDateTime,
duration_from_now: time::Duration,
}

#[derive(Clone, Debug)]
pub enum Msg {
Update,
}

fn now() -> time::OffsetDateTime {
let timestamp = js_sys::Date::now();
let duration = time::Duration::new(timestamp as i64 / 1000, 0);
time::OffsetDateTime::UNIX_EPOCH + duration
}

pub fn init(timestamp: &i64) -> Model {
let duration = time::Duration::new(*timestamp, 0);
let date_time = time::OffsetDateTime::UNIX_EPOCH + duration;
let duration_from_now = now() - date_time;
Model {
date_time,
duration_from_now,
}
}

pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
match msg {
Msg::Update => {
model.duration_from_now = time::OffsetDateTime::now_utc() - model.date_time;
}
}
}

pub fn view(model: &Model) -> Node<Msg> {
div![format!("{} ago", model.duration_from_now)]
}

0 comments on commit 53c24bb

Please sign in to comment.