Skip to content

Commit

Permalink
refactor(tui): chat page to describe how it works with senpai
Browse files Browse the repository at this point in the history
We also notify the user that chat is pico+ only
  • Loading branch information
neurosnap committed Dec 17, 2024
1 parent 6886a8e commit b3374e6
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ services:
volumes:
- ./data/storage/data:/app/.storage
- ./data/pgs-ssh/data:/app/ssh_data
deploy:
resources:
limits:
memory: 3g
pgs-ssh:
networks:
pgs:
Expand Down
84 changes: 84 additions & 0 deletions tui/chat/chat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package chat

import (
tea "github.com/charmbracelet/bubbletea"
"github.com/picosh/pico/tui/common"
"github.com/picosh/pico/tui/pages"
)

var maxWidth = 55

type focus int

const (
focusNone = iota
focusChat
)

type Model struct {
shared *common.SharedModel
focus focus
}

func NewModel(shrd *common.SharedModel) Model {
return Model{
shared: shrd,
focus: focusChat,
}
}

func (m Model) Init() tea.Cmd {
return nil
}

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "q", "esc":
return m, pages.Navigate(pages.MenuPage)
case "tab":
if m.focus == focusNone {
m.focus = focusChat
} else {
m.focus = focusNone
}
case "enter":
if m.focus == focusChat {
return m, m.gotoChat()
}
}
}
return m, nil
}

func (m Model) View() string {
return m.analyticsView()
}

func (m Model) analyticsView() string {
banner := `We provide a managed IRC bouncer for pico+ users. When you click the button we will open our TUI chat with your user authenticated automatically.
If you haven't configured your pico+ account with our IRC bouncer, the guide is here:
https://pico.sh/bouncer
If you want to quickly chat with us on IRC without pico+, go to the web chat:
https://web.libera.chat/gamja?autojoin=#pico.sh`

str := ""
hasPlus := m.shared.PlusFeatureFlag != nil
if hasPlus {
hasFocus := m.focus == focusChat
str += banner + "\n\nLet's Chat! " + common.OKButtonView(m.shared.Styles, hasFocus, true)
} else {
str += banner + "\n\n" + m.shared.Styles.Error.SetString("Our IRC Bouncer is only available to pico+ users.").String()
}

return m.shared.Styles.RoundedBorder.Width(maxWidth).SetString(str).String()
}

func (m Model) gotoChat() tea.Cmd {
return LoadChat(m.shared)
}
2 changes: 1 addition & 1 deletion tui/senpai.go → tui/chat/senpai.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tui
package chat

import (
"io"
Expand Down
3 changes: 3 additions & 0 deletions tui/pages/pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
SettingsPage
LogsPage
AnalyticsPage
ChatPage
)

type NavigateMsg struct{ Page }
Expand Down Expand Up @@ -50,6 +51,8 @@ func ToTitle(page Page) string {
return "logs"
case AnalyticsPage:
return "analytics"
case ChatPage:
return "chat"
}

return ""
Expand Down
6 changes: 4 additions & 2 deletions tui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/muesli/reflow/wordwrap"
"github.com/muesli/reflow/wrap"
"github.com/picosh/pico/tui/analytics"
"github.com/picosh/pico/tui/chat"
"github.com/picosh/pico/tui/common"
"github.com/picosh/pico/tui/createaccount"
"github.com/picosh/pico/tui/createkey"
Expand Down Expand Up @@ -43,7 +44,7 @@ func NewUI(shared *common.SharedModel) *UI {
m := &UI{
shared: shared,
state: initState,
pages: make([]tea.Model, 11),
pages: make([]tea.Model, 12),
}
return m
}
Expand Down Expand Up @@ -86,6 +87,7 @@ func (m *UI) Init() tea.Cmd {
m.pages[pages.SettingsPage] = settings.NewModel(m.shared)
m.pages[pages.LogsPage] = logs.NewModel(m.shared)
m.pages[pages.AnalyticsPage] = analytics.NewModel(m.shared)
m.pages[pages.ChatPage] = chat.NewModel(m.shared)
if m.shared.User == nil {
m.activePage = pages.CreateAccountPage
} else {
Expand Down Expand Up @@ -153,7 +155,7 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case menu.AnalyticsChoice:
m.activePage = pages.AnalyticsPage
case menu.ChatChoice:
return m, LoadChat(m.shared)
m.activePage = pages.ChatPage
case menu.ExitChoice:
m.shared.Dbpool.Close()
return m, tea.Quit
Expand Down

0 comments on commit b3374e6

Please sign in to comment.