diff --git a/app/src/user_table.rs b/app/src/user_table.rs index c1b9207..1fc4b90 100644 --- a/app/src/user_table.rs +++ b/app/src/user_table.rs @@ -16,9 +16,11 @@ pub struct ListUsersQuery; use list_users_query::{RequestFilter, ResponseData}; +type User = list_users_query::ListUsersQueryUsers; + pub struct UserTable { link: ComponentLink, - users: Option>>, + users: Option>>, // Used to keep the request alive long enough. _task: Option, } @@ -75,39 +77,37 @@ impl Component for UserTable { } fn view(&self) -> Html { + let make_user_row = |user: &User| { + html! { + + {&user.id} + {&user.email} + {&user.display_name.as_ref().unwrap_or(&String::new())} + {&user.first_name.as_ref().unwrap_or(&String::new())} + {&user.last_name.as_ref().unwrap_or(&String::new())} + {&user.creation_date.with_timezone(&chrono::Local)} + + } + }; + let make_table = |users: &Vec| { + html! { + + + + + + + + + + {users.iter().map(make_user_row).collect::>()} +
{"User ID"}{"Email"}{"Display name"}{"First name"}{"Last name"}{"Creation date"}
+ } + }; match &self.users { None => html! {{"Loading..."}}, Some(Err(e)) => html! {
{"Error: "}{e.to_string()}
}, - Some(Ok(users)) => { - let table_content: Vec<_> = users - .iter() - .map(|u| { - html! { - - {&u.id} - {&u.email} - {&u.display_name.as_ref().unwrap_or(&String::new())} - {&u.first_name.as_ref().unwrap_or(&String::new())} - {&u.last_name.as_ref().unwrap_or(&String::new())} - {&u.creation_date.with_timezone(&chrono::Local)} - - } - }) - .collect(); - html! { - - - - - - - - - - {table_content} -
{"User ID"}{"Email"}{"Display name"}{"First name"}{"Last name"}{"Creation date"}
- } - } + Some(Ok(users)) => make_table(users), } } }