move actions list to seprate file
This commit is contained in:
parent
f74f50c148
commit
4d1f3f2f3e
2 changed files with 129 additions and 106 deletions
84
actionsList.go
Normal file
84
actionsList.go
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gemini_site/gemlog"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type Action string
|
||||
|
||||
const (
|
||||
Write Action = "write"
|
||||
Read Action = "read"
|
||||
Edit Action = "edit"
|
||||
Delete Action = "delete"
|
||||
)
|
||||
|
||||
var actions = []Action{Write, Read, Edit, Delete}
|
||||
|
||||
type ActionListPageModel struct {
|
||||
cursor int
|
||||
}
|
||||
|
||||
func initialActionListPageModel() ActionListPageModel {
|
||||
return ActionListPageModel{
|
||||
cursor: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (m ActionListPageModel) InitActionListPage() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m ActionListPageModel) Update(msg tea.Msg, ctx *context) (ActionListPageModel, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
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 ActionListPageModel) 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.cursor == i {
|
||||
cursor = ">"
|
||||
}
|
||||
s += fmt.Sprintf("%s %s\n", cursor, action)
|
||||
}
|
||||
return s
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue