diff --git a/internal/ui/search_creators.go b/internal/ui/search_creators.go index 9247e6bc..03fd71f4 100644 --- a/internal/ui/search_creators.go +++ b/internal/ui/search_creators.go @@ -19,6 +19,7 @@ import ( type creatorResult struct { items []app.SearchItem + total int err error } @@ -27,6 +28,7 @@ type creatorPreview struct { cancel context.CancelFunc result <-chan creatorResult items []app.SearchItem + total int err error fetch func(context.Context, string) ([]app.SearchItem, error) @@ -77,7 +79,7 @@ func (s *Shell) syncCreatorPreview(keyword string) { keyword = strings.TrimSpace(keyword) if p.keyword != keyword { p.stop() - p.keyword, p.items, p.err = keyword, nil, nil + p.keyword, p.items, p.total, p.err = keyword, nil, 0, nil if keyword != "" && !s.closed { ctx, cancel := context.WithCancel(context.Background()) p.cancel = cancel @@ -103,7 +105,7 @@ func (s *Shell) syncCreatorPreview(keyword string) { if err == nil { p.storePage(keyword, app.SearchPage{Items: items, HasMore: page.HasMore, Total: page.Total}) } - ch <- creatorResult{items: items, err: err} + ch <- creatorResult{items: items, total: page.Total, err: err} s.wake.invalidate() }() } @@ -112,6 +114,7 @@ func (s *Shell) syncCreatorPreview(keyword string) { select { case result := <-p.result: p.items = uniqueCreators(result.items) + p.total = result.total p.err = result.err p.result = nil if p.cancel != nil { @@ -201,6 +204,9 @@ func (s *Shell) viewSearchLead(c *ui.Context, keyword string, tab int) { pud.Tabs(c, "search:tabs:"+keyword, &s.search.tab, tabs) }) s.viewSearchToolbar(c, tab) + if tab == searchTabUser { + ui.Box(c).Height(space.Px24) + } t := &s.search.lists[tab] if t.list.Layout() != list.ViewCard && tab != searchTabUser && t.list.Paged().Loaded > 0 { diff --git a/internal/ui/search_creators_test.go b/internal/ui/search_creators_test.go index 9627474d..672a8283 100644 --- a/internal/ui/search_creators_test.go +++ b/internal/ui/search_creators_test.go @@ -36,6 +36,30 @@ func TestSearchCreatorsAreClickable(t *testing.T) { } } +// TestSearchUserCardsKeepClearanceAfterCreatorPreview locks spacing inside the combined search lead. +func TestSearchUserCardsKeepClearanceAfterCreatorPreview(t *testing.T) { + s, tt := newSearchPage(t, "音乐", newSearchStub(24, 24)) + s.search.creators.fetch = func(context.Context, string) ([]app.SearchItem, error) { + return []app.SearchItem{creatorItem("42", "测试UP", "", bili.VerificationPersonal)}, nil + } + waitFrames(t, tt, "相关UP主出现", func() bool { return tt.HasText("测试UP") }) + if err := tt.Click("UP 主"); err != nil { + t.Fatal(err) + } + waitFrames(t, tt, "用户卡片出现", func() bool { return tt.HasText("打开 测试UP 的空间") }) + toolbar, ok := tt.Find("默认排序") + if !ok { + t.Fatal("找不到 UP 主排序控件") + } + card, ok := tt.Find("打开 第 1 页 第 1 首 的空间") + if !ok { + t.Fatal("找不到第一张 UP 主卡") + } + if gap := card.Y - (toolbar.Y + toolbar.H); gap < 24 { + t.Fatalf("排序控件和第一张 UP 主卡之间只有 %.1fpx,至少需要 24px", gap) + } +} + // TestSearchCreatorPreviewIgnoresStaleResults locks the current query against a delayed previous result. func TestSearchCreatorPreviewIgnoresStaleResults(t *testing.T) { s, tt := newSearchPage(t, "旧词", newSearchStub(24, 24)) diff --git a/internal/ui/searchpage.go b/internal/ui/searchpage.go index 11c2f60d..d0d666ba 100644 --- a/internal/ui/searchpage.go +++ b/internal/ui/searchpage.go @@ -186,6 +186,9 @@ var searchTabLabels = [searchTabCount]string{"歌曲", "视频", "UP 主"} func (s *Shell) searchTabCountText(tab int) string { t := &s.search.lists[tab] pg := t.list.Paged() + if tab == searchTabUser && s.search.creators.total > 0 { + return strconv.Itoa(s.search.creators.total) + } if pg.Loaded == 0 && !pg.Loading && pg.Err == nil && t.kw == "" { return "" } @@ -206,6 +209,9 @@ func (s *Shell) searchTabCountText(tab int) string { } } } + if n == 0 { + return "" + } return strconv.Itoa(n) } @@ -365,8 +371,8 @@ func (s *Shell) viewSearchResultsBody(c *ui.Context, tab int, keyword string, le ui.Box(c).Height(space.Px8) t.list.Header(c, "search:header:"+strconv.Itoa(tab)) } - if tab == searchTabUser { - ui.Box(c).Height(space.Px16) + if tab == searchTabUser && !lead { + ui.Box(c).Height(space.Px24) } t.list.View(c) } diff --git a/internal/ui/searchpage_test.go b/internal/ui/searchpage_test.go index 1b3d787c..3195f06b 100644 --- a/internal/ui/searchpage_test.go +++ b/internal/ui/searchpage_test.go @@ -447,6 +447,17 @@ func TestTheThreeTypesAndTheirSorts(t *testing.T) { } } +// TestSearchUserTabShowsPreviewTotalBeforeOpeningIt locks the preview count into the tab. +func TestSearchUserTabShowsPreviewTotalBeforeOpeningIt(t *testing.T) { + s, tt := newSearchPage(t, "周杰伦", newSearchStub(24, 24)) + waitFrames(t, tt, "搜索结果标签", func() bool { return tt.HasText("UP 主") }) + s.search.creators.total = 1000 + tt.Frame() + if !tt.HasText("1000") { + t.Fatalf("UP 主标签没有显示预览总数,文字有 %q", tt.Texts()) + } +} + // TestEachSortStaysItsOwn 盯「排序是每个 Tab 各自的」。Biu 的两个列表各有一份排序 // 状态(`video-list` 一个 `order`、`user-list` 一个 `sortKey`);做成一个全局值的话, // 在「用户」里按过排序再切回「视频」,视频那边的排序被改了——而他刚点的明明是用户 @@ -796,8 +807,8 @@ func TestSearchUserCardsKeepClearanceBelowTheToolbar(t *testing.T) { if !ok { t.Fatal("找不到第一张 UP 主卡") } - if gap := card.Y - (toolbar.Y + toolbar.H); gap < 16 { - t.Fatalf("排序控件和第一张 UP 主卡之间只有 %.1fpx,至少需要 16px", gap) + if gap := card.Y - (toolbar.Y + toolbar.H); gap < 24 { + t.Fatalf("排序控件和第一张 UP 主卡之间只有 %.1fpx,至少需要 24px", gap) } }