Skip to content
Snippets Groups Projects
Commit 934f646e authored by marcantoinem's avatar marcantoinem
Browse files

Improve number input

parent de3a210e
No related branches found
No related tags found
No related merge requests found
...@@ -36,16 +36,20 @@ pub struct AppState { ...@@ -36,16 +36,20 @@ pub struct AppState {
impl AppState { impl AppState {
pub async fn new(leptos_options: LeptosOptions, routes: Vec<RouteListing>) -> Self { pub async fn new(leptos_options: LeptosOptions, routes: Vec<RouteListing>) -> Self {
let client = reqwest::Client::builder() #[cfg(not(debug_assertions))]
.user_agent("NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m)") {
.build() // Don't spam Poly when reloading the website in debug mode
.unwrap(); let client = reqwest::Client::builder()
let horsage = client.get(HORSAGE_URL).send().await.unwrap(); .user_agent("NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m)")
let horsage = horsage.text().await.unwrap(); .build()
let fermes = client.get(FERME_URL).send().await.unwrap(); .unwrap();
let fermes = fermes.text().await.unwrap(); let horsage = client.get(HORSAGE_URL).send().await.unwrap();
fs::write("horsage.csv", horsage).expect("Unable to write file"); let horsage = horsage.text().await.unwrap();
fs::write("fermes.csv", fermes).expect("Unable to write file"); let fermes = client.get(FERME_URL).send().await.unwrap();
let fermes = fermes.text().await.unwrap();
fs::write("horsage.csv", horsage).expect("Unable to write file");
fs::write("fermes.csv", fermes).expect("Unable to write file");
}
let horsage = BufReader::new(File::open("horsage.csv").unwrap()); let horsage = BufReader::new(File::open("horsage.csv").unwrap());
let fermes = BufReader::new(File::open("fermes.csv").unwrap()); let fermes = BufReader::new(File::open("fermes.csv").unwrap());
let courses = Arc::new(RwLock::new(Courses::from_csv(horsage, fermes))); let courses = Arc::new(RwLock::new(Courses::from_csv(horsage, fermes)));
......
use leptos::*; use leptos::*;
#[component] #[component]
pub fn NumberInput(#[prop(optional, into)] value: RwSignal<u8>, max: u8) -> impl IntoView { pub fn NumberInput<F>(
#[prop(optional, into)] value: RwSignal<u8>,
max: u8,
label: &'static str,
submit: F,
) -> impl IntoView
where
F: Fn() + Copy + 'static,
{
let on_input = move |ev| { let on_input = move |ev| {
value.set(event_target_value(&ev).parse::<u8>().unwrap()); value.set(event_target_value(&ev).parse::<u8>().unwrap());
submit();
};
let minus = move |_| {
let v = value.get();
if v > 0 {
value.set(v - 1);
submit();
}
};
let plus = move |_| {
let v = value.get();
if v != u8::MAX {
value.set(v + 1);
submit();
}
submit();
}; };
view! { view! {
<input <div class="flex flex-row gap-8 items-center">
on:input=on_input <p class="text-white font-sans">{label}</p>
type="number" <div class="relative flex items-center max-w-20">
min="0" <button on:click=minus type="button" class="bg-gray-100 hover:bg-gray-200 border border-gray-300 rounded-s-lg p-1 h-7 focus:ring-gray-100 focus:ring-2 focus:outline-none">
max=max <svg class="w-3 h-3 text-gray-900" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 2">
prop:value=value <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 1h16"/>
class="number-input" </svg>
/> </button>
<input
type="numeric"
class="bg-gray-50 border-x-0 border-gray-300 h-7 text-center text-gray-900 text-sm focus:ring-amber-500 focus:border-amber-500 block w-full py-2.5"
placeholder="0"
on:input=on_input
type="number"
min="0"
max=max
prop:value=value
required />
<button on:click=plus type="button" class="bg-gray-100 hover:bg-gray-200 border border-gray-300 rounded-e-lg p-1 h-7 focus:ring-gray-100 focus:ring-2 focus:outline-none">
<svg class="w-3 h-3 text-gray-900" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 1v16M1 9h16"/>
</svg>
</button>
</div>
</div>
} }
} }
...@@ -28,7 +28,7 @@ pub fn OptionsForms(action: Action<SchedulesOptions, Vec<Schedule>>) -> impl Int ...@@ -28,7 +28,7 @@ pub fn OptionsForms(action: Action<SchedulesOptions, Vec<Schedule>>) -> impl Int
view! { view! {
<CoursesSelector state=state submit/> <CoursesSelector state=state submit/>
<span class="grow"></span> <span class="grow"></span>
<div class="row-container input-item auto-bottom"><p>"Nombre de conflits maximum"</p><NumberInput value=state.max_nb_conflicts max=127/></div> <NumberInput value=state.max_nb_conflicts max=127 label="Nombre de période de cours en conflits maximum: " submit/>
<SelectOptimizations state=state submit/> <SelectOptimizations state=state submit/>
<button on:click=submit_mobile class="lg:hidden select-none rounded-lg bg-amber-500 py-2 text-xl px-4 w-64 self-center text-center align-middle text-black shadow-md shadow-amber-500/20 transition-all hover:shadow-lg hover:shadow-amber-500/40 focus:opacity-[0.85] focus:shadow-none active:opacity-[0.85] active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none">"Générer les horaires"</button> <button on:click=submit_mobile class="lg:hidden select-none rounded-lg bg-amber-500 py-2 text-xl px-4 w-64 self-center text-center align-middle text-black shadow-md shadow-amber-500/20 transition-all hover:shadow-lg hover:shadow-amber-500/40 focus:opacity-[0.85] focus:shadow-none active:opacity-[0.85] active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none">"Générer les horaires"</button>
} }
......
...@@ -30,7 +30,7 @@ where ...@@ -30,7 +30,7 @@ where
<div class="col-container"> <div class="col-container">
<House weight=weight_house size="10vh"/> <House weight=weight_house size="10vh"/>
<p>"Plus de congés"</p> <p>"Plus de congés"</p>
<input type="range" min="0" max="4" class="opti-slider" prop:value=state.day_off on:input=move |ev| { <input type="range" min="0" max="4" class="opti-slider accent-amber-500" prop:value=state.day_off on:input=move |ev| {
state.day_off.set(event_target_value(&ev).parse::<u8>().unwrap()); state.day_off.set(event_target_value(&ev).parse::<u8>().unwrap());
submit(); submit();
}/> }/>
...@@ -41,7 +41,7 @@ where ...@@ -41,7 +41,7 @@ where
<Sun weight=weight_morning size="10vh"/> <Sun weight=weight_morning size="10vh"/>
</div> </div>
<p>"Cours plus tôt ou plus tard"</p> <p>"Cours plus tôt ou plus tard"</p>
<input type="range" min="-4" max="4" class="opti-slider" prop:value=state.morning on:input=move |ev| { <input type="range" min="-4" max="4" class="opti-slider accent-amber-500" prop:value=state.morning on:input=move |ev| {
state.morning.set(event_target_value(&ev).parse::<i8>().unwrap()); state.morning.set(event_target_value(&ev).parse::<i8>().unwrap());
submit(); submit();
}/> }/>
...@@ -49,7 +49,7 @@ where ...@@ -49,7 +49,7 @@ where
<div class="col-container"> <div class="col-container">
<CalendarCheck weight=weight_finish size="10vh"/> <CalendarCheck weight=weight_finish size="10vh"/>
<p>"Finir plus tôt"</p> <p>"Finir plus tôt"</p>
<input type="range" min="0" max="4" class="opti-slider" prop:value=state.finish_early on:input=move |ev| { <input type="range" min="0" max="4" class="opti-slider accent-amber-500" prop:value=state.finish_early on:input=move |ev| {
state.finish_early.set(event_target_value(&ev).parse::<u8>().unwrap()); state.finish_early.set(event_target_value(&ev).parse::<u8>().unwrap());
submit(); submit();
}/> }/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment