From a4e95330c36963954a47ddfa49c81aa80268b792 Mon Sep 17 00:00:00 2001
From: Brendan O'Connell
Date: Tue, 31 Dec 2024 11:15:40 +0100
Subject: [PATCH] Callbacks in progress
---
thoth-app/src/component/work.rs | 36 +++++++++++------
.../src/component/work_status_dialogue.rs | 40 ++++++++++++++++++-
2 files changed, 61 insertions(+), 15 deletions(-)
diff --git a/thoth-app/src/component/work.rs b/thoth-app/src/component/work.rs
index d8d26cd84..b6ed72001 100644
--- a/thoth-app/src/component/work.rs
+++ b/thoth-app/src/component/work.rs
@@ -558,10 +558,14 @@ impl Component for WorkComponent {
FetchState::NotFetching(_) => html! {},
FetchState::Fetching(_) => html! {},
FetchState::Fetched(_body) => {
- let callback = ctx.link().callback(|event: FocusEvent| {
+ let form_callback = ctx.link().callback(|event: FocusEvent| {
event.prevent_default();
Msg::UpdateWork
});
+ // if matches conditions for non-superuser (i.e. dialogue is present)
+ // let form_callback = event.prevent_default();
+ // nice to have: trigger dialogue by hitting enter
+
// FormImprintSelect: while the work has any related issues, the imprint cannot
// be changed, because an issue's series and work must both have the same imprint.
let imprints = match self.work.issues.as_ref().unwrap_or(&vec![]).is_empty() {
@@ -613,7 +617,7 @@ impl Component for WorkComponent {
-
diff --git a/thoth-app/src/component/work_status_dialogue.rs b/thoth-app/src/component/work_status_dialogue.rs
index 484a7efcf..ea0a480a8 100644
--- a/thoth-app/src/component/work_status_dialogue.rs
+++ b/thoth-app/src/component/work_status_dialogue.rs
@@ -1,5 +1,6 @@
use crate::string::CANCEL_BUTTON;
use crate::string::SAVE_BUTTON;
+use thoth_api::account::model::AccountDetails;
use yew::html;
use yew::prelude::*;
@@ -11,12 +12,17 @@ pub struct ConfirmWorkStatusComponent {
pub struct Props {
pub onclick: Option>,
pub object_name: String,
+ pub current_user: AccountDetails,
+ pub current_state_unpublished: bool,
+ pub is_published: bool,
+ // pub form_callback: Callback<()>,
#[prop_or_default]
pub deactivated: bool,
}
pub enum Msg {
ToggleConfirmWorkStatusDisplay(bool),
+ ExecuteCallback
}
impl Component for ConfirmWorkStatusComponent {
@@ -33,6 +39,16 @@ impl Component for ConfirmWorkStatusComponent {
self.show = value;
true
}
+ Msg::ExecuteCallback => {
+ self.show = false;
+ // trigger the callback
+ // _ctx.props().form_callback(|_| form_callback).emit(());
+ // form_callback.emit(());
+ // when set as true, the modal closes and it saves correctly
+ // true
+ // when set as false, the modal also closes and saves correctly.
+ false
+ }
}
}
@@ -45,11 +61,20 @@ impl Component for ConfirmWorkStatusComponent {
e.prevent_default();
Msg::ToggleConfirmWorkStatusDisplay(false)
});
+ let modal_behavior = if !ctx.props().current_user.resource_access.is_superuser
+ && ctx.props().current_state_unpublished
+ && ctx.props().is_published {
+ &open_modal
+ } else {
+ &close_modal
+ };
+
html! {
<>
+ // Ok, so it looks like the delete confirmation doesn't take care of
+ // closing the modal because the delete message redirects to a different route,
+ // so there's no need to close the modal
+
+ // You'll need to explicitly close the work status modal yourself
+
+ // to do so, you can create a message in the dialogue that is
+ // called onclick and (a) closes the dialogue, (b) emmits the onclick callback
+ // it receives from work.rs
+