diff --git a/hifi-src/src/components/VehicleSearch.jsx b/hifi-src/src/components/VehicleSearch.jsx new file mode 100644 index 0000000..72638dc --- /dev/null +++ b/hifi-src/src/components/VehicleSearch.jsx @@ -0,0 +1,249 @@ +import { useEffect, useId, useMemo, useRef, useState } from 'react'; +import { Link, useNavigate } from 'react-router-dom'; +import { ArrowRight, Search, X } from 'lucide-react'; +import { api } from '../api/client.js'; +import { useLanguage } from '../context/LanguageContext.jsx'; + +// Gaengige Kurzformen, damit "vw golf" oder "mercedes c" auch ohne vollen Markennamen trifft. +const ALIASES = { + vw: 'volkswagen', + mercedes: 'mercedes-benz', + benz: 'mercedes-benz', + mb: 'mercedes-benz', + chevy: 'chevrolet', + alfa: 'alfa romeo', +}; + +const MAX_RESULTS = 8; + +// Kleinschreibung, ohne Akzente, ß -> ss; Bindestriche/Punkte zaehlen als Leerzeichen. +const normalize = (value) => + String(value || '') + .toLowerCase() + .normalize('NFD') + .replace(/[̀-ͯ]/g, '') + .replace(/ß/g, 'ss') + .replace(/[-_./]+/g, ' ') + .replace(/\s+/g, ' ') + .trim(); + +// Ohne Leerzeichen verglichen, damit "golf7", "golf 7" und "Golf VII" sich nicht ausschliessen. +const compact = (value) => value.replace(/\s/g, ''); + +function buildEntries(brands, models) { + const brandEntries = (brands || []).map((brand) => { + const text = normalize(brand.name); + return { key: `b${brand.id}`, type: 'brand', label: brand.name, to: `/fahrzeuge/${brand.slug}`, text, flat: compact(text) }; + }); + const modelEntries = (models || []).map((model) => { + const text = normalize(`${model.brand_name} ${model.name}`); + return { + key: `m${model.id}`, + type: 'model', + label: model.name, + brand: model.brand_name, + image: model.image_path, + to: `/fahrzeuge/${model.brand_slug}/${model.slug}`, + text, + flat: compact(text), + modelText: normalize(model.name), + }; + }); + return [...brandEntries, ...modelEntries]; +} + +function search(entries, query) { + // Pro Wort die Eingabe selbst plus ggf. die ausgeschriebene Marke ("vw" -> "volkswagen"). + const words = normalize(query).split(' ').filter(Boolean); + if (words.length === 0) return []; + const tokens = words.map((word) => (ALIASES[word] ? [word, normalize(ALIASES[word])] : [word])); + const joined = compact(words.join('')); + + const scored = []; + for (const entry of entries) { + const matches = (alt) => entry.text.includes(alt) || entry.flat.includes(compact(alt)); + // Jedes Wort muss vorkommen - oder die ganze Eingabe am Stueck ("golf7"). + if (!tokens.every((alts) => alts.some(matches)) && !entry.flat.includes(joined)) continue; + + // Treffer am Wortanfang und Modelle, die mit der Eingabe beginnen, nach oben. + let score = 0; + for (const alts of tokens) { + if (alts.some((alt) => entry.text.startsWith(alt))) score += 3; + else if (alts.some((alt) => ` ${entry.text}`.includes(` ${alt}`))) score += 2; + if (alts.some((alt) => entry.modelText?.startsWith(alt))) score += 2; + } + if (entry.type === 'brand') score += 1; + scored.push({ entry, score }); + } + scored.sort((a, b) => b.score - a.score || a.entry.text.localeCompare(b.entry.text, undefined, { numeric: true })); + return scored.slice(0, MAX_RESULTS).map((item) => item.entry); +} + +export default function VehicleSearch({ brands }) { + const { t } = useLanguage(); + const navigate = useNavigate(); + const listId = useId(); + const wrapperRef = useRef(null); + const [models, setModels] = useState(null); + const [query, setQuery] = useState(''); + const [open, setOpen] = useState(false); + const [active, setActive] = useState(0); + const loadingRef = useRef(false); + + // Modellliste erst beim ersten Fokus laden - wer nur Marken anklickt, braucht sie nie. + const ensureModels = () => { + if (models || loadingRef.current) return; + loadingRef.current = true; + api + .get('/vehicle-search') + .then(setModels) + .catch(() => setModels([])) + .finally(() => { + loadingRef.current = false; + }); + }; + + const entries = useMemo(() => buildEntries(brands, models), [brands, models]); + const results = useMemo(() => search(entries, query), [entries, query]); + const showPanel = open && query.trim() !== ''; + // Vorschaubilder nur, wenn ueberhaupt ein Treffer eins hat - sonst stoeren leere Platzhalter. + const withThumbs = results.some((entry) => entry.image); + + useEffect(() => setActive(0), [query]); + + useEffect(() => { + if (!showPanel) return undefined; + const onPointerDown = (event) => { + if (!wrapperRef.current?.contains(event.target)) setOpen(false); + }; + document.addEventListener('pointerdown', onPointerDown); + return () => document.removeEventListener('pointerdown', onPointerDown); + }, [showPanel]); + + const go = (entry) => { + setOpen(false); + navigate(entry.to); + }; + + const onKeyDown = (event) => { + if (event.key === 'ArrowDown' && results.length) { + event.preventDefault(); + setOpen(true); + setActive((i) => (i + 1) % results.length); + } else if (event.key === 'ArrowUp' && results.length) { + event.preventDefault(); + setActive((i) => (i - 1 + results.length) % results.length); + } else if (event.key === 'Enter' && showPanel && results[active]) { + event.preventDefault(); + go(results[active]); + } else if (event.key === 'Escape') { + if (showPanel) setOpen(false); + else setQuery(''); + } + }; + + const modelsLoading = models === null && query.trim() !== ''; + + return ( +
{typeof error === 'string' ? error : errorMessage(error, t)}
} diff --git a/hifi/api/public/index.php b/hifi/api/public/index.php index 8f6b09a..cd9f329 100644 --- a/hifi/api/public/index.php +++ b/hifi/api/public/index.php @@ -137,6 +137,7 @@ $router->post('/brands', $perm('brands.manage', fn($p) => BrandController::store $router->put('/brands/{id}', $perm('brands.manage', fn($p) => BrandController::update($p))); $router->delete('/brands/{id}', $perm('brands.manage', fn($p) => BrandController::destroy($p))); $router->get('/brands/{slug}/models', $maint('vehicles', fn($p) => BrandController::modelsForBrand($p))); +$router->get('/vehicle-search', $maint('vehicles', fn($p) => BrandController::searchIndex())); // Wird auch von der Pakete-Verwaltung für die Marke/Modell-Filter & -Auswahl benötigt. $router->get('/models', $anyPerm(['models.manage', 'packages.manage'], fn($p) => ModelController::index())); diff --git a/hifi/api/src/Controllers/BrandController.php b/hifi/api/src/Controllers/BrandController.php index af99b79..9e8df34 100644 --- a/hifi/api/src/Controllers/BrandController.php +++ b/hifi/api/src/Controllers/BrandController.php @@ -114,6 +114,20 @@ class BrandController Http::send(['ok' => true]); } + /** + * Alle Modelle samt Marke fuer die Direktsuche auf /fahrzeuge - die Liste ist klein, + * gefiltert wird im Browser (sofort beim Tippen, ohne Anfrage pro Tastendruck). + */ + public static function searchIndex(): void + { + $stmt = Database::connection()->query( + 'SELECT m.id, m.name, m.slug, m.image_path, b.name AS brand_name, b.slug AS brand_slug + FROM car_models m JOIN brands b ON b.id = m.brand_id + ORDER BY b.sort_order, b.name, m.sort_order, m.name' + ); + Http::send($stmt->fetchAll()); + } + public static function modelsForBrand(array $params): void { $db = Database::connection(); diff --git a/hifi/assets/AGB-BMFvwp8g.js b/hifi/assets/AGB-BMFvwp8g.js new file mode 100644 index 0000000..c1e796d --- /dev/null +++ b/hifi/assets/AGB-BMFvwp8g.js @@ -0,0 +1 @@ +import{j as e}from"./index-ChDBksRH.js";import{L as i}from"./LegalPageView-Blnm2lyV.js";function n(){return e.jsx(i,{slug:"agb",fallbackTitle:"AGB",description:"Allgemeine Geschäftsbedingungen von HifiPlanet Amorbach."})}export{n as default}; diff --git a/hifi/assets/AGB-CpKVKVA6.js b/hifi/assets/AGB-CpKVKVA6.js deleted file mode 100644 index e6aec89..0000000 --- a/hifi/assets/AGB-CpKVKVA6.js +++ /dev/null @@ -1 +0,0 @@ -import{j as e}from"./index-DDrkC388.js";import{L as i}from"./LegalPageView-DV386TeF.js";function n(){return e.jsx(i,{slug:"agb",fallbackTitle:"AGB",description:"Allgemeine Geschäftsbedingungen von HifiPlanet Amorbach."})}export{n as default}; diff --git a/hifi/assets/AccountSettings-CM01TUyg.js b/hifi/assets/AccountSettings-KX5ziPj0.js similarity index 99% rename from hifi/assets/AccountSettings-CM01TUyg.js rename to hifi/assets/AccountSettings-KX5ziPj0.js index be4b221..036a5cb 100644 --- a/hifi/assets/AccountSettings-CM01TUyg.js +++ b/hifi/assets/AccountSettings-KX5ziPj0.js @@ -1,4 +1,4 @@ -import{k as De,r as I,j as u,c as V}from"./index-DDrkC388.js";var Y={},Fe=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},ye={},S={};let de;const Ue=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];S.getSymbolSize=function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return t*4+17};S.getSymbolTotalCodewords=function(t){return Ue[t]};S.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};S.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');de=t};S.isKanjiModeEnabled=function(){return typeof de<"u"};S.toSJIS=function(t){return de(t)};var W={};(function(e){e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(s){if(typeof s!="string")throw new Error("Param is not a string");switch(s.toLowerCase()){case"l":case"low":return e.L;case"m":case"medium":return e.M;case"q":case"quartile":return e.Q;case"h":case"high":return e.H;default:throw new Error("Unknown EC Level: "+s)}}e.isValid=function(n){return n&&typeof n.bit<"u"&&n.bit>=0&&n.bit<4},e.from=function(n,r){if(e.isValid(n))return n;try{return t(n)}catch{return r}}})(W);function xe(){this.buffer=[],this.length=0}xe.prototype={get:function(e){const t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)===1},put:function(e,t){for(let s=0;s${l.innerHTML.replace(/\n/g,"
")}
${l.innerHTML.replace(/\n/g,"
")}
this.bindToMotionValue(i,s)),this.reducedMotionConfig==="never"?this.shouldReduceMotion=!1:this.reducedMotionConfig==="always"?this.shouldReduceMotion=!0:(Vd.current||Bx(),this.shouldReduceMotion=Ko.current),this.shouldSkipAnimations=this.skipAnimationsConfig??!1,(r=this.parent)==null||r.addChild(this),this.update(this.props,this.presenceContext),this.hasBeenMounted=!0}unmount(){var t;this.projection&&this.projection.unmount(),St(this.notifyUpdate),St(this.render),this.valueSubscriptions.forEach(n=>n()),this.valueSubscriptions.clear(),this.removeFromVariantTree&&this.removeFromVariantTree(),(t=this.parent)==null||t.removeChild(this);for(const n in this.events)this.events[n].clear();for(const n in this.features){const r=this.features[n];r&&(r.unmount(),r.isMounted=!1)}this.current=null}addChild(t){this.children.add(t),this.enteringChildren??(this.enteringChildren=new Set),this.enteringChildren.add(t)}removeChild(t){this.children.delete(t),this.enteringChildren&&this.enteringChildren.delete(t)}bindToMotionValue(t,n){if(this.valueSubscriptions.has(t)&&this.valueSubscriptions.get(t)(),n.accelerate&&kx.has(t)&&this.current instanceof HTMLElement){const{factory:o,keyframes:l,times:u,ease:c,duration:d}=n.accelerate,f=new wx({element:this.current,name:t,keyframes:l,times:u,ease:c,duration:dt(d)}),h=o(f);this.valueSubscriptions.set(t,()=>{h(),f.cancel()});return}const r=rs.has(t);r&&this.onBindTransform&&this.onBindTransform();const s=n.on("change",o=>{this.latestValues[t]=o,this.props.onUpdate&&J.preRender(this.notifyUpdate),r&&this.projection&&(this.projection.isTransformDirty=!0),this.scheduleRender()});let i;typeof window<"u"&&window.MotionCheckAppearSync&&(i=window.MotionCheckAppearSync(this,t,n)),this.valueSubscriptions.set(t,()=>{s(),i&&i()})}sortNodePosition(t){return!this.current||!this.sortInstanceNodePosition||this.type!==t.type?0:this.sortInstanceNodePosition(this.current,t.current)}updateFeatures(){let t="animation";for(t in qo){const n=qo[t];if(!n)continue;const{isEnabled:r,Feature:s}=n;if(!this.features[t]&&s&&r(this.props)&&(this.features[t]=new s(this)),this.features[t]){const i=this.features[t];i.isMounted?i.update():(i.mount(),i.isMounted=!0)}}}triggerBuild(){this.build(this.renderState,this.latestValues,this.props)}measureViewportBox(){return this.current?this.measureInstanceViewportBox(this.current,this.props):Ne()}getStaticValue(t){return this.latestValues[t]}setStaticValue(t,n){this.latestValues[t]=n}update(t,n){(t.transformTemplate||this.props.transformTemplate)&&this.scheduleRender(),this.prevProps=this.props,this.props=t,this.prevPresenceContext=this.presenceContext,this.presenceContext=n;for(let r=0;r ${n("home.heroSubtitle")} this.bindToMotionValue(i,s)),this.reducedMotionConfig==="never"?this.shouldReduceMotion=!1:this.reducedMotionConfig==="always"?this.shouldReduceMotion=!0:(Dd.current||Fx(),this.shouldReduceMotion=Wo.current),this.shouldSkipAnimations=this.skipAnimationsConfig??!1,(r=this.parent)==null||r.addChild(this),this.update(this.props,this.presenceContext),this.hasBeenMounted=!0}unmount(){var t;this.projection&&this.projection.unmount(),St(this.notifyUpdate),St(this.render),this.valueSubscriptions.forEach(n=>n()),this.valueSubscriptions.clear(),this.removeFromVariantTree&&this.removeFromVariantTree(),(t=this.parent)==null||t.removeChild(this);for(const n in this.events)this.events[n].clear();for(const n in this.features){const r=this.features[n];r&&(r.unmount(),r.isMounted=!1)}this.current=null}addChild(t){this.children.add(t),this.enteringChildren??(this.enteringChildren=new Set),this.enteringChildren.add(t)}removeChild(t){this.children.delete(t),this.enteringChildren&&this.enteringChildren.delete(t)}bindToMotionValue(t,n){if(this.valueSubscriptions.has(t)&&this.valueSubscriptions.get(t)(),n.accelerate&&vx.has(t)&&this.current instanceof HTMLElement){const{factory:o,keyframes:l,times:u,ease:c,duration:d}=n.accelerate,f=new xx({element:this.current,name:t,keyframes:l,times:u,ease:c,duration:dt(d)}),h=o(f);this.valueSubscriptions.set(t,()=>{h(),f.cancel()});return}const r=ns.has(t);r&&this.onBindTransform&&this.onBindTransform();const s=n.on("change",o=>{this.latestValues[t]=o,this.props.onUpdate&&J.preRender(this.notifyUpdate),r&&this.projection&&(this.projection.isTransformDirty=!0),this.scheduleRender()});let i;typeof window<"u"&&window.MotionCheckAppearSync&&(i=window.MotionCheckAppearSync(this,t,n)),this.valueSubscriptions.set(t,()=>{s(),i&&i()})}sortNodePosition(t){return!this.current||!this.sortInstanceNodePosition||this.type!==t.type?0:this.sortInstanceNodePosition(this.current,t.current)}updateFeatures(){let t="animation";for(t in Go){const n=Go[t];if(!n)continue;const{isEnabled:r,Feature:s}=n;if(!this.features[t]&&s&&r(this.props)&&(this.features[t]=new s(this)),this.features[t]){const i=this.features[t];i.isMounted?i.update():(i.mount(),i.isMounted=!0)}}}triggerBuild(){this.build(this.renderState,this.latestValues,this.props)}measureViewportBox(){return this.current?this.measureInstanceViewportBox(this.current,this.props):Ne()}getStaticValue(t){return this.latestValues[t]}setStaticValue(t,n){this.latestValues[t]=n}update(t,n){(t.transformTemplate||this.props.transformTemplate)&&this.scheduleRender(),this.prevProps=this.props,this.props=t,this.prevPresenceContext=this.presenceContext,this.presenceContext=n;for(let r=0;r ${n("home.heroSubtitle")}$h&&(t.x=1),t.y>>1;FP?(_=S,S=null):_=S.sibling;var C=h(y,S,g[P],k);if(C===null){S===null&&(S=_);break}e&&S&&C.alternate===null&&t(y,S),x=i(C,x,P),T===null?j=C:T.sibling=C,T=C,S=_}if(P===g.length)return n(y,S),me&&Bn(y,P),j;if(S===null){for(;Pe*1e3,vt=e=>e/1e3,dd=(e,t)=>t?e*(1e3/t):0,B0=(e,t,n)=>(((1-3*n+3*t)*e+(3*n-6*t))*e+3*t)*e,Bb=1e-7,$b=12;function Hb(e,t,n,r,s){let i,o,l=0;do o=t+(n-t)/2,i=B0(o,r,s)-e,i>0?n=o:t=o;while(Math.abs(i)>Bb&&++l<$b);return o}function mi(e,t,n,r){if(e===t&&n===r)return ot;const s=i=>Hb(i,0,1,e,n);return i=>i===0||i===1?i:B0(s(i),t,r)}const $0=e=>t=>t<=.5?e(2*t)/2:(2-e(2*(1-t)))/2,H0=e=>t=>1-e(1-t),U0=mi(.33,1.53,.69,.99),fd=H0(U0),W0=$0(fd),G0=e=>e>=1?1:(e*=2)<1?.5*fd(e):.5*(2-Math.pow(2,-10*(e-1))),hd=e=>1-Math.sin(Math.acos(e)),K0=H0(hd),q0=$0(hd),Ub=mi(.42,0,1,1),Wb=mi(0,0,.58,1),Y0=mi(.42,0,.58,1),Gb=e=>Array.isArray(e)&&typeof e[0]!="number",X0=e=>Array.isArray(e)&&typeof e[0]=="number",Kb={linear:ot,easeIn:Ub,easeInOut:Y0,easeOut:Wb,circIn:hd,circInOut:q0,circOut:K0,backIn:fd,backInOut:W0,backOut:U0,anticipate:G0},qb=e=>typeof e=="string",mh=e=>{if(X0(e)){ud(e.length===4);const[t,n,r,s]=e;return mi(t,n,r,s)}else if(qb(e))return Kb[e];return e},Vi=["setup","read","resolveKeyframes","preUpdate","update","preRender","render","postRender"];function Yb(e){let t=new Set,n=new Set,r=!1,s=!1;const i=new WeakSet;let o={delta:0,timestamp:0,isProcessing:!1};function l(c){i.has(c)&&(u.schedule(c),e()),c(o)}const u={schedule:(c,d=!1,f=!1)=>{const p=f&&r?t:n;return d&&i.add(c),p.add(c),c},cancel:c=>{n.delete(c),i.delete(c)},process:c=>{if(o=c,r){s=!0;return}r=!0;const d=t;t=n,n=d,t.forEach(l),t.clear(),r=!1,s&&(s=!1,u.process(c))}};return u}const Xb=40;function Z0(e,t){let n=!1,r=!0;const s={delta:0,timestamp:0,isProcessing:!1},i=()=>n=!0,o=Vi.reduce((g,k)=>(g[k]=Yb(i),g),{}),{setup:l,read:u,resolveKeyframes:c,preUpdate:d,update:f,preRender:h,render:p,postRender:v}=o,w=()=>{const g=An.useManualTiming,k=g?s.timestamp:performance.now();n=!1,g||(s.delta=r?1e3/60:Math.max(Math.min(k-s.timestamp,Xb),1)),s.timestamp=k,s.isProcessing=!0,l.process(s),u.process(s),c.process(s),d.process(s),f.process(s),h.process(s),p.process(s),v.process(s),s.isProcessing=!1,n&&t&&(r=!1,e(w))},b=()=>{n=!0,r=!0,s.isProcessing||e(w)};return{schedule:Vi.reduce((g,k)=>{const j=o[k];return g[k]=(T,S=!1,P=!1)=>(n||b(),j.schedule(T,S,P)),g},{}),cancel:g=>{for(let k=0;k=$o?1/0:t}function Pk(e,t=100,n){const r=n({...e,keyframes:[0,t]}),s=Math.min(yd(r),$o);return{type:"keyframes",ease:i=>r.next(s*i).value/t,duration:vt(s)}}const be={stiffness:100,damping:10,mass:1,velocity:0,duration:800,bounce:.3,visualDuration:.3,restSpeed:{granular:.01,default:2},restDelta:{granular:.005,default:.5},minDuration:.01,maxDuration:10,minDamping:.05,maxDamping:1};function Mu(e,t){return e*Math.sqrt(1-t*t)}const Ck=12;function Ek(e,t,n){let r=n;for(let s=1;szh&&(t.x=1),t.y