mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-06 20:10:12 +02:00
normalize album release types and improve grouping logic (#1892)
This commit is contained in:
@@ -13,6 +13,15 @@ export type GroupingType = 'all' | 'primary';
|
|||||||
|
|
||||||
const PRIMARY_RELEASE_TYPES = ['album', 'broadcast', 'ep', 'other', 'single'];
|
const PRIMARY_RELEASE_TYPES = ['album', 'broadcast', 'ep', 'other', 'single'];
|
||||||
|
|
||||||
|
const getNormalizedReleaseTypes = (album: Album): string[] => {
|
||||||
|
const rawReleaseTypes = [...(album.releaseTypes || []), album.releaseType || ''];
|
||||||
|
const normalizedReleaseTypes = rawReleaseTypes
|
||||||
|
.map((type) => type.trim().toLowerCase())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
return [...new Set(normalizedReleaseTypes)];
|
||||||
|
};
|
||||||
|
|
||||||
export const groupAlbumsByReleaseType = (
|
export const groupAlbumsByReleaseType = (
|
||||||
albums: Album[],
|
albums: Album[],
|
||||||
routeId: string,
|
routeId: string,
|
||||||
@@ -44,10 +53,9 @@ export const groupAlbumsByReleaseType = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Group by all release types
|
// Group by all release types
|
||||||
const releaseTypes = album.releaseTypes || [];
|
const normalizedTypes = getNormalizedReleaseTypes(album);
|
||||||
if (releaseTypes.length > 0) {
|
if (normalizedTypes.length > 0) {
|
||||||
// Sort release types: primaries first (alphabetically), then secondaries (alphabetically)
|
// Sort release types: primaries first (alphabetically), then secondaries (alphabetically)
|
||||||
const normalizedTypes = releaseTypes.map((type) => type.toLowerCase());
|
|
||||||
const primaryTypes = normalizedTypes
|
const primaryTypes = normalizedTypes
|
||||||
.filter((type) => PRIMARY_RELEASE_TYPES.includes(type))
|
.filter((type) => PRIMARY_RELEASE_TYPES.includes(type))
|
||||||
.sort();
|
.sort();
|
||||||
@@ -92,8 +100,7 @@ export const groupAlbumsByReleaseType = (
|
|||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
|
||||||
const releaseTypes = album.releaseTypes || [];
|
const normalizedTypes = getNormalizedReleaseTypes(album);
|
||||||
const normalizedTypes = releaseTypes.map((type) => type.toLowerCase());
|
|
||||||
|
|
||||||
let matchedType: null | string = null;
|
let matchedType: null | string = null;
|
||||||
|
|
||||||
@@ -107,6 +114,8 @@ export const groupAlbumsByReleaseType = (
|
|||||||
matchedType = 'broadcast';
|
matchedType = 'broadcast';
|
||||||
} else if (normalizedTypes.includes('other')) {
|
} else if (normalizedTypes.includes('other')) {
|
||||||
matchedType = 'other';
|
matchedType = 'other';
|
||||||
|
} else if (normalizedTypes.length > 0) {
|
||||||
|
matchedType = normalizedTypes[0];
|
||||||
} else {
|
} else {
|
||||||
matchedType = 'album';
|
matchedType = 'album';
|
||||||
}
|
}
|
||||||
@@ -292,11 +301,11 @@ export const getArtistAlbumsGrouped = (
|
|||||||
const types = releaseType.split('/');
|
const types = releaseType.split('/');
|
||||||
return types.some((type) => {
|
return types.some((type) => {
|
||||||
const enumValue = releaseTypeToEnumMap[type];
|
const enumValue = releaseTypeToEnumMap[type];
|
||||||
return enumValue ? enabledReleaseTypeEnums.has(enumValue) : false;
|
return enumValue ? enabledReleaseTypeEnums.has(enumValue) : true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const enumValue = releaseTypeToEnumMap[releaseType];
|
const enumValue = releaseTypeToEnumMap[releaseType];
|
||||||
return enumValue ? enabledReleaseTypeEnums.has(enumValue) : false;
|
return enumValue ? enabledReleaseTypeEnums.has(enumValue) : true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const releaseTypeEntries = Object.entries(albumsByReleaseType)
|
const releaseTypeEntries = Object.entries(albumsByReleaseType)
|
||||||
|
|||||||
Reference in New Issue
Block a user