From f4aae9865659868110843defc882ebaf373de993 Mon Sep 17 00:00:00 2001 From: emilis Date: Mon, 19 Dec 2022 21:56:51 +0000 Subject: [PATCH] moved timeline from own page to index --- flabk/src/servek/html.rs | 63 +++++++++++++------ flabk/src/servek/mod.rs | 47 ++++++++++++-- flabk/src/servek/servek.rs | 5 -- flabk/static/style/main.css | 70 +++++++++++++++++++++ flabk/static/style/timeline.css | 69 -------------------- flabk/templates/html/index.html | 23 ++++++- flabk/templates/html/loggedin/timeline.html | 53 ---------------- 7 files changed, 180 insertions(+), 150 deletions(-) delete mode 100644 flabk/static/style/timeline.css delete mode 100644 flabk/templates/html/loggedin/timeline.html diff --git a/flabk/src/servek/html.rs b/flabk/src/servek/html.rs index 9fd1a0a..b60105c 100644 --- a/flabk/src/servek/html.rs +++ b/flabk/src/servek/html.rs @@ -14,7 +14,8 @@ use crate::svc::auth::{AuthError, Claims}; use super::{ servek::{Server, ServerError}, - CreateProfileRequest, LoginRequest, NavType, Notification, Redirect, WithNav, + CreateProfileRequest, LoginRequest, NavType, Note, Notification, Profile, Redirect, Timeline, + WithNav, }; use rust_embed::RustEmbed; @@ -38,7 +39,6 @@ impl Server { ) .route("/@/:username", routing::get(Self::profile)) .route("/static/*file", routing::get(Self::static_handler)) - .route("/!", routing::get(Self::timeline)) .fallback(routing::get(Self::handler_404)) } @@ -84,10 +84,49 @@ impl Server { Extension(srv): Extension, cookies: Cookies, ) -> Result { - Ok(( - StatusCode::OK, - response::Html(srv.hb.render("index", &srv.from_cookies(cookies)?)?), - )) + // TODO: show actual posts, these are hardcoded currently to check + // out how they look + let profile1 = Box::new(Profile { + username: "@emilis@puff.place".to_string(), + display_name: "dusty rusty".to_string(), + avatar_url: "https://puff.place/files/thumbnail-501ec5ba-37d6-4163-8e8d-3478a689660d" + .to_string(), + }); + let profile2 = Box::new(Profile::new("@emilk@another.place".to_string())); + let note1 = Note::new(profile1.clone(), Some("hey there goods".to_string())); + let note2 = Note::new( + profile2, + Some("@emilis@puff.place u dont got shit".to_string()), + ); + let note3 = Note::new(profile1, Some("bithces :".to_string())); + + match srv.get_auth(cookies) { + Ok(claims) => Ok(( + StatusCode::OK, + response::Html(srv.hb.render( + "index", + &WithNav::new( + Timeline { + show_postbox: true, + notes: vec![note1, note2, note3], + }, + NavType::LoggedIn, + ), + )?), + ) + .into_response()), + Err(e) => match e { + ServerError::NotLoggedIn => Ok(( + StatusCode::OK, + response::Html( + srv.hb + .render("index", &WithNav::new((), NavType::LoggedOut))?, + ), + ) + .into_response()), + _ => Err(e), + }, + } } async fn favicon() -> impl IntoResponse { @@ -217,18 +256,6 @@ impl Server { )) } - async fn timeline( - cookies: Cookies, - Extension(srv): Extension, - ) -> Result { - let claims = srv.get_auth(cookies)?; - - Ok(( - StatusCode::OK, - response::Html(srv.hb.render("timeline", &())?), - )) - } - async fn create_user( Extension(srv): Extension, Form(body): Form, diff --git a/flabk/src/servek/mod.rs b/flabk/src/servek/mod.rs index e005d5a..7b0c52f 100644 --- a/flabk/src/servek/mod.rs +++ b/flabk/src/servek/mod.rs @@ -2,14 +2,53 @@ use axum::response::{Html, IntoResponse}; use serde::{Deserialize, Serialize}; use tower_cookies::{Cookie, Cookies}; -use crate::svc::{ - auth::{Auth, AuthError, Claims}, - profiles::User, -}; +use crate::svc::auth::{AuthError, Claims}; mod html; pub mod servek; +#[derive(Debug, Clone, Serialize)] +struct Timeline { + pub show_postbox: bool, + pub notes: Vec, +} + +#[derive(Debug, Clone, Serialize)] +struct Note { + pub profile: Box, + pub content: Option, +} + +impl Note { + fn new(profile: Box, content: Option) -> Self { + Self { profile, content } + } +} + +#[derive(Debug, Clone, Serialize)] +struct Profile { + pub display_name: String, + pub username: String, + pub avatar_url: String, +} + +impl Profile { + fn new(username: String) -> Self { + let display_name = username + .strip_prefix('@') + .unwrap() + .split_once('@') + .unwrap() + .0 + .to_string(); + Profile { + display_name, + username, + avatar_url: "/favicon.svg".to_string(), + } + } +} + #[derive(Debug, Clone, Serialize)] struct Notification { pub message: String, diff --git a/flabk/src/servek/servek.rs b/flabk/src/servek/servek.rs index fa01ac7..0ba4330 100644 --- a/flabk/src/servek/servek.rs +++ b/flabk/src/servek/servek.rs @@ -43,11 +43,6 @@ impl Server { .expect("index"); hb.register_template_string("err404", include_str!("../../templates/html/404.html")) .expect("err404"); - hb.register_template_string( - "timeline", - include_str!("../../templates/html/loggedin/timeline.html"), - ) - .expect("timeline"); hb.register_partial( "LoggedOut", include_str!("../../templates/html/nav-loggedout.html"), diff --git a/flabk/static/style/main.css b/flabk/static/style/main.css index a7ca153..d6b8010 100644 --- a/flabk/static/style/main.css +++ b/flabk/static/style/main.css @@ -170,3 +170,73 @@ button { border-style: initial; font-size: large; } + +#postbox { + /* border: 3px solid rebeccapurple; */ + /* padding: 5px; */ + margin: 0 0 30px 0; + height: fit-content; + display: flex; + /* text-align: left; */ +} + +#timeline { + margin: 0; + padding: 0; +} + +#timeline li { + display: grid; + list-style-type: none; + width: 85vw; +} + +#post-content { + color: rgb(204, 179, 230); + background-color: rebeccapurple; + border-width: 0px; + height: 60px; + width: 85vw; +} + +.note { + display: flex; +} + +.content { + display: inline-flex; + flex-direction: column; +} + +div>p { + font-size: small; + margin-left: 2px; + margin-right: 2px; +} + +.display-name { + font-weight: bold; +} + +.username { + color: rgba(102, 51, 153, 0.5); +} + +.user-info { + display: inline-flex; + margin-top: 0px; +} + +#timeline-box { + color: rgb(204, 179, 230); + display: flex; + flex-direction: column; +} + +.note:nth-child(even) { + background: rgba(102, 51, 153, 0.25); +} + +.note:nth-child(odd) { + background: rgba(102, 51, 153, 0.125); +} diff --git a/flabk/static/style/timeline.css b/flabk/static/style/timeline.css deleted file mode 100644 index fd52ffc..0000000 --- a/flabk/static/style/timeline.css +++ /dev/null @@ -1,69 +0,0 @@ -#postbox { - /* border: 3px solid rebeccapurple; */ - /* padding: 5px; */ - margin: 0 0 30px 0; - height: fit-content; - display: flex; - /* text-align: left; */ -} - -#timeline { - margin: 0; - padding: 0; -} - -#timeline li { - display: grid; - list-style-type: none; - width: 85vw; -} - -#post-content { - color: rgb(204, 179, 230); - background-color: rebeccapurple; - border-width: 0px; - height: 60px; - width: 85vw; -} - -.note { - display: flex; -} - -.content { - display: inline-flex; - flex-direction: column; -} - -div>p { - font-size: small; - margin-left: 2px; - margin-right: 2px; -} - -.display-name { - font-weight: bold; -} - -.username { - color: rgba(102, 51, 153, 0.5); -} - -.user-info { - display: inline-flex; - margin-top: 0px; -} - -#timeline-box { - color: rgb(204, 179, 230); - display: flex; - flex-direction: column; -} - -.note:nth-child(even) { - background: rgba(102, 51, 153, 0.25); -} - -.note:nth-child(odd) { - background: rgba(102, 51, 153, 0.125); -} diff --git a/flabk/templates/html/index.html b/flabk/templates/html/index.html index 0b59626..6fef467 100644 --- a/flabk/templates/html/index.html +++ b/flabk/templates/html/index.html @@ -9,7 +9,28 @@ {{> (lookup this "nav_type") }} -

hi {{obj.username}}

+
+ {{#if obj.show_postbox}} +
+ + +
+ {{/if}} +
+ {{#each obj.notes}} +
+ example +
+ +

{{this.content}}

+
+
+ {{/each}} +
+
diff --git a/flabk/templates/html/loggedin/timeline.html b/flabk/templates/html/loggedin/timeline.html deleted file mode 100644 index 5316276..0000000 --- a/flabk/templates/html/loggedin/timeline.html +++ /dev/null @@ -1,53 +0,0 @@ - - - - - timeline - flabk - - - - - - - {{> LoggedIn }} -
-
- - -
-
-
- example -
- -

this is gay :puffrage:

-
-
-
- example -
- -

im posting agen

-
-
-
- example -
- -

just landed in piss

-
-
-
-
- - -