def on_modifier_click()

in experiments/veo-app/pages/portraits.py [0:0]


def on_modifier_click(e: me.ClickEvent):
    """Handles click events for modifier content_buttons."""
    state = me.state(PageState)
    # modifier_key = e.key  # The key of the content_button that was clicked
    modifier_key = e.key.split("mod_btn_")[-1]  # Extract original key

    if not modifier_key:
        print("Error: ClickEvent has no key associated with the content_button.")
        return

    # Toggle the presence of the modifier_key in the modifier_array
    if modifier_key in state.modifier_array:
        # If already selected, remove it (deselect)
        new_modifier_array = [
            mod for mod in state.modifier_array if mod != modifier_key
        ]
        state.modifier_array = new_modifier_array
    else:
        # If not selected, add it (select)
        state.modifier_array = [*state.modifier_array, modifier_key]