Skip to content

Commit

Permalink
Fix button clicking events not working after react renderer parser re…
Browse files Browse the repository at this point in the history
…factor
  • Loading branch information
Exidex committed Nov 14, 2024
1 parent 6a56604 commit 1ca022e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 17 additions & 1 deletion rust/client/src/ui/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2644,7 +2644,7 @@ pub enum ComponentWidgetEvent {
include!(concat!(env!("OUT_DIR"), "/components.rs"));

impl ComponentWidgetEvent {
pub fn handle(self, _plugin_id: PluginId, state: &mut ComponentWidgetState) -> Option<UiViewEvent> {
pub fn handle(self, _plugin_id: PluginId, state: Option<&mut ComponentWidgetState>) -> Option<UiViewEvent> {
match self {
ComponentWidgetEvent::LinkClick { widget_id: _, href } => {
Some(UiViewEvent::Open {
Expand All @@ -2658,6 +2658,8 @@ impl ComponentWidgetEvent {
Some(create_action_on_action_event(widget_id))
}
ComponentWidgetEvent::ToggleDatePicker { widget_id } => {
let state = state.expect("state should always exist for ");

let ComponentWidgetState::DatePicker(DatePickerState { state_value: _, show_picker }) = state else {
panic!("unexpected state kind, widget_id: {:?} state: {:?}", widget_id, state)
};
Expand All @@ -2666,6 +2668,8 @@ impl ComponentWidgetEvent {
None
}
ComponentWidgetEvent::CancelDatePicker { widget_id } => {
let state = state.expect("state should always exist for ");

let ComponentWidgetState::DatePicker(DatePickerState { state_value: _, show_picker }) = state else {
panic!("unexpected state kind, widget_id: {:?} state: {:?}", widget_id, state)
};
Expand All @@ -2674,6 +2678,8 @@ impl ComponentWidgetEvent {
None
}
ComponentWidgetEvent::SubmitDatePicker { widget_id, value } => {
let state = state.expect("state should always exist for ");

{
let ComponentWidgetState::DatePicker(DatePickerState { state_value: _, show_picker }) = state else {
panic!("unexpected state kind, widget_id: {:?} state: {:?}", widget_id, state)
Expand All @@ -2685,6 +2691,8 @@ impl ComponentWidgetEvent {
Some(create_date_picker_on_change_event(widget_id, Some(value)))
}
ComponentWidgetEvent::ToggleCheckbox { widget_id, value } => {
let state = state.expect("state should always exist for ");

{
let ComponentWidgetState::Checkbox(CheckboxState { state_value }) = state else {
panic!("unexpected state kind, widget_id: {:?} state: {:?}", widget_id, state)
Expand All @@ -2696,6 +2704,8 @@ impl ComponentWidgetEvent {
Some(create_checkbox_on_change_event(widget_id, value))
}
ComponentWidgetEvent::SelectPickList { widget_id, value } => {
let state = state.expect("state should always exist for ");

{
let ComponentWidgetState::Select(SelectState { state_value }) = state else {
panic!("unexpected state kind, widget_id: {:?} state: {:?}", widget_id, state)
Expand All @@ -2707,6 +2717,8 @@ impl ComponentWidgetEvent {
Some(create_select_on_change_event(widget_id, Some(value)))
}
ComponentWidgetEvent::OnChangeTextField { widget_id, value } => {
let state = state.expect("state should always exist for ");

{
let ComponentWidgetState::TextField(TextFieldState { state_value, .. }) = state else {
panic!("unexpected state kind, widget_id: {:?} state: {:?}", widget_id, state)
Expand All @@ -2718,6 +2730,8 @@ impl ComponentWidgetEvent {
Some(create_text_field_on_change_event(widget_id, Some(value)))
}
ComponentWidgetEvent::OnChangePasswordField { widget_id, value } => {
let state = state.expect("state should always exist for ");

{
let ComponentWidgetState::TextField(TextFieldState { state_value, .. }) = state else {
panic!("unexpected state kind, widget_id: {:?} state: {:?}", widget_id, state)
Expand All @@ -2729,6 +2743,8 @@ impl ComponentWidgetEvent {
Some(create_password_field_on_change_event(widget_id, Some(value)))
}
ComponentWidgetEvent::OnChangeSearchBar { widget_id, value } => {
let state = state.expect("state should always exist for ");

{
let ComponentWidgetState::TextField(TextFieldState { state_value, .. }) = state else {
panic!("unexpected state kind, widget_id: {:?} state: {:?}", widget_id, state)
Expand Down
6 changes: 3 additions & 3 deletions rust/client/src/ui/widget_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ impl PluginWidgetContainer {
pub fn handle_event(&self, plugin_id: PluginId, event: ComponentWidgetEvent) -> Option<UiViewEvent> {
let mut state = self.state.lock().expect("lock is poisoned");

// TODO for events like typing, synchronous render should be implemented instead of ignoring events
state.get_mut(&event.widget_id())
.and_then(|state| event.handle(plugin_id, state))
let widget_id = event.widget_id();

event.handle(plugin_id, state.get_mut(&widget_id))
}

pub fn render_root_widget<'a>(
Expand Down

0 comments on commit 1ca022e

Please sign in to comment.