refactor(attachmentspicker): use picker.Items directly
This commit is contained in:
parent
1c62b37bc6
commit
08cdb3645c
4 changed files with 11 additions and 23 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue