feat: character categories with filter#2
Merged
Merged
Conversation
- Add category field to all avatar presets (6 categories) - Add GET /api/categories endpoint - Frontend filter chips above avatar grid to filter by category - "全部" chip shows all avatars (default)
There was a problem hiding this comment.
Pull request overview
Adds first-class “category” support for avatar presets and exposes it end-to-end (backend API → frontend filter UI) so users can quickly filter the avatar grid by scenario/persona.
Changes:
- Backend: adds
categoryto preset avatar metadata and introducesGET /api/categories. - Frontend: renders category filter chips and filters the avatar grid based on the selected category.
- UI styling: adds chip styles and bumps static asset cache-busting versions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
static/style.css |
Adds styles for category filter container and chip states. |
static/index.html |
Inserts the category filter container above the avatar grid; bumps asset versions. |
static/app.js |
Fetches categories, renders filter chips, and filters avatar rendering by category. |
app.py |
Adds category data to presets, returns category in /api/avatars, and adds /api/categories. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| list.innerHTML = ""; | ||
| const filtered = currentCategory | ||
| ? allAvatars.filter((a) => a.category === currentCategory) | ||
| : allAvatars; |
Comment on lines
+40
to
+58
| const allChip = document.createElement("button"); | ||
| allChip.className = "category-chip active"; | ||
| allChip.textContent = "全部"; | ||
| allChip.addEventListener("click", () => { | ||
| currentCategory = null; | ||
| $$(".category-chip").forEach((c) => c.classList.remove("active")); | ||
| allChip.classList.add("active"); | ||
| renderAvatars(); | ||
| }); | ||
| container.appendChild(allChip); | ||
|
|
||
| cats.forEach((cat) => { | ||
| const chip = document.createElement("button"); | ||
| chip.className = "category-chip"; | ||
| chip.textContent = cat; | ||
| chip.addEventListener("click", () => { | ||
| currentCategory = cat; | ||
| $$(".category-chip").forEach((c) => c.classList.remove("active")); | ||
| chip.classList.add("active"); |
Comment on lines
+27
to
+31
| CATEGORIES = ["医疗健康", "教育", "文化艺术", "劳动者", "商务科技", "生活"] | ||
|
|
||
| PRESETS = [ | ||
| {"id": "lingnan_uncle", "name": "岭南大叔", "file": "lingnan_uncle.png", "voice": "onyx", "gender": "male", | ||
| "desc": "50 岁广东老街坊", "samples": ["今天带大家品品正宗广州早茶", "来来来,饮啖茶先"]}, | ||
| "category": "生活", "desc": "50 岁广东老街坊", "samples": ["今天带大家品品正宗广州早茶", "来来来,饮啖茶先"]}, |
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
Test plan