Skip to content

Commit

Permalink
Callbacks in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-oconnell committed Dec 31, 2024
1 parent fde822b commit a4e9533
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 15 deletions.
36 changes: 23 additions & 13 deletions thoth-app/src/component/work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,14 @@ impl Component for WorkComponent {
FetchState::NotFetching(_) => html! {<Loader/>},
FetchState::Fetching(_) => html! {<Loader/>},
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() {
Expand Down Expand Up @@ -613,7 +617,7 @@ impl Component for WorkComponent {
</div>
</nav>

<form onsubmit={ callback }>
<form onsubmit={ form_callback }>
<div class="field is-horizontal">
<div class="field-body">
<FormWorkTypeSelect
Expand Down Expand Up @@ -836,19 +840,25 @@ impl Component for WorkComponent {
// if the Work is unpublished (forthcoming, postponed, cancelled)
// and non-superuser sets to published (active, withdrawn, superseded),
// display warning dialogue
if !ctx.props().current_user.resource_access.is_superuser
&& current_state_unpublished
&& is_published
{
<ConfirmWorkStatusComponent
// if !ctx.props().current_user.resource_access.is_superuser
// && current_state_unpublished
// && is_published
// // is superuser = false
// {
<ConfirmWorkStatusComponent
onclick={ ctx.link().callback(|_| Msg::UpdateWork) }
object_name={ self.work.full_title.clone() }
/>
} else {
<button class="button is-success" type="submit">
{ SAVE_BUTTON }
</button>
}
current_user={ ctx.props().current_user.clone() }
current_state_unpublished={ current_state_unpublished }
is_published={ is_published }


/>
// } else {
// <button class="button is-success" type="submit">
// { SAVE_BUTTON }
// </button>
// }
</div>
</div>
</form>
Expand Down
40 changes: 38 additions & 2 deletions thoth-app/src/component/work_status_dialogue.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand All @@ -11,12 +12,17 @@ pub struct ConfirmWorkStatusComponent {
pub struct Props {
pub onclick: Option<Callback<MouseEvent>>,
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 {
Expand All @@ -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
}
}
}

Expand All @@ -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! {
<>
<button
class="button is-success"
onclick={ open_modal }
// onclick={ open_modal }
onclick={ modal_behavior }
disabled={ ctx.props().deactivated }
>
{ SAVE_BUTTON }
Expand All @@ -72,10 +97,21 @@ impl Component for ConfirmWorkStatusComponent {
{ "?" }
</p>
</section>
// 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

<footer class="modal-card-foot">
<button
class="button is-success"
onclick={ ctx.props().onclick.clone() }
// onclick={ ctx.props().onclick.clone() }
onclick={ ctx.link().callback(|_| Msg::ExecuteCallback) }
>
{ SAVE_BUTTON }
</button>
Expand Down

0 comments on commit a4e9533

Please sign in to comment.