1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-25 13:21:10 +00:00
This commit is contained in:
Felix Ableitner 2024-01-25 16:12:30 +01:00
parent 8305680fda
commit 1158cb18eb
3 changed files with 40 additions and 33 deletions

View file

@ -79,3 +79,8 @@ site-addr = "127.0.0.1:8131"
[lib] [lib]
name = "ibis_lib" name = "ibis_lib"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib"]
# This profile significantly speeds up build time. If debug info is needed you can comment the line
# out temporarily, but make sure to leave this in the main branch.
[profile.dev]
debug = 0

View file

@ -71,7 +71,6 @@ pub(in crate::backend::api) async fn edit_article(
DbConflict::delete(resolve_conflict_id, &data.db_connection)?; DbConflict::delete(resolve_conflict_id, &data.db_connection)?;
} }
let original_article = DbArticle::read_view(edit_form.article_id, &data.db_connection)?; let original_article = DbArticle::read_view(edit_form.article_id, &data.db_connection)?;
dbg!(&edit_form.new_text, &original_article.article.text);
if edit_form.new_text == original_article.article.text { if edit_form.new_text == original_article.article.text {
return Err(anyhow!("Edit contains no changes").into()); return Err(anyhow!("Edit contains no changes").into());
} }

View file

@ -1,4 +1,4 @@
use crate::common::EditArticleData; use crate::common::{ArticleView, EditArticleData};
use crate::frontend::app::GlobalState; use crate::frontend::app::GlobalState;
use crate::frontend::components::article_nav::ArticleNav; use crate::frontend::components::article_nav::ArticleNav;
use crate::frontend::pages::article_resource; use crate::frontend::pages::article_resource;
@ -12,23 +12,23 @@ pub fn EditArticle() -> impl IntoView {
let article = article_resource(title.unwrap()); let article = article_resource(title.unwrap());
let (text, set_text) = create_signal(String::new()); let (text, set_text) = create_signal(String::new());
// TODO: set initial text, otherwise submit with no changes results in empty text
//article.with(|article| set_text.update(article.as_ref().unwrap().article.text.clone()));
let (summary, set_summary) = create_signal(String::new()); let (summary, set_summary) = create_signal(String::new());
let (edit_response, set_edit_response) = create_signal(None::<()>); let (edit_response, set_edit_response) = create_signal(None::<()>);
let (edit_error, set_edit_error) = create_signal(None::<String>); let (edit_error, set_edit_error) = create_signal(None::<String>);
let (wait_for_response, set_wait_for_response) = create_signal(false); let (wait_for_response, set_wait_for_response) = create_signal(false);
let button_is_disabled = let button_is_disabled =
Signal::derive(move || wait_for_response.get() || summary.get().is_empty()); Signal::derive(move || wait_for_response.get() || summary.get().is_empty());
let submit_action = create_action(move |(new_text, summary): &(String, String)| { let submit_action = create_action(
move |(new_text, summary, article): &(String, String, ArticleView)| {
let new_text = new_text.clone(); let new_text = new_text.clone();
let summary = summary.clone(); let summary = summary.clone();
let article = article.clone();
async move { async move {
let form = EditArticleData { let form = EditArticleData {
article_id: article.get().unwrap().article.id, article_id: article.article.id,
new_text, new_text,
summary, summary,
previous_version_id: article.get().unwrap().latest_version, previous_version_id: article.latest_version,
resolve_conflict_id: None, resolve_conflict_id: None,
}; };
set_wait_for_response.update(|w| *w = true); set_wait_for_response.update(|w| *w = true);
@ -46,7 +46,8 @@ pub fn EditArticle() -> impl IntoView {
} }
} }
} }
}); },
);
view! { view! {
<ArticleNav article=article.clone()/> <ArticleNav article=article.clone()/>
@ -55,7 +56,9 @@ pub fn EditArticle() -> impl IntoView {
fallback=move || { fallback=move || {
view! { view! {
<Suspense fallback=|| view! { "Loading..." }> { <Suspense fallback=|| view! { "Loading..." }> {
move || article.get().map(|article| move || article.get().map(|article| {
// set initial text, otherwise submit with no changes results in empty text
set_text.set(article.article.text.clone());
view! { view! {
<div class="item-view"> <div class="item-view">
<h1>{article.article.title.replace('_', " ")}</h1> <h1>{article.article.title.replace('_', " ")}</h1>
@ -63,7 +66,7 @@ pub fn EditArticle() -> impl IntoView {
let val = event_target_value(&ev); let val = event_target_value(&ev);
set_text.update(|p| *p = val); set_text.update(|p| *p = val);
}> }>
{article.article.text} {article.article.text.clone()}
</textarea> </textarea>
</div> </div>
{move || { {move || {
@ -79,11 +82,11 @@ pub fn EditArticle() -> impl IntoView {
}/> }/>
<button <button
prop:disabled=move || button_is_disabled.get() prop:disabled=move || button_is_disabled.get()
on:click=move |_| submit_action.dispatch((text.get(), summary.get()))> on:click=move |_| submit_action.dispatch((text.get(), summary.get(), article.clone()))>
Submit Submit
</button> </button>
} }
) })
} }
</Suspense> </Suspense>
}}> }}>