Reach the first-party mobile client's everyday features: - sessions: a search button opens a field; typing asks the server with its search parameter (350 ms settle) and clearing restores the list - composer: attach photos or files (up to five, 10 MB each) as data URLs with the prompt; attachments show as removable chips and are named under the sent message - turn menu: read the answer aloud with the system voice, or stop it - chat: a "latest" button appears after scrolling up and returns to the end of the conversation - reset a live search when a connection ends Bump version to 0.2.0 (build 14).
138 lines
4.4 KiB
Go
138 lines
4.4 KiB
Go
package appui
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
"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
|
|
// Live search: typing settles for a moment, then the server is asked.
|
|
signal.Effect(func() {
|
|
q := c.sessionQuery.Get()
|
|
if !c.searchOpen.Get() {
|
|
return
|
|
}
|
|
t := time.AfterFunc(350*time.Millisecond, func() {
|
|
ui.Post(func() { c.searchSessions(q) })
|
|
})
|
|
signal.OnCleanup(func() { t.Stop() })
|
|
})
|
|
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})
|
|
}),
|
|
),
|
|
ui.Button(ui.ButtonProps{Icon: ui.IconSearch, Label: ui.Val("搜索会话"),
|
|
OnPress: func() {
|
|
open := !c.searchOpen.Peek()
|
|
c.searchOpen.Set(open)
|
|
if !open {
|
|
c.sessionQuery.Set("")
|
|
c.searchSessions("")
|
|
}
|
|
}}),
|
|
c.instancesButton(),
|
|
),
|
|
ui.Show(c.searchOpen, func() ui.Node {
|
|
return ui.Row(ui.Style{Padding: ui.Symmetric(0, 12), Gap: 6, Align: ui.AlignCenter},
|
|
ui.TextField(ui.TextFieldProps{
|
|
Value: c.sessionQuery,
|
|
Placeholder: ui.Val("输入关键词搜索"),
|
|
ReturnKey: ui.ReturnSearch,
|
|
OnSubmit: func() { c.searchSessions(c.sessionQuery.Peek()) },
|
|
Style: ui.Style{Grow: 1},
|
|
}),
|
|
ui.Button(ui.ButtonProps{Title: ui.Val("清除"), OnPress: func() {
|
|
c.sessionQuery.Set("")
|
|
c.searchSessions("")
|
|
}}),
|
|
)
|
|
}),
|
|
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}),
|
|
),
|
|
)
|
|
}
|