fix(wiki): enhance wiki ingredient deep-linking and tooltip legibility
- Add term query param handling to IngredientWiki with smooth scroll and target highlight - Fix Tooltip dark box contrast and click event propagation for study full article button - Improve ingredient fuzzy matching in ProductPage for complete wiki term linking
This commit is contained in:
parent
fd45910387
commit
f762105f09
@ -6,10 +6,12 @@ import { FlaskConical, CheckCircle2, ChevronRight, ChevronLeft, Beaker, Search }
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
import { productService } from "../lib/services/productService";
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
|
||||
export default function IngredientWiki() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const termParam = searchParams.get('term');
|
||||
const texts = useSettingsStore(state => state.texts);
|
||||
const scientificTerms = useSettingsStore(state => state.scientificTerms);
|
||||
const [ingredientsWiki, setIngredientsWiki] = useState<IngredientInfo[]>([]);
|
||||
@ -49,7 +51,7 @@ export default function IngredientWiki() {
|
||||
} catch (e) {}
|
||||
}
|
||||
return {
|
||||
id: t.key,
|
||||
id: t.key || t.wikiId,
|
||||
name: t.term,
|
||||
description: t.definition,
|
||||
benefits
|
||||
@ -58,6 +60,17 @@ export default function IngredientWiki() {
|
||||
}
|
||||
}, [texts, scientificTerms]);
|
||||
|
||||
useEffect(() => {
|
||||
if (termParam && ingredientsWiki.length > 0) {
|
||||
const el = document.getElementById(`wiki-${termParam}`);
|
||||
if (el) {
|
||||
setTimeout(() => {
|
||||
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
}, [termParam, ingredientsWiki]);
|
||||
|
||||
return (
|
||||
<div className="bg-white py-12 px-4 overflow-hidden font-vazir" dir="rtl">
|
||||
<div className="max-w-7xl mx-auto">
|
||||
@ -155,8 +168,13 @@ export default function IngredientWiki() {
|
||||
});
|
||||
});
|
||||
|
||||
const isTargeted = termParam === ing.id;
|
||||
return (
|
||||
<div key={ing.id} className={`flex flex-col lg:flex-row items-center gap-16 ${idx % 2 === 1 ? 'lg:flex-row-reverse' : ''}`}>
|
||||
<div
|
||||
key={ing.id}
|
||||
id={`wiki-${ing.id}`}
|
||||
className={`flex flex-col lg:flex-row items-center gap-16 p-6 rounded-[3rem] transition-all duration-500 ${isTargeted ? 'bg-canina-blue/5 border-2 border-canina-blue ring-4 ring-canina-blue/10 shadow-2xl' : ''} ${idx % 2 === 1 ? 'lg:flex-row-reverse' : ''}`}
|
||||
>
|
||||
{/* Content */}
|
||||
<div className="lg:w-1/2 space-y-8">
|
||||
<motion.div
|
||||
|
||||
@ -410,7 +410,17 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
<h4 className="text-xs font-black text-medical-gray-400 uppercase tracking-widest mb-6 font-vazir">مواد تشکیلدهنده برتر</h4>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
{product.main_ingredients.map((ing, idx) => {
|
||||
const termKey = termKeys.find(key => ing.includes(key));
|
||||
const termKey = termKeys.find(key => {
|
||||
const termObj = scientificTerms[key] || SCIENTIFIC_TERMS[key];
|
||||
const termName = termObj?.term || key;
|
||||
const ingClean = ing.toLowerCase();
|
||||
const keyClean = key.toLowerCase();
|
||||
const termNameClean = termName.toLowerCase();
|
||||
return ingClean.includes(keyClean) ||
|
||||
keyClean.includes(ingClean) ||
|
||||
ingClean.includes(termNameClean) ||
|
||||
termNameClean.includes(ingClean);
|
||||
});
|
||||
return (
|
||||
<div key={idx} className="bg-medical-gray-50 border border-medical-gray-100 px-5 py-3 rounded-2xl flex items-center gap-3 group hover:border-canina-blue/30 transition-all">
|
||||
<span className="text-sm font-bold text-medical-gray-700 font-vazir">
|
||||
|
||||
@ -37,19 +37,22 @@ export default function Tooltip({ termKey, children, onWikiNavigate }: TooltipPr
|
||||
>
|
||||
<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">دانشنامه علمی کانینا</span>
|
||||
<span className="font-black text-[10px] uppercase tracking-widest text-canina-blue">دانشنامه علمی کانینا</span>
|
||||
</div>
|
||||
<h5 className="font-black mb-1">{termData.term}</h5>
|
||||
<p className="text-white/70 text-xs leading-relaxed mb-3">
|
||||
<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">
|
||||
{termData.definition}
|
||||
</p>
|
||||
{termData.wikiId && (
|
||||
<button
|
||||
onClick={() => onWikiNavigate?.(termData.wikiId!)}
|
||||
className="flex items-center gap-1.5 text-canina-blue hover:text-white transition-colors text-[10px] font-bold"
|
||||
onClick={(e) => {
|
||||
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"
|
||||
>
|
||||
<span>مطالعه مقاله کامل</span>
|
||||
<ExternalLink className="w-3 h-3" />
|
||||
<ExternalLink className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
)}
|
||||
{/* Arrow */}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user