Refactor
This commit is contained in:
parent
c2ec1d9504
commit
bd5c46d44d
1 changed files with 22 additions and 22 deletions
|
@ -184,29 +184,29 @@ pub fn PostElement() -> impl IntoView {
|
|||
|
||||
let post = create_resource(|| (), move |_| get_post(slug()));
|
||||
|
||||
let post_view = move || {
|
||||
let render_draft_notice = |post: &Post| -> Option<View> {
|
||||
if post.metadata.draft {
|
||||
return Some(view! {
|
||||
<div class="bg-warning text-on_warning dark:bg-dark_warning dark:text-dart_on_warning rounded-md p-5 mb-5">
|
||||
r#"
|
||||
L'article est en cours d'écriture. La formulation peut ne pas être exacte et les phrases peuvent contenir des fautes.
|
||||
"#
|
||||
</div>
|
||||
}.into_view());
|
||||
}
|
||||
None
|
||||
};
|
||||
|
||||
let render_post_view = move || {
|
||||
post.and_then(|post| {
|
||||
let draft_notice = render_draft_notice(&post);
|
||||
view! {
|
||||
<>
|
||||
{
|
||||
if post.metadata.draft {
|
||||
Some(view!{
|
||||
<div class="bg-warning text-on_warning dark:bg-dark_warning dark:text-dart_on_warning rounded-md p-5 mb-5">
|
||||
r#"
|
||||
L'article est en cours d'écriture. La formulation peut ne pas être exacte et les phrases peuvent contenir des fautes.
|
||||
"#
|
||||
</div>
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
<PostHeader metadata=post.metadata.clone() full_element=true />
|
||||
|
||||
<div inner_html={post.content.clone()}></div>
|
||||
</>
|
||||
}
|
||||
<>
|
||||
{draft_notice}
|
||||
<PostHeader metadata=post.metadata.clone() full_element=true />
|
||||
<div inner_html={post.content.clone()}></div>
|
||||
</>
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
|
@ -214,7 +214,7 @@ pub fn PostElement() -> impl IntoView {
|
|||
<Suspense fallback=move || view! { <Loading title="Chargement du post...".to_string() /> }>
|
||||
<Nav/>
|
||||
<main class="post">
|
||||
{post_view}
|
||||
{render_post_view}
|
||||
<script>load();</script>
|
||||
</main>
|
||||
</Suspense>
|
||||
|
|
Loading…
Reference in a new issue