fix(frontend): 🐛 resolve duplicate audience detection logic in AudienceRouter.tsx
This commit is contained in:
parent
bd9957d6ab
commit
446e09f4ef
2 changed files with 18 additions and 18 deletions
|
|
@ -5,9 +5,10 @@
|
|||
* Consumes theme from ThemeProvider and deployment config for vertical-specific branding.
|
||||
*/
|
||||
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { Link, useLocation, useNavigate } from 'react-router-dom';
|
||||
import styled from 'styled-components';
|
||||
import { useDeploymentConfig } from '../hooks/useDeploymentConfig';
|
||||
import { clearStoredAudience } from '../features/landing/hooks/useAudienceDetection';
|
||||
|
||||
const HeaderContainer = styled.header`
|
||||
position: sticky;
|
||||
|
|
@ -231,9 +232,18 @@ const MobileMenuButton = styled.button`
|
|||
|
||||
export function MarketplaceHeader() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const currentPath = location.pathname;
|
||||
const { branding, vertical } = useDeploymentConfig();
|
||||
|
||||
// Clear audience choice when navigating home via logo
|
||||
// This allows users to return to the choice screen
|
||||
const handleLogoClick = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
clearStoredAudience();
|
||||
navigate('/');
|
||||
};
|
||||
|
||||
const isActive = (path: string) => {
|
||||
if (path === '/' || path === '') {
|
||||
return currentPath === '/';
|
||||
|
|
@ -250,7 +260,7 @@ export function MarketplaceHeader() {
|
|||
return (
|
||||
<HeaderContainer>
|
||||
<HeaderInner>
|
||||
<LogoSection to="/">
|
||||
<LogoSection to="/" onClick={handleLogoClick}>
|
||||
<LogoIcon>
|
||||
<LogoSvg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@
|
|||
* 5. Default to choice screen
|
||||
*/
|
||||
|
||||
import { lazy, Suspense, useState, useCallback } from 'react';
|
||||
import { useAudienceDetection, type AudienceType } from '../hooks/useAudienceDetection';
|
||||
import { lazy, Suspense } from 'react';
|
||||
import { useAudienceDetection } from '../hooks/useAudienceDetection';
|
||||
|
||||
// Lazy load the landing pages
|
||||
const WorkerLandingPage = lazy(() => import('./WorkerLandingPage'));
|
||||
|
|
@ -55,32 +55,22 @@ function PageLoader() {
|
|||
export default function AudienceRouter() {
|
||||
const { audience, confidence } = useAudienceDetection();
|
||||
|
||||
// Allow overriding from choice screen without navigation
|
||||
const [overrideAudience, setOverrideAudience] = useState<AudienceType | null>(null);
|
||||
|
||||
const handleChoice = useCallback((choice: 'worker' | 'client') => {
|
||||
setOverrideAudience(choice);
|
||||
}, []);
|
||||
|
||||
// Use override if set, otherwise use detected audience
|
||||
const effectiveAudience = overrideAudience || audience;
|
||||
|
||||
// Determine whether to show audience toggle
|
||||
// Show toggle when confidence is medium (detected but not definitive)
|
||||
const showToggle = confidence === 'medium';
|
||||
|
||||
return (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
{effectiveAudience === 'worker' && (
|
||||
{audience === 'worker' && (
|
||||
<WorkerLandingPage showAudienceToggle={showToggle} />
|
||||
)}
|
||||
|
||||
{effectiveAudience === 'client' && (
|
||||
{audience === 'client' && (
|
||||
<ClientLandingPage showAudienceToggle={showToggle} />
|
||||
)}
|
||||
|
||||
{effectiveAudience === 'unknown' && (
|
||||
<AudienceChoiceScreen onChoice={handleChoice} />
|
||||
{audience === 'unknown' && (
|
||||
<AudienceChoiceScreen />
|
||||
)}
|
||||
</Suspense>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue