From 5a16717234fbc1a8a34a77657f492f717d234aee Mon Sep 17 00:00:00 2001 From: Filip Hoffmann Date: Sat, 14 Feb 2026 13:37:08 +0100 Subject: [PATCH] force most modal components to be in labels, add radio group --- src/grom/component/label.gleam | 3 +++ src/grom/interaction.gleam | 24 +++--------------------- src/grom/modal.gleam | 27 --------------------------- 3 files changed, 6 insertions(+), 48 deletions(-) diff --git a/src/grom/component/label.gleam b/src/grom/component/label.gleam index 5e22a23..e655823 100644 --- a/src/grom/component/label.gleam +++ b/src/grom/component/label.gleam @@ -5,6 +5,7 @@ import gleam/option.{type Option, None, Some} import grom/component/channel_select.{type ChannelSelect} import grom/component/file_upload.{type FileUpload} import grom/component/mentionable_select.{type MentionableSelect} +import grom/component/radio_group.{type RadioGroup} import grom/component/role_select.{type RoleSelect} import grom/component/string_select.{type StringSelect} import grom/component/text_input.{type TextInput} @@ -29,6 +30,7 @@ pub type Component { MentionableSelect(MentionableSelect) ChannelSelect(ChannelSelect) FileUpload(FileUpload) + RadioGroup(RadioGroup) } // DECODERS -------------------------------------------------------------------- @@ -95,6 +97,7 @@ pub fn component_to_json(component: Component) -> Json { mentionable_select.to_json(mentionable_select) ChannelSelect(channel_select) -> channel_select.to_json(channel_select) FileUpload(file_upload) -> file_upload.to_json(file_upload) + RadioGroup(radio_group) -> radio_group.to_json(radio_group) } } diff --git a/src/grom/interaction.gleam b/src/grom/interaction.gleam index 683ce51..f3eaa55 100644 --- a/src/grom/interaction.gleam +++ b/src/grom/interaction.gleam @@ -81,16 +81,8 @@ pub type ModalSubmission { } pub type SubmittedModalComponent { - StringSelectSubmitted(StringSelectExecution) - TextInputSubmitted(TextInputSubmission) - UserSelectSubmitted(UserSelectExecution) - RoleSelectSubmitted(RoleSelectExecution) - MentionableSelectSubmitted(MentionableSelectExecution) - ChannelSelectSubmitted(ChannelSelectExecution) TextDisplaySubmitted(TextDisplaySubmission) LabelSubmitted(LabelSubmission) - FileUploadSubmitted(FileUploadSubmission) - RadioGroupSubmitted(RadioGroupSubmission) } pub type RadioGroupSubmission { @@ -125,6 +117,7 @@ pub type SubmittedLabelComponent { LabelMentionableSelectSubmitted(MentionableSelectExecution) LabelChannelSelectSubmitted(ChannelSelectExecution) LabelFileUploadSubmitted(FileUploadSubmission) + LabelRadioGroupSubmitted(RadioGroupSubmission) } pub type TextDisplaySubmission { @@ -589,23 +582,11 @@ pub fn submitted_modal_component_decoder() -> decode.Decoder( ) { use type_ <- decode.field("type", decode.int) case type_ { - 3 -> decode.map(string_select_execution_decoder(), StringSelectSubmitted) - 4 -> decode.map(text_input_submission_decoder(), TextInputSubmitted) - 5 -> decode.map(user_select_execution_decoder(), UserSelectSubmitted) - 6 -> decode.map(role_select_execution_decoder(), RoleSelectSubmitted) - 7 -> - decode.map( - mentionable_select_execution_decoder(), - MentionableSelectSubmitted, - ) - 8 -> decode.map(channel_select_execution_decoder(), ChannelSelectSubmitted) 10 -> decode.map(text_display_submission_decoder(), TextDisplaySubmitted) 18 -> decode.map(label_submission_decoder(), LabelSubmitted) - 19 -> decode.map(file_upload_submission_decoder(), FileUploadSubmitted) - 21 -> decode.map(radio_group_submission_decoder(), RadioGroupSubmitted) _ -> decode.failure( - StringSelectSubmitted(StringSelectExecution("", [], None)), + TextDisplaySubmitted(TextDisplaySubmission(0)), "SubmittedModalComponent", ) } @@ -680,6 +661,7 @@ pub fn submitted_label_component_decoder() -> decode.Decoder( LabelChannelSelectSubmitted, ) 19 -> decode.map(file_upload_submission_decoder(), LabelFileUploadSubmitted) + 21 -> decode.map(radio_group_submission_decoder(), LabelRadioGroupSubmitted) _ -> decode.failure( LabelStringSelectSubmitted(StringSelectExecution("", [], None)), diff --git a/src/grom/modal.gleam b/src/grom/modal.gleam index 22dbf04..756b73b 100644 --- a/src/grom/modal.gleam +++ b/src/grom/modal.gleam @@ -1,30 +1,12 @@ import gleam/json.{type Json} -import grom/component/channel_select.{type ChannelSelect} -import grom/component/file_upload.{type FileUpload} import grom/component/label.{type Label} -import grom/component/mentionable_select.{type MentionableSelect} -import grom/component/radio_group.{type RadioGroup} -import grom/component/role_select.{type RoleSelect} -import grom/component/string_select.{type StringSelect} import grom/component/text_display.{type TextDisplay} -import grom/component/text_input.{type TextInput} -import grom/component/user_select.{type UserSelect} // TYPES ----------------------------------------------------------------------- -/// It is suggested that you wrap all components in Labels. -/// (except for TextDisplays and Labels) pub type Component { - StringSelect(StringSelect) - TextInput(TextInput) - UserSelect(UserSelect) - RoleSelect(RoleSelect) - MentionableSelect(MentionableSelect) - ChannelSelect(ChannelSelect) - FileUpload(FileUpload) TextDisplay(TextDisplay) Label(Label) - RadioGroup(RadioGroup) } // ENCODERS -------------------------------------------------------------------- @@ -32,16 +14,7 @@ pub type Component { @internal pub fn component_to_json(component: Component) -> Json { case component { - StringSelect(string_select) -> string_select.to_json(string_select) - TextInput(text_input) -> text_input.to_json(text_input) - UserSelect(user_select) -> user_select.to_json(user_select) - RoleSelect(role_select) -> role_select.to_json(role_select) - MentionableSelect(mentionable_select) -> - mentionable_select.to_json(mentionable_select) - ChannelSelect(channel_select) -> channel_select.to_json(channel_select) - FileUpload(file_upload) -> file_upload.to_json(file_upload) TextDisplay(text_display) -> text_display.to_json(text_display) Label(label) -> label.to_json(label) - RadioGroup(radio_group) -> radio_group.to_json(radio_group) } } -- 2.51.2