add page for reading a single gemlog entry
This commit is contained in:
parent
8414414f98
commit
02ed95a612
5 changed files with 78 additions and 17 deletions
|
|
@ -32,9 +32,12 @@ func (m ActionListPageModel) InitActionListPage() tea.Cmd {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m ActionListPageModel) Update(msg tea.Msg, ctx *context) (ActionListPageModel, tea.Cmd) {
|
func (m ActionListPageModel) Update(msg tea.Msg, active bool, ctx *context) (ActionListPageModel, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
|
if !active {
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "up", "k":
|
case "up", "k":
|
||||||
if m.cursor > 0 {
|
if m.cursor > 0 {
|
||||||
|
|
|
||||||
45
entry.go
45
entry.go
|
|
@ -0,0 +1,45 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gemini_site/gemlog"
|
||||||
|
|
||||||
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
|
)
|
||||||
|
|
||||||
|
type EntryPageModel struct {
|
||||||
|
entry gemlog.GemlogEntry
|
||||||
|
}
|
||||||
|
|
||||||
|
func initialEntryPageModel() EntryPageModel {
|
||||||
|
return EntryPageModel{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m EntryPageModel) Update(msg tea.Msg, active bool, ctx *context) (EntryPageModel, tea.Cmd) {
|
||||||
|
switch msg := msg.(type) {
|
||||||
|
case gemlog.GemLogLoaded:
|
||||||
|
m.entry = msg.Log
|
||||||
|
case tea.KeyMsg:
|
||||||
|
if !active {
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
switch msg.String() {
|
||||||
|
case "left", "h":
|
||||||
|
cmd := func() tea.Msg {
|
||||||
|
return SwitchPages{Page: EntryList}
|
||||||
|
}
|
||||||
|
return m, cmd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m EntryPageModel) View() string {
|
||||||
|
s := m.entry.Slug
|
||||||
|
s += "\n\n"
|
||||||
|
s += m.entry.Gemtxt
|
||||||
|
s += "\n\n-------------------------\n"
|
||||||
|
s += "\n\nPress h or left arrow to go back"
|
||||||
|
return s
|
||||||
|
}
|
||||||
12
entryList.go
12
entryList.go
|
|
@ -48,20 +48,24 @@ func (m EntryListPageModel) Update(msg tea.Msg, active bool, ctx *context) (Entr
|
||||||
}
|
}
|
||||||
return m, cmd
|
return m, cmd
|
||||||
|
|
||||||
case "enter", " ":
|
case "enter", " ", "l":
|
||||||
id := m.entries[m.cursor].ID
|
id := m.entries[m.cursor].ID
|
||||||
rev := m.entries[m.cursor].Rev
|
rev := m.entries[m.cursor].Rev
|
||||||
switch m.actionToTake {
|
switch m.actionToTake {
|
||||||
|
// TODO: handle edit
|
||||||
|
case Read:
|
||||||
|
loadCmd := gemlog.LoadGemlogCMD(ctx.config, id)
|
||||||
|
navCmd := func() tea.Msg {
|
||||||
|
return SwitchPages{Page: Entry}
|
||||||
|
}
|
||||||
|
return m, tea.Sequence(loadCmd, navCmd)
|
||||||
case Delete:
|
case Delete:
|
||||||
delCmd := gemlog.DeleteGemlogCMD(ctx.config, id, rev)
|
delCmd := gemlog.DeleteGemlogCMD(ctx.config, id, rev)
|
||||||
loadCmd := gemlog.LoadGemlogsCMD(ctx.config)
|
loadCmd := gemlog.LoadGemlogsCMD(ctx.config)
|
||||||
navCmd := func() tea.Msg {
|
navCmd := func() tea.Msg {
|
||||||
return SwitchPages{Page: ActionList}
|
return SwitchPages{Page: ActionList}
|
||||||
}
|
}
|
||||||
|
|
||||||
return m, tea.Sequence(delCmd, loadCmd, navCmd)
|
return m, tea.Sequence(delCmd, loadCmd, navCmd)
|
||||||
case Read:
|
|
||||||
return m, gemlog.LoadGemlogCMD(ctx.config, id)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,10 +104,10 @@ func ReadGemlogEntry(config *Config, id string) (GemlogEntry, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var rawData struct {
|
var rawData struct {
|
||||||
ID int `json:"_id"`
|
// ID int `json:"_id"`
|
||||||
Rev int `json:"_rev"`
|
// Rev int `json:"_rev"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
GemText string `json:"gemtext"`
|
GemText string `json:"gemtxt"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
Date time.Time `json:"date"`
|
Date time.Time `json:"date"`
|
||||||
}
|
}
|
||||||
|
|
@ -120,6 +120,7 @@ func ReadGemlogEntry(config *Config, id string) (GemlogEntry, error) {
|
||||||
Title: rawData.Title,
|
Title: rawData.Title,
|
||||||
Slug: rawData.Slug,
|
Slug: rawData.Slug,
|
||||||
Date: rawData.Date,
|
Date: rawData.Date,
|
||||||
|
Gemtxt: rawData.GemText,
|
||||||
Tags: make([]string, 0),
|
Tags: make([]string, 0),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
main.go
18
main.go
|
|
@ -25,6 +25,7 @@ type uiState struct {
|
||||||
|
|
||||||
page Page
|
page Page
|
||||||
entryListPage EntryListPageModel
|
entryListPage EntryListPageModel
|
||||||
|
entryPage EntryPageModel
|
||||||
actionListPage ActionListPageModel
|
actionListPage ActionListPageModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,7 +44,7 @@ func initialModel(config *gemlog.Config) model {
|
||||||
page: ActionList,
|
page: ActionList,
|
||||||
actionListPage: initialActionListPageModel(),
|
actionListPage: initialActionListPageModel(),
|
||||||
entryListPage: initialEntryListPageModel(),
|
entryListPage: initialEntryListPageModel(),
|
||||||
// entryPage: initialEntryPageModel(),
|
entryPage: initialEntryPageModel(),
|
||||||
},
|
},
|
||||||
context: &context{
|
context: &context{
|
||||||
config: config,
|
config: config,
|
||||||
|
|
@ -59,7 +60,7 @@ 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, 3)
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case SwitchPages:
|
case SwitchPages:
|
||||||
m.ui.page = msg.Page
|
m.ui.page = msg.Page
|
||||||
|
|
@ -74,7 +75,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
actionListM, cmd := m.ui.actionListPage.Update(msg, m.context)
|
actionListM, cmd := m.ui.actionListPage.Update(msg, m.ui.page == ActionList, m.context)
|
||||||
m.ui.actionListPage = actionListM
|
m.ui.actionListPage = actionListM
|
||||||
cmds = append(cmds, cmd)
|
cmds = append(cmds, cmd)
|
||||||
|
|
||||||
|
|
@ -82,6 +83,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
m.ui.entryListPage = entryListM
|
m.ui.entryListPage = entryListM
|
||||||
cmds = append(cmds, cmd)
|
cmds = append(cmds, cmd)
|
||||||
|
|
||||||
|
entrytM, cmd := m.ui.entryPage.Update(msg, m.ui.page == Entry, m.context)
|
||||||
|
m.ui.entryPage = entrytM
|
||||||
|
cmds = append(cmds, cmd)
|
||||||
|
|
||||||
return m, tea.Batch(cmds...)
|
return m, tea.Batch(cmds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,10 +99,13 @@ func (m model) View() string {
|
||||||
s += m.ui.notification
|
s += m.ui.notification
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.ui.page == ActionList {
|
switch m.ui.page {
|
||||||
|
case ActionList:
|
||||||
s += m.ui.actionListPage.View()
|
s += m.ui.actionListPage.View()
|
||||||
} else if m.ui.page == EntryList {
|
case EntryList:
|
||||||
s += m.ui.entryListPage.View()
|
s += m.ui.entryListPage.View()
|
||||||
|
case Entry:
|
||||||
|
s += m.ui.entryPage.View()
|
||||||
}
|
}
|
||||||
|
|
||||||
s += "\nPress q to quit.\n"
|
s += "\nPress q to quit.\n"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue