get listing working

This commit is contained in:
Travis Shears 2025-10-01 15:04:08 +02:00
parent 59b46d4902
commit ccf39d829a
6 changed files with 680 additions and 11 deletions

59
main.go
View file

@ -3,6 +3,7 @@ package main
import (
"fmt"
"gemini_site/gemlog"
"log/slog"
"os"
tea "github.com/charmbracelet/bubbletea"
@ -23,10 +24,26 @@ func TODOCmd() tea.Msg {
return gemlog.Notification("This action has not been implemented yet. Try another.")
}
type Page string
const (
ActionList Page = "actionList"
EntryList Page = "entryList"
Entry Page = "entry"
)
type entryListPageModel struct {
entries []gemlog.GemlogListEntry
action Action
}
type uiState struct {
notification string
cursor int
errorTxt string
page Page
entryListPage entryListPageModel
}
type context struct {
@ -41,7 +58,10 @@ type model struct {
func initialModel(config *gemlog.Config) model {
return model{
ui: uiState{
// actions: []Action{Write, Read, Edit, Delete},
page: ActionList,
entryListPage: entryListPageModel{
entries: []gemlog.GemlogListEntry{},
},
},
context: &context{
config: config,
@ -59,6 +79,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.ui.errorTxt = fmt.Sprintf("%s\n\n", fmt.Errorf("%s", msg))
case gemlog.Notification:
m.ui.notification = fmt.Sprintf("%s\n\n", string(msg))
case gemlog.GemLogsLoaded:
m.ui.entryListPage.entries = msg.Logs
m.ui.cursor = 0
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "q":
@ -77,7 +100,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case Write:
return m, gemlog.WritePostCMD(m.context.config)
case Read:
return m, TODOCmd
m.ui.page = EntryList
return m, gemlog.LoadGemlogCMD(m.context.config)
case Edit:
return m, TODOCmd
case Delete:
@ -100,12 +124,26 @@ func (m model) View() string {
s += "Welcome to gemlog cli!\n\nWhat post action would you like to take?\n\n"
}
for i, action := range actions {
cursor := " "
if m.ui.cursor == i {
cursor = ">"
if m.ui.page == ActionList {
for i, action := range actions {
cursor := " "
if m.ui.cursor == i {
cursor = ">"
}
s += fmt.Sprintf("%s %s\n", cursor, action)
}
}
if m.ui.page == EntryList {
slog.Info("rendering entry list", "count", len(m.ui.entryListPage.entries))
for i, entry := range m.ui.entryListPage.entries {
slog.Info("entry", "value", entry)
cursor := " "
if m.ui.cursor == i {
cursor = ">"
}
s += fmt.Sprintf("%s %s : %s\n", cursor, entry.Date, entry.Slug)
}
s += fmt.Sprintf("%s %s\n", cursor, action)
}
s += "\nPress q to quit.\n"
@ -114,6 +152,13 @@ func (m model) View() string {
}
func main() {
f, err := tea.LogToFile("debug.log", "debug")
if err != nil {
fmt.Println("fatal:", err)
os.Exit(1)
}
defer f.Close()
slog.Info("Starting gemlog cli")
config, err := gemlog.LoadConfig()
if err != nil {
fmt.Printf("Error loading config: %v", err)