Skip to main content

header_action_button

Function header_action_button 

Source
pub fn header_action_button<'a, P: Page, A: HeaderAction>(
    cx: &'a Cx,
    input: &A::Input,
) -> BoxView<'a>
Expand description

The button of P’s action A, posting input instead of asking for it, to place in the page’s content: a plan card’s Subscribe, carrying the plan and the interval it offers. P declares A with PageDef::action, which keeps it out of the header, or with PageDef::header_action.

#[derive(FormInput)]
struct Plan {
    name: String,
}

struct Subscribe;

impl HeaderAction for Subscribe {
    type Input = Plan;
    const NAME: &'static str = "subscribe";
}

struct PlansPage;

impl Page for PlansPage {
    fn declare() -> PageDef {
        PageDef::new().action::<Subscribe>()
    }

    async fn render(cx: &Cx) -> Result<impl View> {
        let plan = Plan { name: "pro".to_string() };
        Ok(view! {
            tablo_ui::page(
                tablo_ui::page_content(
                    (tablo_core::header_action_button::<Self, Subscribe>(cx, &plan))
                )
            )
        })
    }
}

The POST runs as the header bar’s would: input is parsed and checked again, and a refused one lands on the action’s input page. A confirms first when it sets confirm. It renders nothing to a request the page or A’s can_run refuses, when P does not declare A, and when input holds a repeater’s rows, which no hidden field carries.