Skip to content

feat: add search functionality for local playlists#147

Merged
roitium merged 3 commits into
devfrom
feat/search-local-playlist
Jan 23, 2026
Merged

feat: add search functionality for local playlists#147
roitium merged 3 commits into
devfrom
feat/search-local-playlist

Conversation

@roitium
Copy link
Copy Markdown
Collaborator

@roitium roitium commented Jan 23, 2026

Summary by CodeRabbit

  • 新功能
    • 在播放列表界面新增本地播放列表搜索:在标题下方显示搜索栏,可输入关键词实时过滤并展示匹配的本地播放列表。
    • 搜索时结果会替换列表视图,支持空查询恢复原始播放列表显示。

✏️ Tip: You can customize this high-level summary in your review settings.

@roitium roitium added the enhancement New feature or request label Jan 23, 2026
@safedep
Copy link
Copy Markdown

safedep Bot commented Jan 23, 2026

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

This report is generated by SafeDep Github App

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 23, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

为本地播放列表新增搜索功能:后端 playlistService.searchPlaylists、查询钩子 useSearchPlaylists,以及在 LocalPlaylistList 中集成的搜索栏与搜索驱动的数据源分支。

Changes

Cohort / File(s) 变更摘要
变更日志
CHANGELOG.md
新增 UNRELEASED -> Added 小节,记录“添加本地播放列表搜索功能”。
服务层
src/lib/services/playlistService.ts
新增 searchPlaylists(query: string) 方法:按 title LIKE %query% 查询 type='local' 播放列表,按 updatedAt 降序、包含 author,错误映射为 DatabaseError。请注意 SQL LIKE 行为与空查询处理(返回空数组)。
查询钩子
src/hooks/queries/db/playlist.ts
新增 playlistKeys.searchPlaylists(query)export const useSearchPlaylists(query, enabled),启用条件为非空 query 且 enabled,使用 keepPreviousData 作为 placeholderData。关注缓存键命名与 enabled 策略。
UI 组件
src/features/library/local/LocalPlaylistList.tsx
集成搜索:导入并使用 useSearchPlaylists,新增 searchQuery state 与 Searchbar UI,计算 finalPlaylists 时当 query 非空使用搜索结果,否则保持原有列表(仍包含“稍后再看”合成项的逻辑)。注意 effect 依赖变化与样式布局调整。

Sequence Diagram

sequenceDiagram
    actor User
    participant UI as LocalPlaylistList (UI)
    participant Hook as useSearchPlaylists (Hook)
    participant Service as PlaylistService (Service)
    participant DB as Database (DB)

    User->>UI: 输入搜索关键词
    activate UI
    UI->>UI: 更新 searchQuery 状态
    UI->>Hook: 调用 useSearchPlaylists(query)
    deactivate UI

    activate Hook
    Hook->>Hook: 校验 query 非空 且 enabled
    Hook->>Service: 调用 searchPlaylists(query)
    deactivate Hook

    activate Service
    Service->>DB: 查询 title LIKE %query% 且 type='local'
    DB-->>Service: 返回匹配的播放列表(按 updatedAt 降序)
    Service->>Service: 关联 author 信息
    Service-->>Hook: 返回结果
    deactivate Service

    activate Hook
    Hook->>Hook: 处理数据,使用 keepPreviousData 占位
    Hook-->>UI: 提供搜索结果状态
    deactivate Hook

    activate UI
    UI->>UI: 计算 finalPlaylists(query 非空则用搜索结果)
    UI-->>User: 渲染并显示搜索结果列表
    deactivate UI
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • feat: ToView as a playlist #71: 修改过 src/features/library/local/LocalPlaylistList.tsxfinalPlaylists 构建逻辑,本 PR 在该路径上添加搜索分支,可能存在交叉影响或合并冲突。

Poem

🐰 我是小兔听见风,
键入几字歌单生,
本地曲目跳出来,
轻啾翻页喜洋洋,
兔耳竖起在草丛。 🎶

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题清晰准确地总结了主要变更:为本地播放列表添加搜索功能,与所有修改文件的核心内容完全一致。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/lib/services/playlistService.ts`:
- Around line 833-854: Trim the incoming query in searchPlaylists, short-circuit
when the trimmed query is empty by returning an immediate successful ResultAsync
containing an empty array (instead of running the DB query), and only call
this.db.query.playlists.findMany when the trimmed query is non-empty; update
references around searchPlaylists, the query variable, and the
like(schema.playlists.title, ...) call to use the trimmed value.
🧹 Nitpick comments (1)
src/hooks/queries/db/playlist.ts (1)

99-105: 建议在 hook 内统一规范化查询字符串
避免因前后空格导致 cache key 细碎化,也让查询参数一致。

♻️ 参考改动
 export const useSearchPlaylists = (query: string, enabled: boolean) => {
+	const normalizedQuery = query.trim()
 	return useQuery({
-		queryKey: playlistKeys.searchPlaylists(query),
-		queryFn: () => returnOrThrowAsync(playlistService.searchPlaylists(query)),
-		enabled: enabled && !!query.trim(),
+		queryKey: playlistKeys.searchPlaylists(normalizedQuery),
+		queryFn: () =>
+			returnOrThrowAsync(playlistService.searchPlaylists(normalizedQuery)),
+		enabled: enabled && !!normalizedQuery,
 		placeholderData: keepPreviousData,
 	})
 }

Comment thread src/lib/services/playlistService.ts
@roitium roitium merged commit 9b5d99a into dev Jan 23, 2026
1 of 2 checks passed
@roitium roitium deleted the feat/search-local-playlist branch January 23, 2026 01:32
@coderabbitai coderabbitai Bot mentioned this pull request Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant