refactor wall
This commit is contained in:
@@ -25,7 +25,7 @@ pub fn shell(options: LeptosOptions) -> impl IntoView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App() -> impl leptos::IntoView {
|
pub fn App() -> impl IntoView {
|
||||||
use leptos_meta::Stylesheet;
|
use leptos_meta::Stylesheet;
|
||||||
use leptos_meta::Title;
|
use leptos_meta::Title;
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ pub fn App() -> impl leptos::IntoView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Home() -> impl leptos::IntoView {
|
pub fn Home() -> impl IntoView {
|
||||||
// TODO: show cards with walls, and a "new wall" button
|
// TODO: show cards with walls, and a "new wall" button
|
||||||
|
|
||||||
tracing::debug!("Rendering home component");
|
tracing::debug!("Rendering home component");
|
||||||
|
|||||||
@@ -67,6 +67,11 @@ pub fn hydrate() {
|
|||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
|
.with_env_filter(
|
||||||
|
tracing_subscriber::EnvFilter::builder()
|
||||||
|
.with_default_directive(tracing::level_filters::LevelFilter::DEBUG.into())
|
||||||
|
.from_env_lossy(),
|
||||||
|
)
|
||||||
.with_writer(
|
.with_writer(
|
||||||
// To avoide trace events in the browser from showing their JS backtrace
|
// To avoide trace events in the browser from showing their JS backtrace
|
||||||
tracing_subscriber_wasm::MakeConsoleWriter::default().map_trace_level_to(tracing::Level::DEBUG),
|
tracing_subscriber_wasm::MakeConsoleWriter::default().map_trace_level_to(tracing::Level::DEBUG),
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ struct RouteParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn EditWall() -> impl leptos::IntoView {
|
pub fn EditWall() -> impl IntoView {
|
||||||
let params = leptos_router::hooks::use_params::<RouteParams>();
|
let params = leptos_router::hooks::use_params::<RouteParams>();
|
||||||
let wall_uid = Signal::derive(move || {
|
let wall_uid = Signal::derive(move || {
|
||||||
params
|
params
|
||||||
@@ -73,7 +73,7 @@ pub fn EditWall() -> impl leptos::IntoView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
fn Ready(wall: models::Wall) -> impl leptos::IntoView {
|
fn Ready(wall: models::Wall) -> impl IntoView {
|
||||||
tracing::debug!("ready");
|
tracing::debug!("ready");
|
||||||
|
|
||||||
let mut holds = vec![];
|
let mut holds = vec![];
|
||||||
@@ -92,7 +92,7 @@ fn Ready(wall: models::Wall) -> impl leptos::IntoView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
fn Hold(hold: models::Hold) -> impl leptos::IntoView {
|
fn Hold(hold: models::Hold) -> impl IntoView {
|
||||||
let hold_position = hold.position;
|
let hold_position = hold.position;
|
||||||
let file_input_ref = NodeRef::<Input>::new();
|
let file_input_ref = NodeRef::<Input>::new();
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ struct RouteParams {
|
|||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub fn Routes() -> impl leptos::IntoView {
|
pub fn Routes() -> impl IntoView {
|
||||||
tracing::debug!("Enter");
|
tracing::debug!("Enter");
|
||||||
|
|
||||||
let params = leptos_router::hooks::use_params::<RouteParams>();
|
let params = leptos_router::hooks::use_params::<RouteParams>();
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use crate::codec::ron::Ron;
|
|
||||||
use crate::codec::ron::RonEncoded;
|
use crate::codec::ron::RonEncoded;
|
||||||
use crate::components::button::Button;
|
use crate::components::button::Button;
|
||||||
use crate::components::header::HeaderItem;
|
use crate::components::header::HeaderItem;
|
||||||
@@ -31,34 +30,31 @@ pub fn Wall() -> impl IntoView {
|
|||||||
|
|
||||||
let wall = crate::resources::wall_by_uid(wall_uid);
|
let wall = crate::resources::wall_by_uid(wall_uid);
|
||||||
|
|
||||||
let (problem_uid, set_problem_uid) = signal(None);
|
let problem_action = Action::new(move |&(wall_uid, problem_uid): &(models::WallUid, models::ProblemUid)| async move {
|
||||||
|
tracing::info!("fetching");
|
||||||
let mut init_problem = false;
|
crate::server_functions::get_problem(wall_uid, problem_uid)
|
||||||
Effect::new(move || {
|
.await
|
||||||
if !init_problem {
|
.map(RonEncoded::into_inner)
|
||||||
if let Some(Ok(wall)) = &*wall.read() {
|
});
|
||||||
set_problem_uid.set(wall.random_problem());
|
let problem_signal = Signal::derive(move || {
|
||||||
init_problem = true;
|
let v = problem_action.value().read_only().get();
|
||||||
}
|
tracing::debug!("val: {:?}", v);
|
||||||
}
|
v.and_then(Result::ok)
|
||||||
});
|
});
|
||||||
|
|
||||||
let problem: Resource<Option<models::Problem>, Ron> = Resource::new_with_options(
|
Effect::new(move |_prev_value| {
|
||||||
move || (wall_uid.get(), problem_uid.get()),
|
problem_action.value().write_only().set(None);
|
||||||
move |(wall_uid, problem_uid)| async move {
|
match wall.get() {
|
||||||
let Some(problem_uid) = problem_uid else {
|
Some(Ok(wall)) => {
|
||||||
return None;
|
if let Some(problem_uid) = wall.random_problem() {
|
||||||
};
|
tracing::debug!("dispatching from effect");
|
||||||
crate::server_functions::get_problem(wall_uid, problem_uid)
|
problem_action.dispatch((wall.uid, problem_uid));
|
||||||
.await
|
}
|
||||||
.map(RonEncoded::into_inner)
|
}
|
||||||
.inspect_err(|err| {
|
Some(Err(_err)) => {}
|
||||||
tracing::error!("{err}");
|
None => {}
|
||||||
})
|
}
|
||||||
.ok()
|
});
|
||||||
},
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
let header_items = move || HeaderItems {
|
let header_items = move || HeaderItems {
|
||||||
left: vec![],
|
left: vec![],
|
||||||
@@ -83,59 +79,34 @@ pub fn Wall() -> impl IntoView {
|
|||||||
<StyledHeader items=Signal::derive(header_items) />
|
<StyledHeader items=Signal::derive(header_items) />
|
||||||
|
|
||||||
<div class="m-2">
|
<div class="m-2">
|
||||||
<Suspense fallback=move || {
|
<Suspense fallback=move || view! { <p>"Loading..."</p> } >
|
||||||
view! { <p>"Loading..."</p> }
|
|
||||||
}>
|
|
||||||
{move || Suspend::new(async move {
|
{move || Suspend::new(async move {
|
||||||
let wall = wall.await;
|
tracing::info!("executing Suspend future");
|
||||||
let problem = problem.await;
|
let wall = wall.await?;
|
||||||
|
|
||||||
wall.map(move |wall| {
|
let v = view! {
|
||||||
let mut cells = vec![];
|
<div class="grid grid-cols-[auto,1fr] gap-8">
|
||||||
for (&hold_position, hold) in &wall.holds {
|
<Grid wall=wall.clone() problem=problem_signal />
|
||||||
let problem = problem.clone();
|
|
||||||
let role = move || {
|
|
||||||
problem
|
|
||||||
.clone()
|
|
||||||
.and_then(|problem| {
|
|
||||||
problem.holds.get(&hold_position).copied()
|
|
||||||
})
|
|
||||||
};
|
|
||||||
let role = Signal::derive(role);
|
|
||||||
let cell = view! { <Hold role hold=hold.clone() /> };
|
|
||||||
cells.push(cell);
|
|
||||||
}
|
|
||||||
let grid_classes = format!(
|
|
||||||
"grid grid-rows-{} grid-cols-{} gap-3",
|
|
||||||
wall.rows,
|
|
||||||
wall.cols,
|
|
||||||
);
|
|
||||||
view! {
|
|
||||||
<div class="grid grid-cols-[auto,1fr] gap-8">
|
|
||||||
// Render the wall
|
|
||||||
<div
|
|
||||||
style="max-height: 90vh; max-width: 90vh;"
|
|
||||||
class=move || { grid_classes.clone() }
|
|
||||||
>
|
|
||||||
{cells}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
<div>
|
||||||
<div>
|
<div>
|
||||||
// TODO:
|
<p>{move || problem_signal.get().map(|p| p.name.clone())}</p>
|
||||||
// <p>{current_problem.read().as_ref().map(|p| p.name.clone())}</p>
|
<p>{move || problem_signal.get().map(|p| p.set_by.clone())}</p>
|
||||||
// <p>{current_problem.read().as_ref().map(|p| p.set_by.clone())}</p>
|
|
||||||
<div></div>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
onclick=move |_| {
|
|
||||||
set_problem_uid.set(wall.random_problem());
|
|
||||||
}
|
|
||||||
text="➤ Next problem"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onclick=move |_| {
|
||||||
|
if let Some(problem_uid) = wall.random_problem() {
|
||||||
|
tracing::info!("dispatching from button click handler");
|
||||||
|
problem_action.dispatch((wall.uid, problem_uid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
text="➤ Next problem"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
}
|
</div>
|
||||||
})
|
};
|
||||||
|
Ok::<_, ServerFnError>(v)
|
||||||
})}
|
})}
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</div>
|
</div>
|
||||||
@@ -145,7 +116,30 @@ pub fn Wall() -> impl IntoView {
|
|||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
fn Hold(hold: models::Hold, #[prop(into)] role: Signal<Option<HoldRole>>) -> impl leptos::IntoView {
|
fn Grid(wall: models::Wall, problem: Signal<Option<models::Problem>>) -> impl IntoView {
|
||||||
|
tracing::debug!("Enter");
|
||||||
|
|
||||||
|
let mut cells = vec![];
|
||||||
|
for (&hold_position, hold) in &wall.holds {
|
||||||
|
let role = move || problem.get().and_then(|p| p.holds.get(&hold_position).copied());
|
||||||
|
let role = Signal::derive(role);
|
||||||
|
let cell = view! { <Hold role hold=hold.clone() /> };
|
||||||
|
cells.push(cell);
|
||||||
|
}
|
||||||
|
let grid_classes = format!("grid grid-rows-{} grid-cols-{} gap-3", wall.rows, wall.cols,);
|
||||||
|
|
||||||
|
view! {
|
||||||
|
<div class="grid grid-cols-[auto,1fr] gap-8">
|
||||||
|
<div style="max-height: 90vh; max-width: 90vh;" class=move || { grid_classes.clone() }>
|
||||||
|
{cells}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
#[tracing::instrument(skip_all)]
|
||||||
|
fn Hold(hold: models::Hold, role: Signal<Option<HoldRole>>) -> impl IntoView {
|
||||||
tracing::trace!("Enter");
|
tracing::trace!("Enter");
|
||||||
let class = move || {
|
let class = move || {
|
||||||
let role_classes = match role.get() {
|
let role_classes = match role.get() {
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ async fn serve(cli: Cli) -> Result<(), Error> {
|
|||||||
let leptos_options = leptos_conf_file.leptos_options;
|
let leptos_options = leptos_conf_file.leptos_options;
|
||||||
let addr = leptos_options.site_addr;
|
let addr = leptos_options.site_addr;
|
||||||
let routes = generate_route_list(App);
|
let routes = generate_route_list(App);
|
||||||
dbg!(&routes);
|
|
||||||
|
|
||||||
let config = load_config(cli)?;
|
let config = load_config(cli)?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user