Fix non dynamic routing :-(

This commit is contained in:
Jeremy Wall 2022-12-30 16:43:56 -06:00
parent a39ed5589f
commit 0167e6070d
4 changed files with 58 additions and 49 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ nix/*/result
result
.vscode/
.session_store/
.gitignore/

View File

@ -43,7 +43,6 @@ pub fn TabbedView<'a, G: Html>(cx: Scope<'a>, state: TabState<'a, G>) -> View<G>
view! {cx,
li(class=class) { a(href=href) { (show) } }
}
// TODO
})
.collect(),
);

View File

@ -12,11 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::app_state::StateHandler;
use crate::{
app_state::StateHandler,
components::{Footer, Header},
pages::*,
};
use sycamore::prelude::*;
use sycamore_router::{HistoryIntegration, Route, Router};
use crate::pages::*;
use tracing::{debug, instrument};
#[derive(Route, Debug)]
pub enum Routes {
@ -71,16 +74,12 @@ pub struct HandlerProps<'ctx> {
sh: StateHandler<'ctx>,
}
#[component]
pub fn Handler<'ctx, G: Html>(cx: Scope<'ctx>, props: HandlerProps<'ctx>) -> View<G> {
let HandlerProps { sh } = props;
#[instrument(skip_all, fields(?route))]
fn route_switch<'ctx, G: Html>(route: &Routes, cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<G> {
debug!("Handling route change");
use ManageRoutes::*;
use PlanningRoutes::*;
view! {cx,
Router(
integration=HistoryIntegration::new(),
view=move |cx: Scope, route: &ReadSignal<Routes>| {
match route.get().as_ref() {
match route {
Routes::Planning(Plan) => view! {cx,
PlanPage(sh)
},
@ -116,7 +115,22 @@ pub fn Handler<'ctx, G: Html>(cx: Scope<'ctx>, props: HandlerProps<'ctx>) -> Vie
PlanPage(sh)
},
}
}
#[component]
pub fn Handler<'ctx, G: Html>(cx: Scope<'ctx>, props: HandlerProps<'ctx>) -> View<G> {
let HandlerProps { sh } = props;
view! {cx,
Router(
integration=HistoryIntegration::new(),
view=move |cx: Scope, route: &ReadSignal<Routes>| {
view!{cx,
div(class="app") {
Header(sh)
(route_switch(route.get().as_ref(), cx, sh))
Footer { }
}
}
},
)
}

View File

@ -15,7 +15,6 @@ use sycamore::{futures::spawn_local_scoped, prelude::*};
use tracing::{info, instrument};
use crate::app_state::Message;
use crate::components::{Footer, Header};
use crate::{api, routing::Handler as RouteHandler};
#[instrument]
@ -33,11 +32,7 @@ pub fn UI<G: Html>(cx: Scope) -> View<G> {
sh.dispatch(cx, Message::LoadState);
// TODO(jwall): This needs to be moved into the RouteHandler
view.set(view! { cx,
div(class="app") {
Header(sh)
RouteHandler(sh=sh)
Footer { }
}
});
}
});