diff options
author | Colin Reeder <colin@vpzom.click> | 2020-06-27 11:19:59 -0600 |
---|---|---|
committer | Colin Reeder <colin@vpzom.click> | 2020-06-27 11:19:59 -0600 |
commit | beacdedfe0d8f2810287922e5d260c35b78179f8 (patch) | |
tree | bd4ddab86a22b509b86326970b4427f0710b5eb7 | |
parent | 0402d74194a2f9df00fab82e7d4425a92c898742 (diff) |
Add community list page, link from header
-rw-r--r-- | res/main.css | 6 | ||||
-rw-r--r-- | src/routes/communities.rs | 97 | ||||
-rw-r--r-- | src/routes/mod.rs | 7 |
3 files changed, 89 insertions, 21 deletions
diff --git a/res/main.css b/res/main.css index b53079a..be66795 100644 --- a/res/main.css +++ b/res/main.css @@ -22,3 +22,9 @@ body { .actionList > * { margin-right: .5em; } + +.siteName { + font-weight: bold; + font-size: 1.2em; + margin-right: 1em; +} diff --git a/src/routes/communities.rs b/src/routes/communities.rs index 15d3f25..aeec354 100644 --- a/src/routes/communities.rs +++ b/src/routes/communities.rs @@ -1,10 +1,67 @@ use crate::routes::{ fetch_base_data, get_cookie_map, get_cookie_map_for_req, html_response, res_to_error, - with_auth, HTPage, PostItem, RespMinimalCommunityInfo, RespPostListPost, + with_auth, CommunityLink, HTPage, PostItem, RespMinimalCommunityInfo, RespPostListPost, }; use std::collections::HashMap; use std::sync::Arc; +async fn page_communities( + _: (), + ctx: Arc<crate::RouteContext>, + req: hyper::Request<hyper::Body>, +) -> Result<hyper::Response<hyper::Body>, crate::Error> { + let cookies = get_cookie_map_for_req(&req)?; + let base_data = fetch_base_data(&ctx.backend_host, &ctx.http_client, &cookies).await?; + + let api_res = res_to_error( + ctx.http_client + .request( + hyper::Request::get(format!("{}/api/unstable/communities", ctx.backend_host,)) + .body(Default::default())?, + ) + .await?, + ) + .await?; + let api_res = hyper::body::to_bytes(api_res.into_body()).await?; + let communities: Vec<RespMinimalCommunityInfo> = serde_json::from_slice(&api_res)?; + + Ok(html_response(render::html! { + <HTPage base_data={&base_data}> + <h1>{"Communities"}</h1> + <div> + <h2>{"Local"}</h2> + <ul> + { + communities.iter() + .filter(|x| x.local) + .map(|community| { + render::rsx! { + <li><CommunityLink community={&community} /></li> + } + }) + .collect::<Vec<_>>() + } + </ul> + </div> + <div> + <h2>{"Remote"}</h2> + <ul> + { + communities.iter() + .filter(|x| !x.local) + .map(|community| { + render::rsx! { + <li><CommunityLink community={&community} /></li> + } + }) + .collect::<Vec<_>>() + } + </ul> + </div> + </HTPage> + })) +} + async fn page_community( params: (i64,), ctx: Arc<crate::RouteContext>, @@ -199,22 +256,24 @@ async fn handler_communities_new_post_submit( } pub fn route_communities() -> crate::RouteNode<()> { - crate::RouteNode::new().with_child_parse::<i64, _>( - crate::RouteNode::new() - .with_handler_async("GET", page_community) - .with_child( - "follow", - crate::RouteNode::new().with_handler_async("POST", handler_community_follow), - ) - .with_child( - "new_post", - crate::RouteNode::new() - .with_handler_async("GET", page_community_new_post) - .with_child( - "submit", - crate::RouteNode::new() - .with_handler_async("POST", handler_communities_new_post_submit), - ), - ), - ) + crate::RouteNode::new() + .with_handler_async("GET", page_communities) + .with_child_parse::<i64, _>( + crate::RouteNode::new() + .with_handler_async("GET", page_community) + .with_child( + "follow", + crate::RouteNode::new().with_handler_async("POST", handler_community_follow), + ) + .with_child( + "new_post", + crate::RouteNode::new() + .with_handler_async("GET", page_community_new_post) + .with_child( + "submit", + crate::RouteNode::new() + .with_handler_async("POST", handler_communities_new_post_submit), + ), + ), + ) } diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 0958813..082a616 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -191,8 +191,11 @@ fn HTPage<'base_data, Children: render::Render>( </head> <body> <header class={"mainHeader"}> - <div class={"left"}><a href={"/"}>{"lotide"}</a></div> - <div class={"right"}> + <div class={"left actionList"}> + <a href={"/"} class={"siteName"}>{"lotide"}</a> + <a href={"/communities"}>{"Communities"}</a> + </div> + <div class={"right actionList"}> { match base_data.login { Some(_) => None, |