use graphql_client::reqwest::post_graphql; use yew::prelude::*; use crate::components; use crate::graphql; pub enum Msg { StartAssignment, StartAssignmentDone(Option>), } #[derive(Properties, PartialEq, Eq)] pub struct AssignmentsProps { pub token: String, } pub struct Assignments { errors: Option>, } impl Component for Assignments { type Message = Msg; type Properties = AssignmentsProps; fn create(_ctx: &Context) -> Self { Self { errors: None } } fn update(&mut self, ctx: &Context, msg: Self::Message) -> bool { match msg { Msg::StartAssignment => { let client = graphql::client(Some(&ctx.props().token)).unwrap(); ctx.link().send_future(async move { let response = post_graphql::( &client, graphql::URL.as_str(), graphql::mutations::start_assignment::start_assignment::Variables, ) .await .unwrap(); Msg::StartAssignmentDone(components::graphql_errors::convert(response.errors)) }); false } Msg::StartAssignmentDone(errors) => { self.errors = errors; true } } } fn view(&self, ctx: &Context) -> Html { html! {
{ "Zuweisungen" }
{ "Aktion" } { "Optionen" }
{ "Zuweisung starten" }
} } }