80 lines
1.8 KiB
Go
80 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"gemini_site/gemlog"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
type EntryListPageModel struct {
|
|
entries []gemlog.GemlogListEntry
|
|
actionToTake Action
|
|
cursor int
|
|
}
|
|
|
|
func InitialEntryListPageModel() EntryListPageModel {
|
|
return EntryListPageModel{
|
|
cursor: 0,
|
|
actionToTake: Read,
|
|
}
|
|
}
|
|
|
|
func (m EntryListPageModel) InitEntryListPage() tea.Cmd {
|
|
return nil
|
|
}
|
|
|
|
func (m EntryListPageModel) Update(msg tea.Msg, ctx *context) (EntryListPageModel, tea.Cmd) {
|
|
switch msg := msg.(type) {
|
|
case gemlog.GemLogsLoaded:
|
|
m.entries = msg.Logs
|
|
return m, nil
|
|
case tea.KeyMsg:
|
|
switch msg.String() {
|
|
case "up", "k":
|
|
if m.cursor > 0 {
|
|
m.cursor--
|
|
}
|
|
case "down", "j":
|
|
if m.cursor < len(actions)-1 {
|
|
m.cursor++
|
|
}
|
|
// case "enter", " ":
|
|
|
|
// action := actions[m.cursor]
|
|
// switch action {
|
|
// case Write:
|
|
// return m, gemlog.WritePostCMD(ctx.config)
|
|
// case Read:
|
|
// m.ui.page = EntryList
|
|
// m.ui.entryListPage.cursor = 0
|
|
// m.ui.entryListPage.actionToTake = Read
|
|
// return m, gemlog.LoadGemlogCMD(ctx.config)
|
|
// case Edit:
|
|
// m.ui.page = EntryList
|
|
// m.ui.entryListPage.cursor = 0
|
|
// m.ui.entryListPage.actionToTake = Edit
|
|
// return m, gemlog.LoadGemlogCMD(ctx.config)
|
|
// case Delete:
|
|
// m.ui.page = EntryList
|
|
// m.ui.entryListPage.cursor = 0
|
|
// m.ui.entryListPage.actionToTake = Delete
|
|
// return m, gemlog.LoadGemlogCMD(m.context.config)
|
|
// }
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
func (m EntryListPageModel) View() string {
|
|
s := fmt.Sprintf("Which entry would you like to %s\n\n", m.actionToTake)
|
|
for i, entry := range m.entries {
|
|
cursor := " "
|
|
if m.cursor == i {
|
|
cursor = ">"
|
|
}
|
|
s += fmt.Sprintf("%s %s : %s\n", cursor, entry.Date, entry.Slug)
|
|
}
|
|
return s
|
|
}
|