While disconnected the screen is the bare list with its own heading; the navigation stack (and its new-session and refresh actions) exists only once connected. That removes the duplicate title and the buttons that could do nothing without a session. Bump version to 0.1.6 (build 7).
102 lines
3.3 KiB
Go
102 lines
3.3 KiB
Go
package appui
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/egoist/asuka/colors"
|
|
"github.com/egoist/asuka/fonts"
|
|
"github.com/egoist/asuka/signal"
|
|
"github.com/egoist/asuka/ui"
|
|
"github.com/openchamber/openchamber-native/internal/ocapi"
|
|
)
|
|
|
|
func (c *controller) sessionsScreen() ui.Node {
|
|
nav := ui.UseNavigator()
|
|
c.nav = nav
|
|
return ui.SafeArea(ui.Style{Grow: 1}, ui.Column(ui.Style{Grow: 1},
|
|
ui.Row(ui.Style{Padding: ui.Symmetric(8, 16), Gap: 4, Align: ui.AlignCenter},
|
|
ui.Column(ui.Style{Grow: 1, Gap: 2},
|
|
ui.Text(c.server, ui.Style{Font: fonts.Footnote, Color: colors.SecondaryLabel, Lines: 1}),
|
|
ui.Show(signal.Func(func() bool { return c.errorMsg.Get() != "" }),
|
|
func() ui.Node {
|
|
return ui.Text(c.errorMsg, ui.Style{Font: fonts.Footnote, Color: colors.Red, Lines: 2})
|
|
}),
|
|
),
|
|
c.instancesButton(),
|
|
),
|
|
ui.Show(signal.Func(func() bool { return len(c.sessions.Get()) == 0 }),
|
|
func() ui.Node {
|
|
return ui.Column(ui.Style{Padding: ui.All(20), Gap: 8},
|
|
ui.StaticText("还没有会话", ui.Style{Font: fonts.Headline}),
|
|
ui.Text(c.status, ui.Style{Color: colors.SecondaryLabel}),
|
|
)
|
|
}),
|
|
ui.List(ui.ListProps{
|
|
Appearance: ui.ListPlain,
|
|
OnRefresh: c.refresh,
|
|
Refreshing: c.busy,
|
|
SwipeActions: func(i int) []ui.Action {
|
|
sess := c.sessions.Peek()[i]
|
|
return []ui.Action{{Title: ui.Val("归档"), Icon: "archivebox",
|
|
OnPress: func() { c.archiveSession(sess) }}}
|
|
},
|
|
LeadingSwipeActions: func(i int) []ui.Action {
|
|
sess := c.sessions.Peek()[i]
|
|
return []ui.Action{{Title: ui.Val("删除"), Icon: ui.IconTrash, Role: ui.ActionDestructive,
|
|
OnPress: func() { c.confirmDelete(sess) }}}
|
|
},
|
|
}, c.sessions, func(s ocapi.Session) string { return s.ID },
|
|
func(s signal.Accessor[ocapi.Session], idx signal.Accessor[int]) ui.Node {
|
|
return ui.View(ui.ViewProps{
|
|
OnPress: func() {
|
|
sess := s.Get()
|
|
ch := c.openChat(&sess, nav)
|
|
nav.Push(ch.screen, ui.ScreenOptions{Title: ch.title, Actions: chatActions(ch)})
|
|
},
|
|
OnLongPress: func() { c.sessionMenu(s.Get()) },
|
|
}, c.sessionRow(s, idx))
|
|
}),
|
|
))
|
|
}
|
|
|
|
func (c *controller) sessionRow(s signal.Accessor[ocapi.Session], _ signal.Accessor[int]) ui.Node {
|
|
return ui.Row(ui.Style{Gap: 10, Padding: ui.Symmetric(10, 16), Align: ui.AlignCenter},
|
|
ui.Show(signal.Func(func() bool { return c.active.Get()[s.Get().ID] }),
|
|
func() ui.Node {
|
|
return ui.View(ui.ViewProps{Style: ui.Style{Width: ui.Pt(8), Height: ui.Pt(8),
|
|
CornerRadius: 4, Background: colors.Accent}})
|
|
}),
|
|
ui.Column(ui.Style{Gap: 3, Grow: 1},
|
|
ui.Text(signal.Func(func() string {
|
|
if t := strings.TrimSpace(s.Get().Title); t != "" {
|
|
return t
|
|
}
|
|
return "(未命名会话)"
|
|
}), ui.Style{Font: fonts.Headline, Lines: 2}),
|
|
ui.Text(signal.Func(func() string {
|
|
sess := s.Get()
|
|
dir := ""
|
|
if sess.Location != nil {
|
|
dir = sess.Location.Directory
|
|
}
|
|
updated := sess.Time.Updated
|
|
if sess.Time.Busy > updated {
|
|
updated = sess.Time.Busy
|
|
}
|
|
model := ""
|
|
if sess.Model != nil {
|
|
model = sess.Model.ID
|
|
}
|
|
parts := []string{shortPath(dir), relativeTime(updated), model}
|
|
out := make([]string, 0, len(parts))
|
|
for _, p := range parts {
|
|
if p != "" {
|
|
out = append(out, p)
|
|
}
|
|
}
|
|
return strings.Join(out, " · ")
|
|
}), ui.Style{Font: fonts.Footnote, Color: colors.SecondaryLabel, Lines: 1}),
|
|
),
|
|
)
|
|
}
|