mentorenwahl/frontend/src/routes/home/student_home.rs

51 lines
1 KiB
Rust
Raw Normal View History

2022-11-12 21:50:06 +00:00
use yew::prelude::*;
use crate::routes::home::student_vote;
2022-11-13 11:44:08 +00:00
pub enum Msg {
Registered,
}
2022-11-12 21:50:06 +00:00
#[derive(Properties, PartialEq)]
pub struct StudentHomeProps {
pub token: String,
pub voted: bool,
}
2022-11-13 11:44:08 +00:00
pub struct StudentHome {
voted: bool,
}
2022-11-12 21:50:06 +00:00
impl Component for StudentHome {
2022-11-13 11:44:08 +00:00
type Message = Msg;
2022-11-12 21:50:06 +00:00
type Properties = StudentHomeProps;
2022-11-13 11:44:08 +00:00
fn create(ctx: &Context<Self>) -> Self {
Self {
voted: ctx.props().voted,
}
}
fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::Registered => {
self.voted = true;
true
}
}
2022-11-12 21:50:06 +00:00
}
fn view(&self, ctx: &Context<Self>) -> Html {
html! {
2022-11-13 11:44:08 +00:00
if self.voted {
2022-11-12 21:50:06 +00:00
<p>{ "Alles in Ordnung." }</p>
} else {
2022-11-13 11:44:08 +00:00
<student_vote::StudentVote
token={ctx.props().token.to_owned()}
onvoted={ctx.link().callback(|_| Msg::Registered)}
/>
2022-11-12 21:50:06 +00:00
}
}
}
}