moved timeline from own page to index

This commit is contained in:
emilis 2022-12-19 21:56:51 +00:00
parent be7c415980
commit f4aae98656
7 changed files with 180 additions and 150 deletions

View File

@ -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<Server>,
cookies: Cookies,
) -> Result<impl IntoResponse, ServerError> {
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<Server>,
) -> Result<impl IntoResponse, ServerError> {
let claims = srv.get_auth(cookies)?;
Ok((
StatusCode::OK,
response::Html(srv.hb.render("timeline", &())?),
))
}
async fn create_user(
Extension(srv): Extension<Server>,
Form(body): Form<CreateProfileRequest>,

View File

@ -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<Note>,
}
#[derive(Debug, Clone, Serialize)]
struct Note {
pub profile: Box<Profile>,
pub content: Option<String>,
}
impl Note {
fn new(profile: Box<Profile>, content: Option<String>) -> 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,

View File

@ -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"),

View File

@ -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);
}

View File

@ -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);
}

View File

@ -9,7 +9,28 @@
<body>
{{> (lookup this "nav_type") }}
<h1>hi {{obj.username}}</h1>
<div class="main" id="timeline-box">
{{#if obj.show_postbox}}
<div id="postbox">
<textarea id="post-content" placeholder="im tosti"></textarea>
<button>send</button>
</div>
{{/if}}
<div id="timeline">
{{#each obj.notes}}
<div class="note">
<img class="avatar" src="{{this.profile.avatar_url}}" alt="example" />
<div class="content">
<div class="user-info">
<p class="display-name">{{this.profile.display_name}}</p>
<p class="username">{{this.profile.username}}</p>
</div>
<p class="post-text">{{this.content}}</p>
</div>
</div>
{{/each}}
</div>
</div>
</body>
</html>

View File

@ -1,53 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>timeline - flabk</title>
<link rel="stylesheet" href="/static/style/main.css">
<link rel="stylesheet" href="/static/style/timeline.css">
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
</head>
<body>
{{> LoggedIn }}
<div class="main" id="timeline-box">
<div id="postbox">
<textarea id="post-content" placeholder="im tosti"></textarea>
<button>send</button>
</div>
<div id="timeline">
<div class="note">
<img class="avatar" src="/favicon.svg" alt="example" />
<div class="content">
<div class="user-info">
<p class="display-name">Big Duck</p>
<p class="username">@emilis@flab.k</p>
</div>
<p class="post-text">this is gay :puffrage:</p>
</div>
</div>
<div class="note">
<img class="avatar" src="/favicon.svg" alt="example" />
<div class="content">
<div class="user-info">
<p class="display-name">Big Duck</p>
<p class="username">@emilis@flab.k</p>
</div>
<p class="post-text">im posting agen</p>
</div>
</div>
<div class="note">
<img class="avatar" src="/favicon.svg" alt="example" />
<div class="content">
<div class="user-info">
<p class="display-name">Big Duck</p>
<p class="username">@emilis@flab.k</p>
</div>
<p class="post-text">just landed in piss</p>
</div>
</div>
</div>
</div>
</body>
</html>