Basic frontend rendering

main
Ashelyn Dawn 5 months ago committed by Ashelyn Rose
parent 014c551b12
commit e527c456b0
No known key found for this signature in database
GPG Key ID: D1980B8C6F349BC1

838
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -14,3 +14,5 @@ time = { version = "0.3.34" }
uuid = { version = "1.7.0", features = ["v4", "serde"] } uuid = { version = "1.7.0", features = ["v4", "serde"] }
serde_json = "1.0.114" serde_json = "1.0.114"
joinrs = { path = "../joinrs/joinrs" } joinrs = { path = "../joinrs/joinrs" }
leptos = { version = "0.6.11", features = ["ssr"] }
regex = "1.10.4"

@ -6,6 +6,8 @@ use dotenv::dotenv;
mod db; mod db;
mod routes; mod routes;
mod ui;
mod util;
#[rocket::main] #[rocket::main]
async fn main() { async fn main() {

@ -1,11 +1,17 @@
use rocket::{http::Status, State}; use rocket::{http::Status, State};
use crate::db::DB; use crate::db::DB;
use crate::ui::layouts::index::Index;
use crate::util::render_bare;
#[get("/")] #[get("/")]
pub async fn site_index(db : &State<DB>) -> Result<String, (Status, String)> { pub async fn site_index(db : &State<DB>) -> Result<String, (Status, String)> {
let site = db.get_site_data().await.unwrap(); let site = db.get_site_data().await.unwrap();
let response = serde_json::to_string(&site).unwrap();
let response = render_bare(leptos::view! {
<Index site={site}/>
});
Ok(response) Ok(response)
} }

@ -0,0 +1,10 @@
use leptos::{component, view, IntoView};
use crate::db::objects::Site;
#[component]
pub fn Header(site: Site) -> impl IntoView {
view!(
<h1>{site.title}</h1>
)
}

@ -0,0 +1 @@
pub mod header;

@ -0,0 +1,11 @@
use leptos::{component, view, IntoView};
use crate::{db::objects::Site, ui::components::header::Header};
#[component]
pub fn Index(site: Site) -> impl IntoView {
view!(
<>
<Header site={site}/>
</>
)
}

@ -0,0 +1 @@
pub mod index;

@ -0,0 +1,2 @@
pub mod components;
pub mod layouts;

@ -0,0 +1,10 @@
pub fn render_bare<N>(view: N) -> String
where N: leptos::IntoView + 'static {
let render_result = leptos::ssr::render_to_string(|| {view});
let html_comment: regex::Regex = regex::Regex::new(r"<!--.*-->").unwrap();
let leptos_string = render_result.to_string();
let bare_string = html_comment.replace_all(&leptos_string, "");
bare_string.to_string()
}
Loading…
Cancel
Save