Spaces:
Running
Running
File size: 9,405 Bytes
0dcbaee de55c35 295a30c 0dcbaee de55c35 0dcbaee de55c35 0dcbaee de55c35 0dcbaee 385c360 0dcbaee 385c360 0dcbaee 385c360 de55c35 295a30c de55c35 abb5ee1 de55c35 385c360 de55c35 0dcbaee de55c35 0dcbaee de55c35 0dcbaee de55c35 0dcbaee de55c35 385c360 de55c35 0dcbaee de55c35 0dcbaee de55c35 0dcbaee de55c35 295a30c abb5ee1 de55c35 0dcbaee de55c35 0dcbaee de55c35 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | import React from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { Link, useLocation } from 'react-router-dom';
import { useAuth } from '../context/AuthContext';
import logo from '../assets/logo.png';
import { useTranslation } from 'react-i18next';
import { getLandingCopy } from '../features/landing/landingCopy';
const Layout = ({ children }) => {
const { user } = useAuth();
const location = useLocation();
const isLanding = location.pathname === '/';
const [isMobileMenuOpen, setIsMobileMenuOpen] = React.useState(false);
const { i18n } = useTranslation();
const copy = getLandingCopy(i18n.language).nav;
const isUk = i18n.language?.startsWith('uk');
const toggleLanguage = () => {
const next = isUk ? 'en' : 'uk';
i18n.changeLanguage(next);
try { localStorage.setItem('language', next); } catch { /* ignore */ }
};
const navItems = [
{ name: copy.product, href: '#product' },
{ name: copy.how, href: '#how-it-works' },
{ name: copy.templates, href: '#templates' },
{ name: copy.pricing, href: '#pricing' }
];
const [activeSection, setActiveSection] = React.useState('#product');
React.useEffect(() => {
if (!isLanding) return;
const timer = setTimeout(() => {
const observerOptions = {
root: null,
rootMargin: '-30% 0px -60% 0px',
threshold: 0
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
if (entry.target.id === 'hero') {
setActiveSection('#product');
} else {
setActiveSection(`#${entry.target.id}`);
}
}
});
}, observerOptions);
const sectionsToObserve = ['hero', 'product', 'how-it-works', 'templates', 'pricing'];
sectionsToObserve.forEach(id => {
const el = document.getElementById(id);
if (el) observer.observe(el);
});
return () => observer.disconnect();
}, 100);
return () => clearTimeout(timer);
}, [isLanding]);
return (
<div className="flex flex-col min-h-screen text-on-background">
{/* TopNavBar */}
<nav className="bg-surface-container-lowest border-b-2 border-primary shadow-[6px_6px_0px_0px_var(--color-primary)] dark:shadow-[6px_6px_0px_0px_rgba(255,255,255,0.07)] sticky top-0 z-50">
<div className="flex justify-between items-center w-full px-margin_edge py-5 max-w-screen-2xl mx-auto">
<Link to="/">
<motion.div
initial={{ opacity: 0, x: -20 }}
animate={{ opacity: 1, x: 0 }}
className="font-display-lg text-4xl text-primary tracking-tight cursor-pointer flex items-center gap-3"
>
<img src={logo} alt="TaskFlow Logo" className="w-10 h-10 object-contain" />
<span>TaskFlow</span>
</motion.div>
</Link>
<div className="hidden md:flex gap-gutter items-center">
{navItems.map((item, i) => {
const isActive = activeSection === item.href;
return (
<motion.a
key={item.name}
initial={{ opacity: 0, y: -10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.1 * i }}
className={`text-xl transition-all relative py-2 ${
isActive
? 'text-primary font-bold border-b-2 border-secondary'
: 'text-on-surface-variant hover:text-primary'
}`}
href={isLanding ? item.href : `/${item.href}`}
>
{item.name}
</motion.a>
);
})}
</div>
<div className="flex gap-6 items-center">
<button
onClick={toggleLanguage}
className="px-2.5 py-1 rounded-lg border-2 border-primary/20 hover:border-primary text-sm font-bold text-primary transition-colors cursor-pointer"
title={isUk ? 'English' : 'Українська'}
>
{isUk ? 'EN' : 'UA'}
</button>
<div className="hidden sm:flex gap-6 items-center">
{user ? (
<Link to="/dashboard">
<motion.button
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
className="bg-primary text-on-primary font-bold py-3 px-6 rough-border rough-shadow-hover transition-all text-xl"
>
{copy.workspace}
</motion.button>
</Link>
) : (
<>
<Link to="/auth">
<button className="text-xl font-medium text-on-surface-variant hover:text-primary transition-colors">{copy.login}</button>
</Link>
<Link to="/auth">
<motion.button
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
className="bg-primary text-on-primary font-bold py-3 px-6 rough-border rough-shadow-hover transition-all"
>
{copy.start}
</motion.button>
</Link>
</>
)}
</div>
{/* Mobile Menu Toggle */}
<button
className="md:hidden p-2 text-primary"
onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}
>
<svg xmlns="http://www.w3.org/2000/svg" className="h-10 w-10" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d={isMobileMenuOpen ? "M6 18L18 6M6 6l12 12" : "M4 6h16M4 12h16M4 18h16"} />
</svg>
</button>
</div>
</div>
{/* Mobile Menu Overlay */}
<AnimatePresence>
{isMobileMenuOpen && (
<motion.div
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: 1, height: 'auto' }}
exit={{ opacity: 0, height: 0 }}
className="md:hidden bg-surface-container-lowest border-t-2 border-primary overflow-hidden"
>
<div className="flex flex-col p-margin_edge gap-6">
{navItems.map((item) => {
const isActive = activeSection === item.href;
return (
<a
key={item.name}
href={isLanding ? item.href : `/${item.href}`}
className={`text-2xl font-display-lg transition-colors ${
isActive ? 'text-primary font-bold' : 'text-on-surface-variant hover:text-primary'
}`}
onClick={() => setIsMobileMenuOpen(false)}
>
{item.name}
</a>
);
})}
<div className="flex flex-col gap-4 pt-6 border-t border-dashed border-primary/20">
{user ? (
<Link to="/dashboard" onClick={() => setIsMobileMenuOpen(false)}>
<button className="w-full py-4 text-2xl font-bold bg-primary text-on-primary rough-border rough-shadow">{copy.workspace}</button>
</Link>
) : (
<>
<Link to="/auth" onClick={() => setIsMobileMenuOpen(false)}>
<button className="w-full py-4 text-2xl font-bold text-primary rough-border">{copy.login}</button>
</Link>
<Link to="/auth" onClick={() => setIsMobileMenuOpen(false)}>
<button className="w-full py-4 text-2xl font-bold bg-primary text-on-primary rough-border rough-shadow">{copy.start}</button>
</Link>
</>
)}
</div>
</div>
</motion.div>
)}
</AnimatePresence>
</nav>
{/* Page Content */}
<main className="flex-grow">
{children}
</main>
{/* Footer */}
<footer className="bg-surface-container-lowest w-full border-t-4 border-primary mt-20">
<div className="grid grid-cols-1 md:grid-cols-2 gap-gutter px-margin_edge py-16 w-full max-w-screen-2xl mx-auto">
<div className="flex flex-col gap-6">
<div className="text-5xl font-display-lg text-primary flex items-center gap-3">
<img src={logo} alt="TaskFlow Logo" className="w-12 h-12 object-contain" />
<span>TaskFlow</span>
</div>
<div className="text-xl text-on-surface-variant">
© 2026 TaskFlow
</div>
</div>
<div className="flex flex-wrap gap-10 items-center md:justify-end">
{navItems.map(item => (
<a key={item.href} className="text-xl font-bold text-on-surface-variant hover:text-primary underline decoration-secondary decoration-4 transition-all" href={isLanding ? item.href : `/${item.href}`}>{item.name}</a>
))}
</div>
</div>
</footer>
</div>
);
};
export default Layout;
|