mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-29 04:11:09 +00:00
bugfix
This commit is contained in:
parent
8305680fda
commit
1158cb18eb
3 changed files with 40 additions and 33 deletions
|
@ -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
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,41 +12,42 @@ 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(
|
||||||
let new_text = new_text.clone();
|
move |(new_text, summary, article): &(String, String, ArticleView)| {
|
||||||
let summary = summary.clone();
|
let new_text = new_text.clone();
|
||||||
async move {
|
let summary = summary.clone();
|
||||||
let form = EditArticleData {
|
let article = article.clone();
|
||||||
article_id: article.get().unwrap().article.id,
|
async move {
|
||||||
new_text,
|
let form = EditArticleData {
|
||||||
summary,
|
article_id: article.article.id,
|
||||||
previous_version_id: article.get().unwrap().latest_version,
|
new_text,
|
||||||
resolve_conflict_id: None,
|
summary,
|
||||||
};
|
previous_version_id: article.latest_version,
|
||||||
set_wait_for_response.update(|w| *w = true);
|
resolve_conflict_id: None,
|
||||||
let res = GlobalState::api_client().edit_article(&form).await;
|
};
|
||||||
set_wait_for_response.update(|w| *w = false);
|
set_wait_for_response.update(|w| *w = true);
|
||||||
match res {
|
let res = GlobalState::api_client().edit_article(&form).await;
|
||||||
Ok(_res) => {
|
set_wait_for_response.update(|w| *w = false);
|
||||||
set_edit_response.update(|v| *v = Some(()));
|
match res {
|
||||||
set_edit_error.update(|e| *e = None);
|
Ok(_res) => {
|
||||||
}
|
set_edit_response.update(|v| *v = Some(()));
|
||||||
Err(err) => {
|
set_edit_error.update(|e| *e = None);
|
||||||
let msg = err.0.to_string();
|
}
|
||||||
log::warn!("Unable to edit: {msg}");
|
Err(err) => {
|
||||||
set_edit_error.update(|e| *e = Some(msg));
|
let msg = err.0.to_string();
|
||||||
|
log::warn!("Unable to edit: {msg}");
|
||||||
|
set_edit_error.update(|e| *e = Some(msg));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
);
|
||||||
|
|
||||||
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>
|
||||||
}}>
|
}}>
|
||||||
|
|
Loading…
Reference in a new issue