webcomment/webui/src/lib.rs
2023-05-02 18:03:21 +02:00

90 lines
1.8 KiB
Rust

mod api;
mod components;
mod types;
use gloo::console;
use js_sys::Date;
use parking_lot::RwLock;
use wasm_bindgen::prelude::*;
use webcomment_common::types::*;
use yew::{html, Component, Context, Html, Properties};
use crate::{components::*, types::*};
pub enum Msg {
Increment,
Decrement,
}
#[derive(Properties, PartialEq)]
pub struct AppProps {
root_id: String,
}
impl Default for AppProps {
fn default() -> Self {
Self {
root_id: String::from("comments"),
}
}
}
pub struct App {
value: i64,
}
impl Component for App {
type Message = Msg;
type Properties = AppProps;
fn create(_ctx: &Context<Self>) -> Self {
Self { value: 0 }
}
fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::Increment => {
self.value += 1;
console::log!("plus one"); // Will output a string to the browser console
true // Return true to cause the displayed change to update
}
Msg::Decrement => {
self.value -= 1;
console::log!("minus one");
true
}
}
}
fn view(&self, ctx: &Context<Self>) -> Html {
let props = ctx.props();
let comment_props = CommentProps {
root_id: String::from("comments"),
comment: FullComment {
author: String::from("Toto"),
email: Some(String::from("toto@fai.tld")),
id: CommentId::new(),
last_edit_time: Some(123),
post_time: 42,
text: String::from("Bonjour"),
},
};
html! {
<div id={ props.root_id.clone() }>
<CommentComponent ..comment_props />
</div>
}
}
}
#[wasm_bindgen(start)]
async fn main_js() {
/*let api = api::Api {
inner: RwLock::new(api::ApiInner { admin_psw: None, comments: Default::default(), url: "http://127.0.0.1:31720".into() })
};
api.get_comments_by_topic("test".into()).await;*/
yew::Renderer::<App>::new().render();
}
fn main() {}