fix(ui): display status message when moving card

After moving cards from one status to another the status bar now shows
either a confirmation or an error message depending on the success of
the move.
This commit is contained in:
Dan Anglin 2024-01-13 19:54:24 +00:00
parent eb2ed4060a
commit 43095b9932
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
3 changed files with 24 additions and 7 deletions

View file

@ -48,7 +48,7 @@ func (c *cardView) setDoneFunc(handler func(key tcell.Key)) {
c.SetDoneFunc(handler)
}
func (c *cardView) print(id int, title, status, created, description string) {
func (c *cardView) setText(id int, title, status, created, description string) {
fmt.Fprintf(c, c.contentFormat, id, title, status, created, description)
}

View file

@ -1,6 +1,10 @@
package ui
import "codeflow.dananglin.me.uk/apollo/pelican/internal/board"
import (
"fmt"
"codeflow.dananglin.me.uk/apollo/pelican/internal/board"
)
type statusSelection struct {
cardID int
@ -8,13 +12,16 @@ type statusSelection struct {
nextStatusID int
}
func (s statusSelection) moveCard(kanban board.Board) {
func (s statusSelection) moveCard(kanban board.Board) error {
moveArgs := board.MoveToStatusArgs{
CardID: s.cardID,
CurrentStatusID: s.currentStatusID,
NextStatusID: s.nextStatusID,
}
// TODO: grab error for status line.
_ = kanban.MoveToStatus(moveArgs)
if err := kanban.MoveToStatus(moveArgs); err != nil {
return fmt.Errorf("error moving card; %w", err)
}
return nil
}

View file

@ -187,13 +187,23 @@ func (u *UI) inputCapture() func(event *tcell.EventKey) *tcell.EventKey {
}
status := u.focusedStatusName()
u.view.print(card.ID, card.Title, status, card.Created, card.Description)
u.view.setText(card.ID, card.Title, status, card.Created, card.Description)
u.pages.ShowPage(viewPage)
u.SetFocus(u.view)
case selection:
u.statusSelection.nextStatusID = u.focusedStatusID()
if u.statusSelection.currentStatusID != u.statusSelection.nextStatusID {
u.statusSelection.moveCard(u.board)
if err := u.statusSelection.moveCard(u.board); err != nil {
u.statusbar.displayMessage(
errorLevel,
fmt.Sprintf("Failed to move card: %v", err),
)
} else {
u.statusbar.displayMessage(
infoLevel,
"Card moved successfully.",
)
}
}
u.statusSelection = statusSelection{0, 0, 0}