Skip to content

Commit

Permalink
Merge pull request #4 from treethought/channel-post
Browse files Browse the repository at this point in the history
support casting to channel, better sizing
  • Loading branch information
treethought authored Jun 15, 2024
2 parents 76f3148 + c6938c7 commit 66b3b6a
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 100 deletions.
87 changes: 48 additions & 39 deletions ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (
// TODO provide to models
var renderer *lipgloss.Renderer = lipgloss.DefaultRenderer()

var activeColor = lipgloss.AdaptiveColor{Dark: "#874BFD", Light: "#874BFD"}

var (
mainStyle = lipgloss.NewStyle().Margin(0).Padding(0).Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color("#874BFD"))
mainStyle = lipgloss.NewStyle().Margin(0).Padding(0).Border(lipgloss.RoundedBorder())
)

func NewStyle() lipgloss.Style {
Expand Down Expand Up @@ -49,20 +51,19 @@ type AppContext struct {
}

type App struct {
ctx *AppContext
client *api.Client
cfg *config.Config
focusedModel tea.Model
focused string
navname string
sidebar *Sidebar
showSidebar bool
prev string
prevName string
quickSelect *QuickSelect
showQuickSelect bool
publish *PublishInput
statusLine *StatusLine
ctx *AppContext
client *api.Client
cfg *config.Config
focusedModel tea.Model
focused string
navname string
sidebar *Sidebar
showSidebar bool
prev string
prevName string
quickSelect *QuickSelect
publish *PublishInput
statusLine *StatusLine
// signinPrompt *SigninPrompt
splash *SplashView
help *HelpView
Expand Down Expand Up @@ -150,8 +151,8 @@ func (a *App) SetNavName(name string) {
}

func (a *App) focusMain() {
if a.showQuickSelect {
a.showQuickSelect = false
if a.quickSelect.Active() {
a.quickSelect.SetActive(false)
}
if a.publish.Active() {
a.publish.SetActive(false)
Expand Down Expand Up @@ -245,10 +246,10 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg.activeOnly {
_, cmd := a.sidebar.Update(msg)
return a, cmd
} else {
_, cmd := a.quickSelect.Update(msg.channels)
return a, cmd
}
_, qcmd := a.quickSelect.Update(msg.channels)
_, pcmd := a.publish.Update(msg.channels)
return a, tea.Batch(qcmd, pcmd)
case *feedLoadedMsg:
a.splash.SetActive(false)
case *channelInfoMsg:
Expand Down Expand Up @@ -277,25 +278,28 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
_, statusHeight := lipgloss.Size(a.statusLine.View())

wx, wy := msg.Width, msg.Height-statusHeight
fx, fy := mainStyle.GetFrameSize()
wx = wx - fx
wy = wy - fy

sideMax := 30
sidePct := int(float64(wx) * 0.2)
sx := sidePct
if sideMax < sidePct {
sx = sideMax
}
a.sidebar.SetSize(sx, wy-4)
spx := min(80, wx-10)
spy := min(80, wy-10)

a.splash.SetSize(spx, spy)

sx := min(30, int(float64(wx)*0.2))
a.sidebar.SetSize(sx, wy-statusHeight)
sideWidth, _ := lipgloss.Size(a.sidebar.View())

pw := wx - sideWidth
py := wy - 10
a.publish.SetSize(pw, py)
a.splash.SetSize(pw, py)
a.quickSelect.SetSize(pw, py)
a.help.SetSize(pw, py)
mx := wx - sideWidth
mx = min(mx, int(float64(wx)*0.8))

fx, fy := mainStyle.GetFrameSize()
mx, my := wx-sideWidth-fx-4, wy-fy
my := min(wy, int(float64(wy)*0.9))

dialogX, dialogY := int(float64(mx)*0.8), int(float64(my)*0.8)
a.publish.SetSize(dialogX, dialogY)
a.quickSelect.SetSize(dialogX, dialogY)
a.help.SetSize(dialogX, dialogY)

childMsg := tea.WindowSizeMsg{
Width: mx,
Expand Down Expand Up @@ -338,7 +342,7 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
_, cmd := a.publish.Update(msg)
return a, cmd
}
if a.showQuickSelect {
if a.quickSelect.Active() {
q, cmd := a.quickSelect.Update(msg)
a.quickSelect = q.(*QuickSelect)
return a, cmd
Expand Down Expand Up @@ -376,13 +380,14 @@ func (a *App) View() string {
main := focus.View()
side := a.sidebar.View()
if a.splash.Active() {
main = a.splash.View()
main = lipgloss.Place(GetWidth(), GetHeight(), lipgloss.Center, lipgloss.Center, a.splash.View())
return main
}

if a.publish.Active() {
main = a.publish.View()
}
if a.showQuickSelect {
if a.quickSelect.Active() {
main = a.quickSelect.View()
}
if !a.showSidebar {
Expand All @@ -393,7 +398,11 @@ func (a *App) View() string {
main = a.help.View()
}

main = mainStyle.Render(main)
ss := mainStyle
if !a.sidebar.Active() {
ss = ss.BorderForeground(activeColor)
}
main = ss.Render(main)

return lipgloss.JoinVertical(lipgloss.Top,
lipgloss.JoinHorizontal(lipgloss.Center, side, main),
Expand Down
14 changes: 7 additions & 7 deletions ui/cast_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,29 @@ func (m *CastView) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds := []tea.Cmd{}

fx, fy := style.GetFrameSize()
w := min(msg.Width-fx, int(float64(GetWidth())*0.75))
h := min(msg.Height-fy, GetHeight()-4)

w, h := msg.Width-fx, msg.Height-fy
m.w, m.h = w, h

m.header.Width = w
m.header.Height = min(10, int(float64(h)*0.2))

hHeight := lipgloss.Height(m.header.View())

cx, cy := w, h-hHeight
cy := h - hHeight

m.vp.Width = cx
m.vp.Height = int(float64(cy) * 0.5)
m.vp.Width = w - fx
m.vp.Height = int(float64(cy) * 0.5) //- fy

m.img.SetSize(0, 0)

if m.hasImg {
m.img.SetSize(4, 4)
m.vp.Height = int(float64(cy) * 0.25)
}
m.replies.SetSize(msg.Width, int(float64(cy)*0.5))
m.replies.SetSize(w, int(float64(cy)*0.5))

m.pubReply.SetSize(msg.Width, msg.Height-10)
m.pubReply.SetSize(m.w, m.h)
return m, tea.Batch(cmds...)

case *ctxInfoMsg:
Expand Down
7 changes: 5 additions & 2 deletions ui/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,14 @@ func (m *FeedView) SetSize(w, h int) {

_, dy := lipgloss.Size(channelHeaderStyle.Render(m.descVp.View()))
fx, fy := feedStyle.GetFrameSize()
m.table.SetWidth(w - fx)
x := min(w-fx, int(float64(GetWidth())*0.75))
m.table.SetWidth(x)
m.table.SetHeight(h - fy - dy)

// m.table.SetWidth(w -fx)
m.setTableConfig()

lw := int(float64(w) * 0.2)
lw := int(float64(w) * 0.75)
m.loading.SetSize(lw, h)
}

Expand Down
4 changes: 2 additions & 2 deletions ui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (k navKeymap) HandleMsg(a *App, msg tea.KeyMsg) tea.Cmd {
return noOp()

case key.Matches(msg, k.QuickSelect):
a.showQuickSelect = true
a.quickSelect.SetActive(true)
return nil

case key.Matches(msg, k.Help):
Expand All @@ -172,7 +172,7 @@ func (k navKeymap) HandleMsg(a *App, msg tea.KeyMsg) tea.Cmd {
return noOp()

case key.Matches(msg, k.ToggleSidebarFocus):
if a.showQuickSelect {
if a.quickSelect.Active() {
_, cmd := a.quickSelect.Update(msg)
return cmd
}
Expand Down
Loading

0 comments on commit 66b3b6a

Please sign in to comment.