Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions render/delete_dialog_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"charm.land/lipgloss/v2"
)

type DeleteHandler interface {
Delete(entry *structure.Entry) error
}

type DeleteChoice int

const (
Expand All @@ -27,16 +31,16 @@ type EntryDeleted struct {
}

type DeleteDialogModel struct {
nav *Navigation
toDelete []*structure.Entry
choice DeleteChoice
deleteHandler DeleteHandler
toDelete []*structure.Entry
choice DeleteChoice
}

func NewDeleteDialogModel(nav *Navigation, toDelete []*structure.Entry) *DeleteDialogModel {
func NewDeleteDialogModel(dh DeleteHandler, toDelete []*structure.Entry) *DeleteDialogModel {
return &DeleteDialogModel{
choice: CancelChoice,
toDelete: toDelete,
nav: nav,
deleteHandler: dh,
choice: CancelChoice,
toDelete: toDelete,
}
}

Expand All @@ -59,7 +63,7 @@ func (ddm *DeleteDialogModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

if ddm.choice == ConfirmChoice {
for _, entry := range ddm.toDelete {
err = ddm.nav.Delete(entry)
err = ddm.deleteHandler.Delete(entry)
}

deleted = true
Expand Down
2 changes: 1 addition & 1 deletion render/dir_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func NewDirModel(nav *Navigation, filters ...filter.EntryFilter) *DirModel {
func() { go teaProg.Send(EnqueueRefresh{Mode: CMD}) },
),
errPopup: NewPopupModel(
ErrorTitle, time.Second*10, teaProg, PopupDefaultErrorStyle(),
ErrorTitle, time.Second*10, PopupDefaultErrorStyle(),
),
summaryInfo: &summaryInfo{},
sortState: SortState{Key: structure.SortSize, Desc: true},
Expand Down
8 changes: 3 additions & 5 deletions render/popup.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type PopupModel struct {
duration time.Duration
ttl time.Time
styles *PopupStyles
program *tea.Program
title string
queueLimit int
hideCountdown bool
Expand All @@ -56,7 +55,7 @@ type PopupModel struct {
// NewPopupModel creates a new *PopupModel instance with the provided title and
// visibility duration. The *PopupStyles are optional, and if the value is empty,
// the DefaultPopupStyle will be used.
func NewPopupModel(title string, d time.Duration, p *tea.Program, ps *PopupStyles) *PopupModel {
func NewPopupModel(title string, d time.Duration, ps *PopupStyles) *PopupModel {
if len(title) == 0 {
title = InfoTitle
}
Expand All @@ -69,7 +68,6 @@ func NewPopupModel(title string, d time.Duration, p *tea.Program, ps *PopupStyle
title: title,
duration: d,
styles: ps,
program: p,
messageQueue: make([]string, 0, queueLimit),
queueLimit: queueLimit,
}
Expand Down Expand Up @@ -224,7 +222,7 @@ func (pm *PopupModel) nextMessage() (string, bool) {
}

func (pm *PopupModel) condTickCmd() {
if pm.program == nil || !pm.visible {
if teaProg == nil || !pm.visible {
return
}

Expand All @@ -233,7 +231,7 @@ func (pm *PopupModel) condTickCmd() {
defer ticker.Stop()

for range ticker.C {
pm.program.Send(PopupMsgTick{})
teaProg.Send(PopupMsgTick{})

pm.Update(nil)

Expand Down
10 changes: 5 additions & 5 deletions render/popup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestPopupModel_Show_AddsMessage(t *testing.T) {
pm := render.NewPopupModel("Test", time.Second, nil, nil)
pm := render.NewPopupModel("Test", time.Second, nil)

pm.Show("msg1")

Expand All @@ -20,7 +20,7 @@ func TestPopupModel_Show_AddsMessage(t *testing.T) {
}

func TestPopupModel_Show_ReplacesWhenFull(t *testing.T) {
pm := render.NewPopupModel("Test", time.Second, nil, nil)
pm := render.NewPopupModel("Test", time.Second, nil)

for i := 1; i <= 5; i++ {
pm.Show("msg" + string(rune('0'+i)))
Expand All @@ -35,7 +35,7 @@ func TestPopupModel_Show_ReplacesWhenFull(t *testing.T) {
}

func TestPopupModel_Update_RemovesMessagesOnTTL(t *testing.T) {
pm := render.NewPopupModel("Test", time.Millisecond*50, nil, nil)
pm := render.NewPopupModel("Test", time.Millisecond*50, nil)

pm.Show("msg1")
pm.Show("msg2")
Expand All @@ -51,7 +51,7 @@ func TestPopupModel_Update_RemovesMessagesOnTTL(t *testing.T) {
}

func TestPopupModel_View_ReturnsEmptyWhenNotVisible(t *testing.T) {
pm := render.NewPopupModel("Test", time.Second, nil, nil)
pm := render.NewPopupModel("Test", time.Second, nil)

assert.Empty(t, pm.View())

Expand All @@ -72,7 +72,7 @@ func TestPopupModel_View_ShowsCountdown(t *testing.T) {
lipgloss.NewStyle(),
)

pm := render.NewPopupModel("Test", time.Second, nil, style)
pm := render.NewPopupModel("Test", time.Second, style)
pm.Show("hello")

view := pm.View()
Expand Down
2 changes: 1 addition & 1 deletion render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type (
EnqueueRefresh struct{ Mode Mode }
)

var teaProg = new(tea.Program)
var teaProg *tea.Program

type ViewModel struct {
driveModel *DriveModel
Expand Down
Loading