Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/ui/search_creators.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

type creatorResult struct {
items []app.SearchItem
total int
err error
}

Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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()
}()
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions internal/ui/search_creators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 8 additions & 2 deletions internal/ui/searchpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand All @@ -206,6 +209,9 @@ func (s *Shell) searchTabCountText(tab int) string {
}
}
}
if n == 0 {
return ""
}
return strconv.Itoa(n)
}

Expand Down Expand Up @@ -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)
}
Expand Down
15 changes: 13 additions & 2 deletions internal/ui/searchpage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`);做成一个全局值的话,
// 在「用户」里按过排序再切回「视频」,视频那边的排序被改了——而他刚点的明明是用户
Expand Down Expand Up @@ -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)
}
}

Expand Down