mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-19 22:19:36 +02:00
chore: CATEGORIES_USER_TYPES_MAPPINGS
This commit is contained in:
@@ -136,7 +136,17 @@ const categoriesConfig: {
|
|||||||
title: 'translation:categories.xml.title'
|
title: 'translation:categories.xml.title'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
const CATEGORIES_USER_TYPES_MAPPINGS: Partial<Record<ToolCategory, UserType>> =
|
||||||
|
{
|
||||||
|
xml: 'Developers',
|
||||||
|
csv: 'Developers',
|
||||||
|
json: 'Developers',
|
||||||
|
gif: 'General Users',
|
||||||
|
png: 'General Users',
|
||||||
|
'image-generic': 'General Users',
|
||||||
|
video: 'General Users',
|
||||||
|
audio: 'General Users'
|
||||||
|
};
|
||||||
// Filter tools by user types
|
// Filter tools by user types
|
||||||
export const filterToolsByUserTypes = (
|
export const filterToolsByUserTypes = (
|
||||||
tools: DefinedTool[],
|
tools: DefinedTool[],
|
||||||
@@ -145,9 +155,8 @@ export const filterToolsByUserTypes = (
|
|||||||
if (userTypes.length === 0) return tools;
|
if (userTypes.length === 0) return tools;
|
||||||
|
|
||||||
return tools.filter((tool) => {
|
return tools.filter((tool) => {
|
||||||
const devToolsCategories: ToolCategory[] = ['xml', 'json', 'csv'];
|
if (CATEGORIES_USER_TYPES_MAPPINGS[tool.type]) {
|
||||||
if (devToolsCategories.includes(tool.type)) {
|
return userTypes.includes(CATEGORIES_USER_TYPES_MAPPINGS[tool.type]!);
|
||||||
return userTypes.includes('Developers');
|
|
||||||
}
|
}
|
||||||
// If tool has no userTypes defined, show it to all users
|
// If tool has no userTypes defined, show it to all users
|
||||||
if (!tool.userTypes || tool.userTypes.length === 0) return true;
|
if (!tool.userTypes || tool.userTypes.length === 0) return true;
|
||||||
@@ -242,7 +251,14 @@ export const getToolsByCategory = (
|
|||||||
userTypes: aggregatedUserTypes // <-- Add this line
|
userTypes: aggregatedUserTypes // <-- Add this line
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter((category) => category.tools.length > 0) // Only show categories with tools
|
.filter((category) => category.tools.length > 0)
|
||||||
|
.filter((category) =>
|
||||||
|
userTypes.length > 0
|
||||||
|
? [...category.userTypes, CATEGORIES_USER_TYPES_MAPPINGS[category.type]]
|
||||||
|
.filter(Boolean)
|
||||||
|
.some((categoryUserType) => userTypes.includes(categoryUserType!))
|
||||||
|
: true
|
||||||
|
) // Only show categories with tools
|
||||||
.sort(
|
.sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
toolCategoriesOrder.indexOf(a.type) -
|
toolCategoriesOrder.indexOf(a.type) -
|
||||||
|
Reference in New Issue
Block a user