feat: fix custom category order

This commit is contained in:
shinya
2025-07-31 23:10:27 +08:00
parent ed96ee0554
commit 636f408d4a
4 changed files with 21 additions and 9 deletions

View File

@@ -1 +1 @@
20250731215708
20250731231027

View File

@@ -72,17 +72,23 @@ function DoubanPageClient() {
// 当type变化时重置选择器状态
useEffect(() => {
if (type === 'custom' && customCategories.length > 0) {
// 自定义分类模式:根据 customCategories 设置初始状态
// 自定义分类模式:优先选择 movie如果没有 movie 则选择 tv
const types = Array.from(
new Set(customCategories.map((cat) => cat.type))
);
if (types.length > 0) {
const firstType = types[0];
setPrimarySelection(firstType);
// 优先选择 movie如果没有 movie 则选择 tv
let selectedType = types[0]; // 默认选择第一个
if (types.includes('movie')) {
selectedType = 'movie';
} else {
selectedType = 'tv';
}
setPrimarySelection(selectedType);
// 设置第一个分类的 query 作为二级选择
// 设置选中类型的第一个分类的 query 作为二级选择
const firstCategory = customCategories.find(
(cat) => cat.type === firstType
(cat) => cat.type === selectedType
);
if (firstCategory) {
setSecondarySelection(firstCategory.query);

View File

@@ -40,10 +40,16 @@ const DoubanCustomSelector: React.FC<DoubanCustomSelectorProps> = ({
width: number;
}>({ left: 0, width: 0 });
// 根据 customCategories 生成一级选择器选项(按 type 分组)
// 根据 customCategories 生成一级选择器选项(按 type 分组,电影优先
const primaryOptions = React.useMemo(() => {
const types = Array.from(new Set(customCategories.map((cat) => cat.type)));
return types.map((type) => ({
// 确保电影类型排在前面
const sortedTypes = types.sort((a, b) => {
if (a === 'movie' && b !== 'movie') return -1;
if (a !== 'movie' && b === 'movie') return 1;
return 0;
});
return sortedTypes.map((type) => ({
label: type === 'movie' ? '电影' : '剧集',
value: type,
}));

View File

@@ -2,7 +2,7 @@
'use client';
const CURRENT_VERSION = '20250731215708';
const CURRENT_VERSION = '20250731231027';
// 版本检查结果枚举
export enum UpdateStatus {