mirror of
https://github.com/Nutomic/ibis.git
synced 2024-12-25 13:31:22 +00:00
Also add preview for creating article
This commit is contained in:
parent
ef7d29d2ee
commit
b4e54c914d
1 changed files with 17 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue