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
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ repos:
language: system
types: [rust]
pass_filenames: false
- id: dioxus-check
name: dioxus check
entry: dx check
language: system
types: [rust]
pass_filenames: false
12 changes: 7 additions & 5 deletions src/components/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ fn handle_action(selected_race: &mut Signal<SelectedRace>, action: Action) {
#[component]
pub fn App() -> Element {
let mut selected_race = use_signal(|| SelectedRace::None);
let config = use_context::<Config>();

use_coroutine(
move |mut actions_rx: UnboundedReceiver<Action>| async move {
use_coroutine(move |mut actions_rx: UnboundedReceiver<Action>| {
let config = config.clone();
async move {
let (tx, mut rfid_rx) = broadcast::channel::<rfid_reader::Event>(128);
for serial in use_context::<Config>().rfid_devices {
for serial in config.rfid_devices {
tokio::spawn(rfid_reader::rfid_serial(serial, tx.clone()));
}

Expand All @@ -79,8 +81,8 @@ pub fn App() -> Element {
}
}
}
},
);
}
});

rsx! {
div {
Expand Down
25 changes: 15 additions & 10 deletions src/components/races_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@ use crate::{race::Race, restclient::RaceRestAPI};

type SignalRace = Signal<Option<Result<Race, Box<dyn std::error::Error>>>>;

async fn load_race(mut selected_race: SignalRace, id: u32) {
async fn load_race(api: RaceRestAPI, mut selected_race: SignalRace, id: u32) {
selected_race.set(None);
let race = Race::load(use_context::<RaceRestAPI>(), id).await;
let race = Race::load(api, id).await;
selected_race.set(Some(race));
}

#[component]
pub fn RacesList(selected_race: SignalRace) -> Element {
let api = use_context::<RaceRestAPI>();

let races: Resource<Result<Vec<crate::restclient::Race>, Box<dyn Error>>> =
use_resource(move || async move {
let api = use_context::<RaceRestAPI>();
let mut races = api.races().await?;
races.sort_by(|a, b| b.date_of_event.cmp(&a.date_of_event));
use_resource(move || {
let api = api.clone();
async move {
let mut races = api.races().await?;
races.sort_by(|a, b| b.date_of_event.cmp(&a.date_of_event));

if let Some(earliest_race) = races.first() {
load_race(selected_race, earliest_race.id).await;
if let Some(earliest_race) = races.first() {
load_race(api, selected_race, earliest_race.id).await;
}
Ok(races)
}
Ok(races)
});

rsx! {
Expand All @@ -34,8 +38,9 @@ pub fn RacesList(selected_race: SignalRace) -> Element {
onchange: move |e| {
e.prevent_default();
let race_id = e.value().parse::<u32>().ok().unwrap();
let api = use_context::<RaceRestAPI>();
spawn(async move {
load_race(selected_race, race_id).await;
load_race(api, selected_race, race_id).await;
});
},
for race in races.iter() {
Expand Down
Loading