diff --git a/asuka.json b/asuka.json index efc0028..e0e41d8 100644 --- a/asuka.json +++ b/asuka.json @@ -1,7 +1,7 @@ { "name": "OpenChamber", "id": "com.openchamber.native", - "version": "0.1.8", - "build": 9, + "version": "0.1.9", + "build": 10, "orientations": ["portrait", "landscape"] } diff --git a/internal/appui/chat.go b/internal/appui/chat.go index 0e43b03..cb2c74c 100644 --- a/internal/appui/chat.go +++ b/internal/appui/chat.go @@ -60,6 +60,9 @@ type chat struct { modelNames *signal.Signal[map[string]string] + footerOpen *signal.Signal[bool] + footerID *signal.Signal[string] + pickerOpen *signal.Signal[bool] pickerKind string pickerItems *signal.Signal[[]pickerItem] @@ -100,6 +103,8 @@ func (c *controller) openChat(s *ocapi.Session, nav *ui.Navigator) *chat { permList: signal.NewFunc([]ocapi.PermissionRequest{}, nil), hasPerms: signal.New(false), modelNames: signal.NewFunc(map[string]string{}, nil), + footerOpen: signal.New(false), + footerID: signal.New(""), pickerOpen: signal.New(false), pickerItems: signal.NewFunc([]pickerItem{}, nil), pickerFilter: signal.New(""), @@ -226,27 +231,58 @@ func (ch *chat) copyAnswer(id string) { } func (ch *chat) footerMenu(id string) { - m := ch.byID.Peek()[id] - label := ch.modelName(m.Model) - if label == "" { - label = "回答" - } - stamp := "" - if m.Time.Completed > 0 { - stamp = time.UnixMilli(m.Time.Completed).Format("2006-01-02 15:04") - } - ui.Alert(ui.AlertProps{ - Title: label, - Message: stamp, - ActionSheet: true, - Actions: []ui.Action{ - {Title: ui.Val("复制回答"), Icon: "doc.on.doc", OnPress: func() { ch.copyAnswer(id) }}, - {Title: ui.Val("从这里分叉"), OnPress: func() { ch.forkFrom(id) }}, - {Title: ui.Val("取消"), Role: ui.ActionCancel}, + ch.footerID.Set(id) + ch.footerOpen.Set(true) +} + +// footerSheet is the "more" panel: the completion time, then the actions, +// as the first-party client shows on touch screens. +func (ch *chat) footerSheet() ui.Node { + return ui.Sheet(ui.SheetProps{ + Open: ch.footerOpen, + Detents: ui.DetentMedium, + Grabber: true, + OnDismiss: func() { ch.footerOpen.Set(false) }, + Content: func() ui.Node { + id := ch.footerID.Peek() + m := ch.byID.Peek()[id] + stamp := "" + if m.Time.Completed > 0 { + stamp = time.UnixMilli(m.Time.Completed).Format("2006-01-02 15:04") + } + act := func(f func()) func() { + return func() { + ch.footerOpen.Set(false) + f() + } + } + return ui.SafeArea(ui.Style{Padding: ui.All(20), Gap: 4}, + ui.StaticText("更多操作", ui.Style{Font: fonts.Footnote, Color: colors.SecondaryLabel}), + ui.Show(signal.Func(func() bool { return stamp != "" }), func() ui.Node { + return ui.Row(ui.Style{Padding: ui.Symmetric(8, 0), Gap: 8, Align: ui.AlignCenter}, + ui.Symbol(ui.Icon("clock"), ui.Style{Font: fonts.Footnote, Color: colors.SecondaryLabel}), + ui.StaticText(stamp, ui.Style{Font: fonts.Footnote, Color: colors.SecondaryLabel}), + ) + }), + sheetAction("复制回答", "doc.on.doc", act(func() { ch.copyAnswer(id) })), + sheetAction("从这里分叉", "", act(func() { ch.forkFrom(id) })), + ) }, }) } +func sheetAction(title string, icon ui.Icon, onPress func()) ui.Node { + parts := make([]ui.Node, 0, 2) + if icon != "" { + parts = append(parts, ui.Symbol(icon, ui.Style{Font: fonts.Body, Color: colors.SecondaryLabel})) + } + parts = append(parts, ui.StaticText(title, ui.Style{Font: fonts.Body})) + return ui.View(ui.ViewProps{ + OnPress: onPress, + Style: ui.Style{Padding: ui.Symmetric(12, 4), Align: ui.AlignCenter}, + }, ui.Row(ui.Style{Gap: 12, Align: ui.AlignCenter}, parts...)) +} + func (ch *chat) forkFrom(id string) { client := ch.client() if client == nil { @@ -622,6 +658,7 @@ func (ch *chat) screen() ui.Node { ch.permissionSection(), ch.composer(), ), + ch.footerSheet(), ui.Sheet(ui.SheetProps{ Open: ch.pickerOpen, Detents: ui.DetentLarge, diff --git a/internal/appui/chat_test.go b/internal/appui/chat_test.go index 3ac1eaa..f16d871 100644 --- a/internal/appui/chat_test.go +++ b/internal/appui/chat_test.go @@ -309,7 +309,7 @@ func TestTurnFooter(t *testing.T) { a.Tap("更多操作") a.WaitFor("复制回答") a.Expect("从这里分叉") - a.Tap("取消") + a.Back() } func TestForkFromTurnFooter(t *testing.T) {