feat: add search functionality for local playlists#147
Merged
Conversation
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
|
Caution Review failedThe pull request is closed. Walkthrough为本地播放列表新增搜索功能:后端 playlistService.searchPlaylists、查询钩子 useSearchPlaylists,以及在 LocalPlaylistList 中集成的搜索栏与搜索驱动的数据源分支。 Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
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, }) }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.