get seprate file for entry list working
This commit is contained in:
parent
4d1f3f2f3e
commit
b680a2f5d7
4 changed files with 102 additions and 32 deletions
80
entryList.go
Normal file
80
entryList.go
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue