Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ pub fn App() -> Element {
Some(Ok(race)) => rsx! {
if show_starts() {
div { class: "d-flex flex-column row-gap-1 mb-1",
for track in race.clone().tracks {
TrackStart { track: track.clone() }
for (track , start) in race.tracks_with_start() {
TrackStart { track, start }
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/components/time_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ fn format_time(time: DateTime<Utc>) -> String {

#[component]
pub fn TimeInput(
time: Signal<Option<DateTime<Utc>>>,
time: Option<DateTime<Utc>>,
editing: Signal<bool>,
onsave: EventHandler<DateTime<Utc>>,
) -> Element {
let mut text = use_signal(|| "".to_string());

use_effect(move || {
text.set(match time() {
Some(start) => format_time(start),
None => "".to_string(),
});
if editing() {
text.set(match time {
Some(start) => format_time(start),
None => "".to_string(),
});
}
});

rsx! {
Expand All @@ -41,7 +43,6 @@ pub fn TimeInput(
onkeydown: move |evt| {
if evt.key() == Key::Enter {
if let Some(parsed) = parse_time(&text()) {
time.set(Some(parsed));
editing.set(false);
onsave(parsed);
}
Expand All @@ -57,7 +58,7 @@ pub fn TimeInput(
ondoubleclick: move |_evt| {
editing.set(true);
},
if let Some(start) = time() {
if let Some(start) = time {
{format_time(start)}
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/components/track_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use crate::{
};

#[component]
pub fn TrackStart(track: Track) -> Element {
let mut start: Signal<Option<DateTime<Utc>>> = use_signal(|| None);
pub fn TrackStart(track: Track, start: Option<DateTime<Utc>>) -> Element {
let mut editing = use_signal(|| false);
let track2 = track.clone();

Expand All @@ -23,7 +22,6 @@ pub fn TrackStart(track: Track) -> Element {
time: start,
editing,
onsave: move |time| {
start.set(Some(time));
use_coroutine_handle::<Action>().send(Action::Start(track.clone(), time));
},
}
Expand All @@ -42,7 +40,6 @@ pub fn TrackStart(track: Track) -> Element {
button {
class: "btn btn-success",
onclick: move |_| {
start.set(Some(Utc::now()));
use_coroutine_handle::<Action>().send(Action::Start(track2.clone(), Utc::now()));
},
"Start"
Expand Down
11 changes: 11 additions & 0 deletions src/race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct Race {
pub racers: Vec<Racer>,
pub categories: Vec<Category>,
pub tracks: Vec<Track>,
track_starts: HashMap<Track, DateTime<Utc>>,
log: Rc<RefCell<RaceEvents>>,
}

Expand Down Expand Up @@ -223,20 +224,29 @@ impl Race {
racers,
categories,
tracks,
track_starts: racelog.track_starts.clone(),
log: RefCell::new(racelog).into(),
};
race.map_start_number_to_track_rank();
race.map_start_number_to_categories_rank();
Ok(race)
}

pub fn tracks_with_start(&self) -> Vec<(Track, Option<DateTime<Utc>>)> {
self.tracks
.iter()
.map(|track| (track.clone(), self.track_starts.get(track).copied()))
.collect()
}

pub fn start(&mut self, track: Track, time: DateTime<Utc>) {
for racer in self.racers.iter_mut() {
if racer.track == track {
racer.start = Some(time);
self.log.borrow_mut().log_start(&track, time);
}
}
self.track_starts.insert(track, time);
}

fn finish<F>(&mut self, mut predicate: F) -> Result<(), ()>
Expand Down Expand Up @@ -433,6 +443,7 @@ mod tests {
racers,
categories: vec![],
tracks: vec![track.clone()],
track_starts: HashMap::new(),
log: Rc::new(RefCell::new(RaceEvents::load(100000))),
};

Expand Down
2 changes: 1 addition & 1 deletion src/race_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl PartialEq for RaceEvents {

pub struct RaceEvents {
writer: BufWriter<File>,
track_starts: HashMap<Track, DateTime<Utc>>,
pub track_starts: HashMap<Track, DateTime<Utc>>,
finish_times: HashMap<StartNumber, DateTime<Utc>>,
}

Expand Down
Loading