Skip to content
Open
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
11 changes: 9 additions & 2 deletions tui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

const defaultEditor = "vim"

/* PROJECTS */
/* ENTRIES */

func openEditorCmd() tea.Cmd {
file, err := os.CreateTemp(os.TempDir(), "")
Expand Down Expand Up @@ -51,7 +51,14 @@ func (m Entry) createEntryCmd(file *os.File) tea.Cmd {
}
}

/* ENTRIES */
func (m Entry) deleteEntryCmd(id uint) tea.Cmd {
return func() tea.Msg {
constants.Er.DeleteEntryByID(id)
return m.setupEntries()
}
}

/* PROJECTS */

func createProjectCmd(name string, pr *project.GormRepository) tea.Cmd {
return func() tea.Msg {
Expand Down
21 changes: 20 additions & 1 deletion tui/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ func (m *Entry) setViewportContent() {
if len(m.entries) == 0 {
content = "There are no entries for this project :)"
} else {
content = entry.FormatEntry(m.entries[m.paginator.Page])
var entryNum int
if m.paginator.Page >= len(m.entries) && len(m.entries) > 0 {
entryNum = m.paginator.Page - 1
} else {
entryNum = m.paginator.Page
}

content = entry.FormatEntry(m.entries[entryNum])
}
str, err := glamour.Render(content, "dark")
if err != nil {
Expand Down Expand Up @@ -116,6 +123,18 @@ func (m Entry) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, constants.Keymap.Quit):
m.quitting = true
return m, tea.Quit
// add delete entry functionality
case key.Matches(msg, constants.Keymap.Delete):
if len(m.entries) > 0 {
currEntryId := m.entries[m.paginator.Page].ID

// if i'm on the last page, go back one page, else it will crash
if m.paginator.Page == len(m.entries)-1 {
m.paginator.PrevPage()
}

return m, m.deleteEntryCmd(currEntryId)
}
}
}

Expand Down