app: Render recipe as mardown
This commit is contained in:
parent
7c7eee04b2
commit
4ecc06e01b
4 changed files with 213 additions and 9 deletions
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
bootstrap::{bs, FormModal, ModalBody, ModalFooter, ModalToggleButton, TitledModal},
|
||||
ingredients::do_add_ingredient,
|
||||
recipe::IngredientSelect,
|
||||
use_error, use_trimmed_context, ErrorView,
|
||||
use_error, use_trimmed_context, ErrorView,
|
||||
};
|
||||
|
||||
use super::RecipeIngredient;
|
||||
|
|
@ -341,12 +341,15 @@ pub fn RecipeCreator(cx: Scope) -> Element {
|
|||
}
|
||||
div {
|
||||
h2 { "Steps" }
|
||||
div {class: "text-start",
|
||||
textarea {
|
||||
class: "form-control",
|
||||
id: "steps-area",
|
||||
value: "{steps}",
|
||||
rows: "10",
|
||||
oninput: move |e| steps.set(e.value.clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
hr {}
|
||||
ModalToggleButton { class: "btn btn-lg btn-primary", modal_id: "newRcpModal", "Create Recipe" }
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use api::{
|
|||
};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_router::{use_route, use_router};
|
||||
use pulldown_cmark::{Parser, html};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -616,6 +617,15 @@ fn RecipeViewer(cx: Scope<RecipeViewerProps>) -> Element {
|
|||
}
|
||||
};
|
||||
|
||||
let steps_rendered = use_memo(cx, &cx.props.info.steps, |steps| {
|
||||
let parser = Parser::new(&steps);
|
||||
|
||||
let mut html_output = String::new();
|
||||
html::push_html(&mut html_output, parser);
|
||||
|
||||
ammonia::clean(&html_output)
|
||||
});
|
||||
|
||||
cx.render(rsx! {
|
||||
h1 {
|
||||
"{cx.props.info.name}"
|
||||
|
|
@ -690,10 +700,8 @@ fn RecipeViewer(cx: Scope<RecipeViewerProps>) -> Element {
|
|||
hr {}
|
||||
div { class: "text-start",
|
||||
h2 { "Steps" }
|
||||
ul { class: "list-group list-group-flush",
|
||||
for line in cx.props.info.steps.split('\n') {
|
||||
li { class: "list-group-item", line }
|
||||
}
|
||||
div {
|
||||
dangerous_inner_html: "{steps_rendered}"
|
||||
}
|
||||
EditSteps {
|
||||
recipe: cx.props.id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue