Skip to content
Snippets Groups Projects
Commit 0029fe41 authored by marcantoinem's avatar marcantoinem
Browse files

feat: implement infinite scroll

parent 390da5ea
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,21 @@ pub fn GeneratorPage() -> impl IntoView { ...@@ -32,7 +32,21 @@ pub fn GeneratorPage() -> impl IntoView {
<aside class="left-panel" class=("hide-left-panel", hide)> <aside class="left-panel" class=("hide-left-panel", hide)>
<OptionsForms/> <OptionsForms/>
</aside> </aside>
<section class="right-panel"> <section class="right-panel" on:scroll=move |ev| {
use web_sys::wasm_bindgen::JsCast;
let target = ev
.target()
.unwrap()
.dyn_into::<web_sys::Element>()
.unwrap();
let scroll_top = target.scroll_top() as f64;
logging::log!("{} {}", scroll_top, target.client_height());
if (scroll_top + target.client_height() as f64 >= target.scroll_height() as f64 - 500.0) && state.step.get() == 5 {
state.regenerate();
}
}>
<SchedulesComponent/> <SchedulesComponent/>
</section> </section>
<Notifications modal set_modal/> <Notifications modal set_modal/>
......
...@@ -23,6 +23,7 @@ pub struct OptionState { ...@@ -23,6 +23,7 @@ pub struct OptionState {
pub step: RwSignal<u8>, pub step: RwSignal<u8>,
pub hide: RwSignal<bool>, pub hide: RwSignal<bool>,
pub schedule: RwSignal<Vec<Schedule>>, pub schedule: RwSignal<Vec<Schedule>>,
pub max_size: StoredValue<usize>,
} }
impl OptionState { impl OptionState {
...@@ -67,6 +68,18 @@ impl OptionState { ...@@ -67,6 +68,18 @@ impl OptionState {
} }
pub fn generate(&self) { pub fn generate(&self) {
self.max_size.set_value(5);
self.gen();
}
pub fn regenerate(&self) {
self.max_size.update_value(|size| {
*size = std::cmp::max(*size * 2, 2usize.pow(16));
});
self.gen();
}
fn gen(&self) {
let mut schedule_option: SchedulesOptions = self.into(); let mut schedule_option: SchedulesOptions = self.into();
schedule_option.apply_personal_schedule(); schedule_option.apply_personal_schedule();
let schedules = schedule_option.get_schedules().into_sorted_vec(); let schedules = schedule_option.get_schedules().into_sorted_vec();
...@@ -107,6 +120,7 @@ impl Default for OptionState { ...@@ -107,6 +120,7 @@ impl Default for OptionState {
step: create_rw_signal(0), step: create_rw_signal(0),
schedule: create_rw_signal(vec![]), schedule: create_rw_signal(vec![]),
hide: create_rw_signal(false), hide: create_rw_signal(false),
max_size: store_value(5usize),
} }
} }
} }
...@@ -121,6 +135,7 @@ impl From<&OptionState> for SchedulesOptions { ...@@ -121,6 +135,7 @@ impl From<&OptionState> for SchedulesOptions {
.into_iter() .into_iter()
.map(|c| c.into()) .map(|c| c.into())
.collect(); .collect();
let max_size = state.max_size.get_value();
let max_nb_conflicts = state.max_nb_conflicts.get(); let max_nb_conflicts = state.max_nb_conflicts.get();
let evaluation = EvaluationOption { let evaluation = EvaluationOption {
day_off: state.day_off.get(), day_off: state.day_off.get(),
...@@ -133,7 +148,7 @@ impl From<&OptionState> for SchedulesOptions { ...@@ -133,7 +148,7 @@ impl From<&OptionState> for SchedulesOptions {
max_nb_conflicts, max_nb_conflicts,
evaluation, evaluation,
user_conflicts, user_conflicts,
max_size: 10, max_size,
} }
} }
} }
$background-color: #151420; $background-color: #151420;
$highlight-color: #F28A00; $highlight-color: rgb(245 158 11);
$highlight-text: #0F1741; $highlight-text: #0F1741;
$tern-color: #daa662; $tern-color: #daa662;
$tern-text: #3b3b3b; $tern-text: #3b3b3b;
...@@ -11,9 +11,10 @@ $success: #0FCC3B; ...@@ -11,9 +11,10 @@ $success: #0FCC3B;
@keyframes fadeIn { @keyframes fadeIn {
0% { 0% {
opacity: 0; opacity: 0;
} }
100% { 100% {
opacity: 1; opacity: 1;
} }
} }
\ No newline at end of file
...@@ -125,6 +125,8 @@ main { ...@@ -125,6 +125,8 @@ main {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
overflow-y: auto;
max-height: calc(100vh - 3em);
gap: 3rem; gap: 3rem;
padding: 1rem; padding: 1rem;
background-color: $light-background; background-color: $light-background;
......
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