mirror of
https://github.com/Nutomic/ibis.git
synced 2024-12-26 01:01:22 +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]
|
||||
name = "ibis_lib"
|
||||
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)?;
|
||||
}
|
||||
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 {
|
||||
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::components::article_nav::ArticleNav;
|
||||
use crate::frontend::pages::article_resource;
|
||||
|
@ -12,41 +12,42 @@ pub fn EditArticle() -> impl IntoView {
|
|||
let article = article_resource(title.unwrap());
|
||||
|
||||
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 (edit_response, set_edit_response) = create_signal(None::<()>);
|
||||
let (edit_error, set_edit_error) = create_signal(None::<String>);
|
||||
let (wait_for_response, set_wait_for_response) = create_signal(false);
|
||||
let button_is_disabled =
|
||||
Signal::derive(move || wait_for_response.get() || summary.get().is_empty());
|
||||
let submit_action = create_action(move |(new_text, summary): &(String, String)| {
|
||||
let new_text = new_text.clone();
|
||||
let summary = summary.clone();
|
||||
async move {
|
||||
let form = EditArticleData {
|
||||
article_id: article.get().unwrap().article.id,
|
||||
new_text,
|
||||
summary,
|
||||
previous_version_id: article.get().unwrap().latest_version,
|
||||
resolve_conflict_id: None,
|
||||
};
|
||||
set_wait_for_response.update(|w| *w = true);
|
||||
let res = GlobalState::api_client().edit_article(&form).await;
|
||||
set_wait_for_response.update(|w| *w = false);
|
||||
match res {
|
||||
Ok(_res) => {
|
||||
set_edit_response.update(|v| *v = Some(()));
|
||||
set_edit_error.update(|e| *e = None);
|
||||
}
|
||||
Err(err) => {
|
||||
let msg = err.0.to_string();
|
||||
log::warn!("Unable to edit: {msg}");
|
||||
set_edit_error.update(|e| *e = Some(msg));
|
||||
let submit_action = create_action(
|
||||
move |(new_text, summary, article): &(String, String, ArticleView)| {
|
||||
let new_text = new_text.clone();
|
||||
let summary = summary.clone();
|
||||
let article = article.clone();
|
||||
async move {
|
||||
let form = EditArticleData {
|
||||
article_id: article.article.id,
|
||||
new_text,
|
||||
summary,
|
||||
previous_version_id: article.latest_version,
|
||||
resolve_conflict_id: None,
|
||||
};
|
||||
set_wait_for_response.update(|w| *w = true);
|
||||
let res = GlobalState::api_client().edit_article(&form).await;
|
||||
set_wait_for_response.update(|w| *w = false);
|
||||
match res {
|
||||
Ok(_res) => {
|
||||
set_edit_response.update(|v| *v = Some(()));
|
||||
set_edit_error.update(|e| *e = None);
|
||||
}
|
||||
Err(err) => {
|
||||
let msg = err.0.to_string();
|
||||
log::warn!("Unable to edit: {msg}");
|
||||
set_edit_error.update(|e| *e = Some(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
view! {
|
||||
<ArticleNav article=article.clone()/>
|
||||
|
@ -55,7 +56,9 @@ pub fn EditArticle() -> impl IntoView {
|
|||
fallback=move || {
|
||||
view! {
|
||||
<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! {
|
||||
<div class="item-view">
|
||||
<h1>{article.article.title.replace('_', " ")}</h1>
|
||||
|
@ -63,7 +66,7 @@ pub fn EditArticle() -> impl IntoView {
|
|||
let val = event_target_value(&ev);
|
||||
set_text.update(|p| *p = val);
|
||||
}>
|
||||
{article.article.text}
|
||||
{article.article.text.clone()}
|
||||
</textarea>
|
||||
</div>
|
||||
{move || {
|
||||
|
@ -79,11 +82,11 @@ pub fn EditArticle() -> impl IntoView {
|
|||
}/>
|
||||
<button
|
||||
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
|
||||
</button>
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
</Suspense>
|
||||
}}>
|
||||
|
|
Loading…
Reference in a new issue