From 08cdb3645c814b997d6af4c0db5d4b4ccd93f6b8 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Tue, 29 Sep 2026 01:13:47 -0400 Subject: [PATCH] refactor(attachmentspicker): use picker.Items directly --- internal/ui/chat/attachmentspicker/model.go | 13 ------------- internal/ui/chat/messageslist/model.go | 14 +++++++------- internal/ui/chat/messageslist/msg.go | 4 ++-- internal/ui/chat/model.go | 3 ++- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/internal/ui/chat/attachmentspicker/model.go b/internal/ui/chat/attachmentspicker/model.go index 27be837..d88ca17 100644 --- a/internal/ui/chat/attachmentspicker/model.go +++ b/internal/ui/chat/attachmentspicker/model.go @@ -7,11 +7,6 @@ import ( "github.com/ayn2op/tview/picker" ) -type Item struct { - Label string - Action tview.Cmd -} - type Model struct { uipicker.Model } @@ -33,14 +28,6 @@ func (m Model) View() tview.Element { }, CancelMsg{}) } -func (m *Model) SetItems(items []Item) { - pickerItems := make(picker.Items, len(items)) - for i, item := range items { - pickerItems[i] = picker.Item{Text: item.Label, Reference: item.Action} - } - m.Model.SetItems(pickerItems) -} - func (m Model) Update(msg tview.Msg) (Model, tview.Cmd) { var cmd tview.Cmd m.Model, cmd = m.Model.Update(msg) diff --git a/internal/ui/chat/messageslist/model.go b/internal/ui/chat/messageslist/model.go index c917dd2..0e4892a 100644 --- a/internal/ui/chat/messageslist/model.go +++ b/internal/ui/chat/messageslist/model.go @@ -25,12 +25,12 @@ import ( "github.com/ayn2op/discordo/internal/consts" "github.com/ayn2op/discordo/internal/markdown" "github.com/ayn2op/discordo/internal/ui" - "github.com/ayn2op/discordo/internal/ui/chat/attachmentspicker" "github.com/ayn2op/ningen/v3" "github.com/ayn2op/tview" "github.com/ayn2op/tview/help" "github.com/ayn2op/tview/keybind" "github.com/ayn2op/tview/list" + "github.com/ayn2op/tview/picker" "github.com/ayn2op/tview/richtext" "github.com/ayn2op/tview/scrollbar" "github.com/ayn2op/tview/textview" @@ -1076,9 +1076,9 @@ func (ml *Model) download() tview.Cmd { return ml.confirmAttachment(attachment, saveAttachment(attachment)) } - items := make([]attachmentspicker.Item, len(selectedMessage.Attachments)) + items := make(picker.Items, len(selectedMessage.Attachments)) for i, attachment := range selectedMessage.Attachments { - items[i] = attachmentspicker.Item{Label: attachment.Filename, Action: ml.confirmAttachment(attachment, saveAttachment(attachment))} + items[i] = picker.Item{Text: attachment.Filename, Reference: ml.confirmAttachment(attachment, saveAttachment(attachment))} } return ml.showAttachmentsPicker(items) } @@ -1144,17 +1144,17 @@ func messageURLs(msg discord.Message) []string { } func (ml *Model) showAttachmentsList(urls []string, attachments []discord.Attachment, openAttachment func(discord.Attachment) tview.Cmd) tview.Cmd { - var items []attachmentspicker.Item + var items picker.Items for _, attachment := range attachments { - items = append(items, attachmentspicker.Item{Label: attachment.Filename, Action: openAttachment(attachment)}) + items = append(items, picker.Item{Text: attachment.Filename, Reference: openAttachment(attachment)}) } for _, url := range urls { - items = append(items, attachmentspicker.Item{Label: url, Action: openURL(url)}) + items = append(items, picker.Item{Text: url, Reference: openURL(url)}) } return ml.showAttachmentsPicker(items) } -func (ml *Model) showAttachmentsPicker(items []attachmentspicker.Item) tview.Cmd { +func (ml *Model) showAttachmentsPicker(items picker.Items) tview.Cmd { return func() tview.Msg { return ShowAttachmentsMsg(items) } } diff --git a/internal/ui/chat/messageslist/msg.go b/internal/ui/chat/messageslist/msg.go index 34bcd2d..3d27712 100644 --- a/internal/ui/chat/messageslist/msg.go +++ b/internal/ui/chat/messageslist/msg.go @@ -2,8 +2,8 @@ package messageslist import ( "github.com/ayn2op/arikawa/v3/discord" - "github.com/ayn2op/discordo/internal/ui/chat/attachmentspicker" "github.com/ayn2op/tview" + "github.com/ayn2op/tview/picker" ) // Msg is implemented by the messages the list sends itself, which must reach it whatever has the focus. @@ -33,4 +33,4 @@ type ReplyMsg struct { type EditMsg discord.Message // ShowAttachmentsMsg asks to pick one of the attachments and links of the selected message. -type ShowAttachmentsMsg []attachmentspicker.Item +type ShowAttachmentsMsg picker.Items diff --git a/internal/ui/chat/model.go b/internal/ui/chat/model.go index a096003..26a551f 100644 --- a/internal/ui/chat/model.go +++ b/internal/ui/chat/model.go @@ -31,6 +31,7 @@ import ( "github.com/ayn2op/tview/column" "github.com/ayn2op/tview/inert" "github.com/ayn2op/tview/keybind" + "github.com/ayn2op/tview/picker" "github.com/ayn2op/tview/row" "github.com/ayn2op/tview/stack" ) @@ -256,7 +257,7 @@ func (m *Model) update(msg tview.Msg) tview.Cmd { case attachmentspicker.CancelMsg: return m.closeAttachmentsPicker() case messageslist.ShowAttachmentsMsg: - m.attachmentsPicker.SetItems(msg) + m.attachmentsPicker.SetItems(picker.Items(msg)) m.attachmentsPickerOpen = true return nil case messageslist.ReplyMsg: