on main help sign in
fix(ui): filepicker: remove redundant Init method and Action type
cb8ddcbAyman Bagabas
internal/ui/dialog/filepicker.go+2−7
@@ -49,7 +49,7 @@ type FilePicker struct {
49var _ Dialog = (*FilePicker)(nil)
49var _ Dialog = (*FilePicker)(nil)
50
50
51// NewFilePicker creates a new [FilePicker] dialog.
51// NewFilePicker creates a new [FilePicker] dialog.
52−func NewFilePicker(com *common.Common) (*FilePicker, Action) {
52+func NewFilePicker(com *common.Common) (*FilePicker, tea.Cmd) {
53 f := new(FilePicker)
53 f := new(FilePicker)
54 f.com = com
54 f.com = com
55
55
@@ -98,7 +98,7 @@ func NewFilePicker(com *common.Common) (*FilePicker, Action) {
98
98
99 f.fp = fp
99 f.fp = fp
100
100
101− return f, ActionCmd{f.fp.Init()}
101+ return f, f.fp.Init()
102}
102}
103
103
104// SetImageCapabilities sets the image capabilities for the [FilePicker].
104// SetImageCapabilities sets the image capabilities for the [FilePicker].
@@ -156,11 +156,6 @@ func (f *FilePicker) ID() string {
156 return FilePickerID
156 return FilePickerID
157}
157}
158
158
159−// Init implements the [Dialog] interface.
160−func (f *FilePicker) Init() tea.Cmd {
161− return f.fp.Init()
162−}
163−
164// HandleMsg updates the [FilePicker] dialog based on the given message.
159// HandleMsg updates the [FilePicker] dialog based on the given message.
165func (f *FilePicker) HandleMsg(msg tea.Msg) Action {
160func (f *FilePicker) HandleMsg(msg tea.Msg) Action {
166 var cmds []tea.Cmd
161 var cmds []tea.Cmd
internal/ui/model/ui.go+3−4
@@ -2345,13 +2345,12 @@ func (m *UI) openFilesDialog() tea.Cmd {
2345 return nil
2345 return nil
2346 }
2346 }
2347
2347
2348− filePicker, action := dialog.NewFilePicker(m.com)
2348+ filePicker, cmd := dialog.NewFilePicker(m.com)
2349 filePicker.SetImageCapabilities(&m.imgCaps)
2349 filePicker.SetImageCapabilities(&m.imgCaps)
2350 m.dialog.OpenDialog(filePicker)
2350 m.dialog.OpenDialog(filePicker)
2351
2351
2352− switch action := action.(type) {
2352+ if cmd != nil {
2353− case dialog.ActionCmd:
2354− return action.Cmd
2353+ return cmd
2355 }
2354 }
2356
2355
2357 return nil
2356 return nil