Skip to content

Commit

Permalink
fix #33: use editor state to tell if delete button should be rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
PetoMPP committed Dec 26, 2023
1 parent a18eeb0 commit 95f89cd
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/components/organisms/editor/atoms/delete_button.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
api::client::ApiClient,
api::client::{ApiClient, RequestError},
async_event,
components::atoms::modal::{show_modal_callback, Buttons, ModalButton, ModalData, ModalStore},
data::{
Expand All @@ -21,12 +21,21 @@ pub fn delete_button(props: &EditorProps) -> Html {
let (locales_store, _) = use_store::<LocalesStore>();
let (_, modal_dispatch) = use_store::<ModalStore>();
let navigator = use_navigator().unwrap();
let err = use_state(|| None);
let err = use_state(|| Option::<RequestError>::None);
if let Some(e) = &*err {
if let Err(redirect) = e.handle_failed_auth(session_dispatch) {
return redirect;
}
gloo::dialogs::alert(e.to_string().as_str());
}
let (Some(resid), Some(lang)) = (&props.resid, &props.lang) else {
return html! {};
};
if let EditorState::Loading = &props.state {
return html! {};
match &props.state {
EditorState::Loading
| EditorState::Ok(None)
| EditorState::Ok(Some((Some(true), _, _))) => return Html::default(),
_ => {}
}
let onstatechange = &props.onstatechanged;
let token = session_store.token.clone().unwrap_or_default();
Expand Down Expand Up @@ -54,12 +63,6 @@ pub fn delete_button(props: &EditorProps) -> Html {
},
modal_dispatch.clone(),
);
if let Some(e) = &*err {
if let Err(redirect) = e.handle_failed_auth(session_dispatch) {
return redirect;
}
gloo::dialogs::alert(e.to_string().as_str());
}
html! {
<button {onclick} class={"flex btn btn-error"}>{locales_store.get(TK::Delete)}</button>
}
Expand Down

0 comments on commit 95f89cd

Please sign in to comment.