feat(wiki): add complete scientific terms dictionary for all product ingredients
- Add colloidal silver, retinol palmitate, grapefruit seed extract, bovine blood/serum, argan/walnut/rosehip oils, etc. - Map all product ingredients across all categories to Wiki scientific terms - Update IngredientWiki matching rules for 100% ingredient coverage
This commit is contained in:
1 parent
f762105f09
commit
fcc738f25c
3 files changed
+141
-26
No files matched your search
@@ -6,6 +6,7 @@ import { FlaskConical, CheckCircle2, ChevronRight, ChevronLeft, Beaker, Search }
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
import { productService } from "../lib/services/productService";
|
||||
|
||||
import { SCIENTIFIC_TERMS } from "../lib/data/scientificTerms";
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
|
||||
export default function IngredientWiki() {
|
||||
@@ -23,41 +24,39 @@ export default function IngredientWiki() {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
let list: IngredientInfo[] = [];
|
||||
const raw = texts.ingredients_wiki || texts.ingredients_wiki_text;
|
||||
if (raw) {
|
||||
try {
|
||||
const parsed = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
||||
if (Array.isArray(parsed)) {
|
||||
setIngredientsWiki(parsed.map((item: any) => ({
|
||||
list = parsed.map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
description: item.description,
|
||||
benefits: Array.isArray(item.benefits) ? item.benefits : []
|
||||
})));
|
||||
return;
|
||||
}));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to parse ingredients_wiki:", e);
|
||||
}
|
||||
}
|
||||
const terms = Object.values(scientificTerms);
|
||||
if (terms.length > 0) {
|
||||
setIngredientsWiki(terms.map((t: any) => {
|
||||
let benefits: string[] = [];
|
||||
if (t.keywords) {
|
||||
try {
|
||||
const parsed = typeof t.keywords === 'string' ? JSON.parse(t.keywords) : t.keywords;
|
||||
if (Array.isArray(parsed)) benefits = parsed;
|
||||
} catch (e) {}
|
||||
}
|
||||
return {
|
||||
id: t.key || t.wikiId,
|
||||
|
||||
// Merge terms from scientificTerms and static SCIENTIFIC_TERMS dictionary
|
||||
const mergedTerms = { ...SCIENTIFIC_TERMS, ...scientificTerms };
|
||||
Object.entries(mergedTerms).forEach(([key, t]: [string, any]) => {
|
||||
const wikiId = t.wikiId || t.key || key;
|
||||
if (!list.some(item => item.id === wikiId || item.name.includes(t.term))) {
|
||||
list.push({
|
||||
id: wikiId,
|
||||
name: t.term,
|
||||
description: t.definition,
|
||||
benefits
|
||||
};
|
||||
}));
|
||||
}
|
||||
benefits: []
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
setIngredientsWiki(list);
|
||||
}, [texts, scientificTerms]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -163,7 +162,23 @@ export default function IngredientWiki() {
|
||||
(ing.id === 'l-carnitine' && (miClean.includes('کارنیتین') || miClean.includes('carnitine'))) ||
|
||||
(ing.id === 'seaweed' && (miClean.includes('جلبک') || miClean.includes('seaweed'))) ||
|
||||
(ing.id === 'hyaluronic' && (miClean.includes('هیالورونات') || miClean.includes('hyaluron'))) ||
|
||||
(ing.id === 'calendula-sea-buckthorn' && (miClean.includes('کالاندولا') || miClean.includes('سنجد') || miClean.includes('calendula'))) ||
|
||||
(ing.id === 'calendula-sea-buckthorn' && (miClean.includes('کالاندولا') || miClean.includes('سنجد') || miClean.includes('خولان') || miClean.includes('calendula'))) ||
|
||||
(ing.id === 'colloidal-silver' && miClean.includes('کلوئیدی')) ||
|
||||
(ing.id === 'retinol-palmitate' && (miClean.includes('رتینول') || miClean.includes('پالمیتات'))) ||
|
||||
(ing.id === 'grapefruit-seed' && miClean.includes('گریپ')) ||
|
||||
(ing.id === 'vaseline' && miClean.includes('وازلین')) ||
|
||||
(ing.id === 'panthenol' && miClean.includes('پانتنول')) ||
|
||||
(ing.id === 'diatomaceous' && miClean.includes('دیاتومه')) ||
|
||||
(ing.id === 'artichoke' && miClean.includes('کنگر')) ||
|
||||
(ing.id === 'brewers-yeast' && (miClean.includes('مخمر') || miClean.includes('yeast'))) ||
|
||||
(ing.id === 'willow-bark' && miClean.includes('بید')) ||
|
||||
(ing.id === 'ginger' && miClean.includes('زنجبیل')) ||
|
||||
(ing.id === 'bovine-serum' && miClean.includes('سرم')) ||
|
||||
(ing.id === 'bovine-blood' && miClean.includes('خون')) ||
|
||||
(ing.id === 'beef-fat' && miClean.includes('چربی')) ||
|
||||
(ing.id === 'argan-oil' && miClean.includes('آرگان')) ||
|
||||
(ing.id === 'rosehip-oil' && miClean.includes('گل رز')) ||
|
||||
(ing.id === 'walnut-oil' && miClean.includes('گردو')) ||
|
||||
(ing.id === 'dodecanoic' && (miClean.includes('دودکانوئیک') || miClean.includes('مارگوسا') || miClean.includes('insect')));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,15 +32,15 @@ export default function Tooltip({ termKey, children, onWikiNavigate }: TooltipPr
|
||||
initial={{ opacity: 0, y: 10, scale: 0.95 }}
|
||||
animate={{ opacity: 1, y: 0, scale: 1 }}
|
||||
exit={{ opacity: 0, y: 10, scale: 0.95 }}
|
||||
className="absolute bottom-full left-1/2 -translate-x-1/2 mb-3 w-64 p-4 bg-medical-gray-900 text-white rounded-2xl shadow-2xl z-[100] text-sm"
|
||||
className="absolute bottom-full left-1/2 -translate-x-1/2 mb-3 w-72 p-5 bg-white text-medical-gray-900 rounded-2xl shadow-2xl border border-medical-gray-200 z-[100] text-sm"
|
||||
dir="rtl"
|
||||
>
|
||||
<div className="flex items-center gap-2 mb-2 text-canina-blue">
|
||||
<Info className="w-4 h-4" />
|
||||
<span className="font-black text-[10px] uppercase tracking-widest text-canina-blue">دانشنامه علمی کانینا</span>
|
||||
<span className="font-black text-[11px] uppercase tracking-widest text-canina-blue">دانشنامه علمی کانینا</span>
|
||||
</div>
|
||||
<h5 className="font-black text-sm text-white mb-2 leading-snug">{termData.term}</h5>
|
||||
<p className="text-gray-200 text-xs leading-relaxed mb-3 font-medium">
|
||||
<h5 className="font-black text-base text-medical-gray-900 mb-2 leading-snug">{termData.term}</h5>
|
||||
<p className="text-medical-gray-600 text-xs leading-relaxed mb-4 font-bold">
|
||||
{termData.definition}
|
||||
</p>
|
||||
{termData.wikiId && (
|
||||
@@ -49,14 +49,14 @@ export default function Tooltip({ termKey, children, onWikiNavigate }: TooltipPr
|
||||
e.stopPropagation();
|
||||
onWikiNavigate?.(termData.wikiId!);
|
||||
}}
|
||||
className="flex items-center gap-1.5 text-canina-blue hover:text-cyan-300 transition-colors text-xs font-black cursor-pointer pt-1 border-t border-white/10 w-full"
|
||||
className="flex items-center justify-between text-canina-blue hover:text-blue-700 transition-colors text-xs font-black cursor-pointer pt-2 border-t border-medical-gray-100 w-full"
|
||||
>
|
||||
<span>مطالعه مقاله کامل</span>
|
||||
<ExternalLink className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
)}
|
||||
{/* Arrow */}
|
||||
<div className="absolute top-full left-1/2 -translate-x-1/2 border-8 border-transparent border-t-medical-gray-900" />
|
||||
<div className="absolute top-full left-1/2 -translate-x-1/2 border-8 border-transparent border-t-white" />
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
Reference in new issue
Block a user