#How does dioxus_router::Router work?

15 messages · Page 1 of 1 (latest)

sacred sentinel
#

I've tried following the code, but my rust game is minimal (I'm just a lost Gopher).

More precisely my question is how does it know which route to display? I'm trying to follow/copy the code for a slides component library where each slide is in an enum (like routes).

I'm trying to figure out what to do here (commented out code was co-pilots attempt): https://github.com/alexanderjophus/dioxus-slides/blob/main/packages/slides/src/slides.rs#L21-L28

For reference here's the router version: https://github.com/DioxusLabs/dioxus/blob/master/packages/router/src/components/router.rs#L147-L164

Full code is here: https://github.com/alexanderjophus/dioxus-slides

hollow rune
#

Copilot is close, you need to get the route from somewhere, but generally it is correct:

let slide = &R::from_str("route").unwrap();
slide.render(cx)
sacred sentinel
#

This is a huge help. I cannot stress that enough. Thank you so much for your time

sacred sentinel
#

I have it showing the first slide. I think I now have 2 problems to solve and we're in a v0.0.1 state

  1. have a way to link to prev/next slides (copyable from Link?)
  2. figure out how to define a #[default] in the enum that would be the first slide

Thank you again, this has been huge.

hollow rune
#
  1. For the link you can change this (https://github.com/alexanderjophus/dioxus-slides/blob/4ae711cd0111348577eab9cd59435d3d716e6764/packages/slides/src/slides.rs#L21) to a use_shared_state that stores the current slide. You can render the current route in the Slider component. In the next component you can consume the state and move to the next silde
GitHub

A slides component library for creating slideshows in dioxus - alexanderjophus/dioxus-slides

sacred sentinel
#

How do you have access to my VSCode screen, that's literally what I'm working on 😄

hollow rune
#
  1. If you make the enum full of only unit members you can use #[default]:
#[derive(Slidable, Clone, Default)]
enum Slides {
    #[default]
    Intro,
    Second,
    Final,
}
sacred sentinel
#

a use_shared_state that stores the current slide
What does this look like? I've tried let slide = use_shared_state::<R>(cx) as well as let slide = use_shared_state::<isize>(cx)

#

R was good, I just missed the read()
Actually, that returns None

hollow rune
#

Do you have use shared state provider higher up in your app

sacred sentinel
sacred sentinel
#

I think I have one last question (for now);
in pub fn Slider<R: Slidable + Clone + Default>(cx: Scope<SliderProps<R>>) -> Element{...} I can set the shared_state_provider, to be of type R, which allows me to set the 'starting point' of the slide deck to R::default. This is awesome.
In my Slide component (or a next component, haven't decided) - I lose access to R. Is there a way to determine the enum in the Slide component? Or am I misreading something somewhere

#

I think the API I want at the end of the day is something like this

fn Intro(cx: Scope) -> Element {
    cx.render(rsx!(Slide {
        content: render! {
            div {
                h1 { "Hello, world!" }
                p { "This is the first slide." }
            }
        },
        next: Second,
    }))
}
#

(or Slides::Second, I think they're both simple)