1
0
Fork 0

Added Info to Forum, polished Forums selector

This commit is contained in:
マリウス 2023-01-05 20:47:20 -05:00
parent 42e9987d29
commit 6656710329
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
9 changed files with 34 additions and 6 deletions

View File

@ -43,7 +43,7 @@ func (a *Aggregator) ListForums() ([]forum.Forum, []error) {
}
sort.SliceStable(forums, func(i, j int) bool {
return strings.Compare(forums[i].Name, forums[j].Name) == -1
return strings.Compare(forums[i].Title(), forums[j].Title()) == -1
})
return forums, errs

View File

@ -1,9 +1,13 @@
package forum
import "strings"
type Forum struct {
ID string
Name string
Info string
SysIDX int
}
@ -12,9 +16,9 @@ func (forum Forum) FilterValue() string {
}
func (forum Forum) Title() string {
return forum.Name
return strings.Title(forum.Name)
}
func (forum Forum) Description() string {
return forum.ID
return forum.Info
}

View File

@ -132,6 +132,8 @@ func (sys *System) ListForums() ([]forum.Forum, error) {
ID: strconv.Itoa(cat.ID),
Name: cat.Name,
Info: cat.Description,
SysIDX: sys.ID,
})
}

View File

@ -101,31 +101,37 @@ func (sys *System) ListForums() ([]forum.Forum, error) {
{
ID: "top",
Name: "Top HN Stories",
Info: "Top stories on Hacker News",
SysIDX: sys.ID,
},
{
ID: "best",
Name: "Best HN Stories",
Info: "Best stories on Hacker News",
SysIDX: sys.ID,
},
{
ID: "new",
Name: "New HN Stories",
Info: "New stories on Hacker News",
SysIDX: sys.ID,
},
{
ID: "ask",
Name: "Ask HN",
Info: "Ask Hacker News about the world",
SysIDX: sys.ID,
},
{
ID: "show",
Name: "Show HN",
Info: "Show Hacker News something awesome",
SysIDX: sys.ID,
},
{
ID: "jobs",
Name: "Jobs HN",
Info: "... because we can't *all* become Astronauts",
SysIDX: sys.ID,
},
}, nil

View File

@ -142,6 +142,8 @@ func (sys *System) ListForums() ([]forum.Forum, error) {
ID: strconv.Itoa(i.Community.ID),
Name: i.Community.Name,
Info: i.Community.Description.ValueOr(i.Community.Title),
SysIDX: sys.ID,
})
}

View File

@ -126,7 +126,9 @@ func (sys *System) ListForums() ([]forum.Forum, error) {
for _, tag := range *tags {
models = append(models, forum.Forum{
ID: tag.Tag,
Name: tag.Description,
Name: tag.Tag,
Info: tag.Description,
SysIDX: sys.ID,
})

View File

@ -64,23 +64,31 @@ func (m Model) View() string {
var row string
var spinner string = ""
selectorWidth := 40
selectorTextLen := selectorWidth - 7
selector := lipgloss.NewStyle().
Foreground(lipgloss.Color("#7fffd4")).
BorderForeground(lipgloss.Color("#7fffd4")).
Border(lipgloss.NormalBorder()).
Padding(0, 1, 0, 1).
Width(40)
Width(selectorWidth)
curSysIdx := m.ctx.GetCurrentSystem()
var currentSystem string = "All"
if curSysIdx >= 0 {
currentSystem = (*m.ctx.Systems[curSysIdx]).Title()
if len(currentSystem) > selectorTextLen {
currentSystem = currentSystem[0:selectorTextLen]
}
}
curForum := m.ctx.GetCurrentForum()
var currentForum string = "All"
if curForum.ID != "" {
currentForum = curForum.Title()
if len(currentForum) > selectorTextLen {
currentForum = currentForum[0:selectorTextLen]
}
}
systemSelector := selector.Render(fmt.Sprintf("⏷ %s", currentSystem))

View File

@ -110,6 +110,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, m.keymap.NewPost):
i, ok := m.list.SelectedItem().(post.Post)
if ok {
m.focused = false // TODO: Refactor and use ToolKit
m.viewcache = m.buildView(false)
cmd := cmd.New(
cmd.WinOpen,
@ -124,6 +125,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
},
)
cmds = append(cmds, cmd.Tea())
return m, tea.Batch(cmds...)
}
}

View File

@ -35,7 +35,9 @@ func buildView(mi interface{}, cached bool) string {
title += fmt.Sprintf(" to reply #%d", m.replyToIdx)
}
} else if m.action == "post" {
title = fmt.Sprintf("New Post in %s", m.iface.(*post.Post).Forum.Name)
p := m.iface.(*post.Post)
sysTitle := (*m.ctx.Systems[p.SysIDX]).Title()
title = fmt.Sprintf("New Post in %s on %s", p.Forum.Name, sysTitle)
}
// textinputWidth := m.tk.ViewWidth() - 2