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
|
|
@ -49,11 +49,12 @@ func (m ActionListPageModel) Update(msg tea.Msg, ctx *context) (ActionListPageMo
|
||||||
switch action {
|
switch action {
|
||||||
case Write:
|
case Write:
|
||||||
return m, gemlog.WritePostCMD(ctx.config)
|
return m, gemlog.WritePostCMD(ctx.config)
|
||||||
// case Read:
|
case Read:
|
||||||
// m.ui.page = EntryList
|
switchPageCmd := func() tea.Msg {
|
||||||
// m.ui.entryListPage.cursor = 0
|
return SwitchPages{Page: EntryList}
|
||||||
// m.ui.entryListPage.actionToTake = Read
|
}
|
||||||
// return m, gemlog.LoadGemlogCMD(ctx.config)
|
loadGemLogsCmd := gemlog.LoadGemlogCMD(ctx.config)
|
||||||
|
return m, tea.Batch(switchPageCmd, loadGemLogsCmd)
|
||||||
// case Edit:
|
// case Edit:
|
||||||
// m.ui.page = EntryList
|
// m.ui.page = EntryList
|
||||||
// m.ui.entryListPage.cursor = 0
|
// m.ui.entryListPage.cursor = 0
|
||||||
|
|
|
||||||
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
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,6 @@ func LoadGemlogCMD(config *Config) tea.Cmd {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrorMsg{err}
|
return ErrorMsg{err}
|
||||||
}
|
}
|
||||||
return GemLogsLoaded{logs}
|
return GemLogsLoaded{Logs: logs}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
37
main.go
37
main.go
|
|
@ -13,22 +13,18 @@ type Page string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ActionList Page = "actionList"
|
ActionList Page = "actionList"
|
||||||
// EntryList Page = "entryList"
|
EntryList Page = "entryList"
|
||||||
// Entry Page = "entry"
|
// Entry Page = "entry"
|
||||||
)
|
)
|
||||||
|
|
||||||
// type entryListPageModel struct {
|
type SwitchPages struct{ Page Page }
|
||||||
// entries []gemlog.GemlogListEntry
|
|
||||||
// actionToTake Action
|
|
||||||
// cursor int
|
|
||||||
// }
|
|
||||||
|
|
||||||
type uiState struct {
|
type uiState struct {
|
||||||
notification string
|
notification string
|
||||||
errorTxt string
|
errorTxt string
|
||||||
|
|
||||||
page Page
|
page Page
|
||||||
// entryListPage entryListPageModel
|
entryListPage EntryListPageModel
|
||||||
actionListPage ActionListPageModel
|
actionListPage ActionListPageModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,6 +63,8 @@ func (m model) Init() tea.Cmd {
|
||||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
cmds := make([]tea.Cmd, 0)
|
cmds := make([]tea.Cmd, 0)
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
|
case SwitchPages:
|
||||||
|
m.ui.page = msg.Page
|
||||||
case gemlog.ErrorMsg:
|
case gemlog.ErrorMsg:
|
||||||
m.ui.errorTxt = fmt.Sprintf("%s\n\n", fmt.Errorf("%s", msg))
|
m.ui.errorTxt = fmt.Sprintf("%s\n\n", fmt.Errorf("%s", msg))
|
||||||
case gemlog.Notification:
|
case gemlog.Notification:
|
||||||
|
|
@ -78,13 +76,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delegate to the active page
|
actionListM, cmd := m.ui.actionListPage.Update(msg, m.context)
|
||||||
switch m.ui.page {
|
m.ui.actionListPage = actionListM
|
||||||
case ActionList:
|
cmds = append(cmds, cmd)
|
||||||
m2, cmd := m.ui.actionListPage.Update(msg, m.context)
|
|
||||||
m.ui.actionListPage = m2
|
entryListM, cmd := m.ui.entryListPage.Update(msg, m.context)
|
||||||
|
m.ui.entryListPage = entryListM
|
||||||
cmds = append(cmds, cmd)
|
cmds = append(cmds, cmd)
|
||||||
}
|
|
||||||
|
|
||||||
return m, tea.Batch(cmds...)
|
return m, tea.Batch(cmds...)
|
||||||
}
|
}
|
||||||
|
|
@ -100,19 +98,10 @@ func (m model) View() string {
|
||||||
|
|
||||||
if m.ui.page == ActionList {
|
if m.ui.page == ActionList {
|
||||||
s += m.ui.actionListPage.View()
|
s += m.ui.actionListPage.View()
|
||||||
|
} else if m.ui.page == EntryList {
|
||||||
|
s += m.ui.entryListPage.View()
|
||||||
}
|
}
|
||||||
|
|
||||||
// if m.ui.page == EntryList {
|
|
||||||
// s += fmt.Sprintf("Which entry would you like to %s\n\n", m.ui.entryListPage.actionToTake)
|
|
||||||
// for i, entry := range m.ui.entryListPage.entries {
|
|
||||||
// cursor := " "
|
|
||||||
// if m.ui.entryListPage.cursor == i {
|
|
||||||
// cursor = ">"
|
|
||||||
// }
|
|
||||||
// s += fmt.Sprintf("%s %s : %s\n", cursor, entry.Date, entry.Slug)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
s += "\nPress q to quit.\n"
|
s += "\nPress q to quit.\n"
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue