feat: modernize search filters & intelligent label shortening
- Introduced shortenCategory utility to strip redundant terms from labels - Refactored BottleGrid filters into a compact, collapsible layout - Added filter count indicator and improved chip styling - Fully localized new filter UI elements
This commit is contained in:
33
src/lib/format.ts
Normal file
33
src/lib/format.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Shortens a whisky category label by removing redundant common terms.
|
||||
* Example: "Single Malt Scotch Whisky" -> "Single Malt"
|
||||
*/
|
||||
export const shortenCategory = (label: string): string => {
|
||||
if (!label) return '';
|
||||
|
||||
const replacements: [string, string][] = [
|
||||
['Single Malt Scotch Whisky', 'Single Malt'],
|
||||
['Blended Malt Scotch Whisky', 'Blended Malt'],
|
||||
['Single Grain Scotch Whisky', 'Single Grain'],
|
||||
['Blended Scotch Whisky', 'Blended'],
|
||||
['Kentucky Straight Bourbon Whiskey', 'Bourbon'],
|
||||
['Straight Bourbon Whiskey', 'Bourbon'],
|
||||
['Tennessee Whiskey', 'Tennessee'],
|
||||
['Japanese Whisky', 'Japanese'],
|
||||
['Irish Whiskey', 'Irish'],
|
||||
['Canadian Whisky', 'Canadian'],
|
||||
['American Whiskey', 'American'],
|
||||
['Rye Whiskey', 'Rye'],
|
||||
];
|
||||
|
||||
for (const [full, short] of replacements) {
|
||||
if (label === full) return short;
|
||||
}
|
||||
|
||||
return label
|
||||
.replace(/ Scotch Whisky/gi, '')
|
||||
.replace(/ Scotch/gi, '')
|
||||
.replace(/ Whisky/gi, '')
|
||||
.replace(/ Whiskey/gi, '')
|
||||
.trim();
|
||||
};
|
||||
Reference in New Issue
Block a user