Skip to content

Commit

Permalink
better loading
Browse files Browse the repository at this point in the history
  • Loading branch information
treethought committed Jun 10, 2024
1 parent 2adc8f8 commit 36e5eb4
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ tofui

dist/
.tofui
.db
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ build:
go build -o ./tofui

clean:
rm -rf /tmp/tofui
rm -rf ~/.tofui/db

start:
go run cmd/main.go run -c examples/config.yaml

deploy:
@echo "Deploying as user: ${DEPLOY_USER}"
ssh ${DEPLOY_USER}@${DEPLOY_HOST} "sudo systemctl stop tofui"
scp ./tofui ${DEPLOY_USER}@${DEPLOY_HOST}:/usr/bin/
scp config.yaml ${DEPLOY_USER}@${DEPLOY_HOST}:/etc/tofui/config.yaml
scp tofui.yaml ${DEPLOY_USER}@${DEPLOY_HOST}:/etc/tofui/config.yaml
ssh ${DEPLOY_USER}@${DEPLOY_HOST} "sudo systemctl daemon-reload && sudo systemctl start tofui"

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

tofui (Terminally On Farcaster User Interface) is a TUI for [farcaster](https://www.farcaster.xyz/).

It supports running locally using your own [Neynar](https://neynar.com/) application, or as a hosted SSH app using [wish](https://github.com/charmbracelet/wish)
It supports running locally using your own [Neynar](https://neynar.com/) application, or as a hosted SSH app using [wish](https://github.com/charmbracelet/wish).

![tofui screenshot](./media/screenshot.png)

Expand All @@ -13,6 +13,8 @@ Use a hosted instance of tofui over ssh

```
ssh -p 42069 tofui.xyz
(Note this is WIP and may be slow / unavailable)
```

### SSH Sessions, Authentication and Details
Expand Down
23 changes: 17 additions & 6 deletions ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (a *App) FocusPrev() tea.Cmd {

func (a *App) Init() tea.Cmd {
cmds := []tea.Cmd{}
cmds = append(cmds, a.sidebar.Init(), a.quickSelect.Init(), a.publish.Init())
cmds = append(cmds, a.splash.Init(), a.sidebar.Init(), a.quickSelect.Init(), a.publish.Init())
focus := a.GetFocused()
if focus != nil {
cmds = append(cmds, focus.Init())
Expand Down Expand Up @@ -269,8 +269,11 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
_, cmd := a.quickSelect.Update(msg.channels)
return a, cmd
}
case *api.FeedResponse:
case *feedLoadedMsg:
a.splash.SetActive(false)
case *channelInfoMsg:
a.splash.SetInfo(msg.channel.Name)
case *api.FeedResponse:
// allow msg to pass through to profile's embedded feed
if a.focused == "profile" {
_, cmd := a.GetFocused().Update(msg)
Expand All @@ -279,6 +282,7 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
feed := a.GetModel("feed").(*FeedView)
feed.Clear()
focusCmd := a.SetFocus("feed")
a.splash.SetInfo("loading channels...")
return a, tea.Batch(feed.setItems(msg.Casts), focusCmd)
case SelectProfileMsg:
focusCmd := a.SetFocus("profile")
Expand Down Expand Up @@ -338,6 +342,13 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds = append(cmds, cmd)
}
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "q":
return a, tea.Quit
}
if a.splash.Active() {
return a, nil
}
if a.publish.Active() {
_, cmd := a.publish.Update(msg)
return a, cmd
Expand All @@ -348,14 +359,14 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return a, cmd
}

switch msg.String() {
case "ctrl+c", "q":
return a, tea.Quit
}
case *currentAccountMsg:
_, cmd := a.sidebar.Update(msg)
return a, cmd
}
if a.splash.Active() {
_, cmd := a.splash.Update(msg)
return a, cmd
}
if a.signinPrompt.Active() {
_, cmd := a.signinPrompt.Update(msg)
return a, cmd
Expand Down
8 changes: 4 additions & 4 deletions ui/cast_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ func getCastChannelCmd(client *api.Client, cast *api.Cast) tea.Cmd {
}
ch, err := client.GetChannelByParentUrl(cast.ParentURL)
if err != nil {
return channelInfoErrMsg{err, cast.Hash, cast.ParentURL}
return &channelInfoErrMsg{err, cast.Hash, cast.ParentURL}
}
return channelInfoMsg{ch, cast.Hash, cast.ParentURL}
return &channelInfoMsg{ch, cast.Hash, cast.ParentURL}
}
}

Expand Down Expand Up @@ -164,11 +164,11 @@ func (m *CastFeedItem) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
cmds := []tea.Cmd{}
switch msg := msg.(type) {
case channelInfoErrMsg:
case *channelInfoErrMsg:
if msg.cast != m.cast.Hash {
return m, nil
}
case channelInfoMsg:
case *channelInfoMsg:
if msg.cast != m.cast.Hash {
return m, nil
}
Expand Down
8 changes: 8 additions & 0 deletions ui/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var (
docStyle = NewStyle().Margin(2, 2).Align(lipgloss.Center)
)

type feedLoadedMsg struct{}

type apiErrorMsg struct {
err error
}
Expand Down Expand Up @@ -201,6 +203,12 @@ func (m *FeedView) setItems(casts []*api.Cast) tea.Cmd {
}
m.table.SetRows(rows)
m.loading.SetActive(false)

done := func() tea.Msg {
return &feedLoadedMsg{}
}
cmds = append(cmds, done)

return tea.Batch(cmds...)
}

Expand Down
6 changes: 3 additions & 3 deletions ui/loading.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func tickCmd() tea.Cmd {
}

type Loading struct {
prog progress.Model
prog *progress.Model
active bool
pct float64
}
Expand All @@ -26,7 +26,7 @@ func NewLoading() *Loading {
p.ShowPercentage = false
return &Loading{
active: true,
prog: p,
prog: &p,
}
}

Expand Down Expand Up @@ -62,7 +62,7 @@ func (m *Loading) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !m.active {
return m, nil
}
m.pct = m.pct + 0.25
m.pct = m.pct + 0.1
if m.pct > 1 {
m.pct = 0
}
Expand Down
54 changes: 0 additions & 54 deletions ui/spalsh.go

This file was deleted.

90 changes: 90 additions & 0 deletions ui/splash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package ui

import (
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)

var txt = `
████████╗ ██████╗ ███████╗██╗ ██╗██╗
╚══██╔══╝██╔═══██╗██╔════╝██║ ██║██║
██║ ██║ ██║█████╗ ██║ ██║██║
██║ ██║ ██║██╔══╝ ██║ ██║██║
██║ ╚██████╔╝██║ ╚██████╔╝██║
╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝
Terminally On Farcaster User Interface
`

var splashStyle = NewStyle().Align(lipgloss.Center).Margin(2, 2)

type SplashView struct {
vp *viewport.Model
info *viewport.Model
loading *Loading
active bool
spinner *spinner.Model
}

func NewSplashView() *SplashView {
x, y := lipgloss.Size(txt)
vp := viewport.New(x, y)
vp.SetContent(txt)
l := NewLoading()
l.SetActive(true)
info := viewport.New(20, 6)
info.SetContent("fetching feed...")
s := spinner.New()
s.Spinner = spinner.Dot
s.Style = NewStyle().Foreground(lipgloss.Color("205"))
return &SplashView{vp: &vp, loading: l, info: &info, active: true, spinner: &s}
}

func (m *SplashView) Active() bool {
return m.active
}
func (m *SplashView) SetActive(active bool) {
m.loading.SetActive(active)
m.active = active
}

func (m *SplashView) SetInfo(content string) {
m.info.SetContent(content)
}

func (m *SplashView) SetSize(w, h int) {
x, y := splashStyle.GetFrameSize()
m.vp.Width = w - x
m.vp.Height = h - y - 4
m.info.Width = w - x
m.info.Height = h - y - 8
m.loading.SetSize((w-x)/2, h)
}

func (m *SplashView) Init() tea.Cmd {
return tea.Batch(m.loading.Init(), m.spinner.Tick)
}
func (m *SplashView) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !m.active {
return m, nil
}
cmds := []tea.Cmd{}
_, lcmd := m.loading.Update(msg)
cmds = append(cmds, lcmd)
_, scmd := m.spinner.Update(msg)
cmds = append(cmds, scmd)

cmds = append(cmds, m.spinner.Tick)
return m, tea.Batch(cmds...)
}
func (m *SplashView) View() string {
return splashStyle.Render(
lipgloss.JoinVertical(lipgloss.Top,
m.vp.View(),
lipgloss.NewStyle().MarginTop(1).Render(m.loading.View()),
lipgloss.JoinHorizontal(lipgloss.Left, m.spinner.View(), " ", m.info.View()),
),
)
}

0 comments on commit 36e5eb4

Please sign in to comment.