1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-28 17:21:10 +00:00

Also add preview for creating article

This commit is contained in:
Felix Ableitner 2024-10-28 11:28:16 +01:00
parent ef7d29d2ee
commit b4e54c914d

View file

@ -1,4 +1,7 @@
use crate::{common::CreateArticleForm, frontend::app::GlobalState};
use crate::{
common::CreateArticleForm,
frontend::{app::GlobalState, markdown::render_markdown},
};
use html::Textarea;
use leptos::*;
use leptos_router::Redirect;
@ -14,6 +17,8 @@ pub fn CreateArticle() -> impl IntoView {
trigger_resize: _,
} = use_textarea_autosize(textarea);
let (summary, set_summary) = create_signal(String::new());
let (show_preview, set_show_preview) = create_signal(false);
let (preview, set_preview) = create_signal(String::new());
let (create_response, set_create_response) = create_signal(None::<()>);
let (create_error, set_create_error) = create_signal(None::<String>);
let (wait_for_response, set_wait_for_response) = create_signal(false);
@ -67,9 +72,19 @@ pub fn CreateArticle() -> impl IntoView {
<textarea
value=content
placeholder="Article text..."
on:input=move |evt| set_content.set(event_target_value(&evt))
on:input=move |evt| {
let val = event_target_value(&evt);
set_preview.set(render_markdown(&val));
set_content.set(val);
}
node_ref=textarea
></textarea>
<button on:click=move |_| {
set_show_preview.update(|s| *s = !*s)
}>Preview</button>
<Show when=move || { show_preview.get() }>
<div id="preview" inner_html=move || preview.get()></div>
</Show>
<div>
<a href="https://commonmark.org/help/" target="blank_">
Markdown