Spaces:
Running
Running
Commit ·
94eb7aa
1
Parent(s): 874b177
fix lending
Browse files- src/components/Sidebar.jsx +11 -2
- src/context/ThemeContext.jsx +2 -1
- src/pages/LandingPage.jsx +14 -0
src/components/Sidebar.jsx
CHANGED
|
@@ -37,12 +37,18 @@ const SidebarItem = ({ icon: Icon, label, active, onClick, badge }) => (
|
|
| 37 |
</motion.button>
|
| 38 |
);
|
| 39 |
|
|
|
|
|
|
|
| 40 |
const Sidebar = () => {
|
| 41 |
const navigate = useNavigate();
|
| 42 |
const location = useLocation();
|
| 43 |
const { logout, user } = useAuth();
|
| 44 |
const { t } = useTranslation();
|
| 45 |
-
const [projectCount, setProjectCount] = useState(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
useEffect(() => {
|
| 48 |
if (!user) return;
|
|
@@ -51,7 +57,10 @@ const Sidebar = () => {
|
|
| 51 |
const API_URL = import.meta.env.VITE_API_URL;
|
| 52 |
const res = await axios.get(`${API_URL}/graphs/user/${user.id}`);
|
| 53 |
if (Array.isArray(res.data)) {
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
}
|
| 56 |
} catch (err) {
|
| 57 |
console.error('[Sidebar] Failed to fetch project count:', err);
|
|
|
|
| 37 |
</motion.button>
|
| 38 |
);
|
| 39 |
|
| 40 |
+
let cachedProjectCount = null;
|
| 41 |
+
|
| 42 |
const Sidebar = () => {
|
| 43 |
const navigate = useNavigate();
|
| 44 |
const location = useLocation();
|
| 45 |
const { logout, user } = useAuth();
|
| 46 |
const { t } = useTranslation();
|
| 47 |
+
const [projectCount, setProjectCount] = useState(() => {
|
| 48 |
+
if (cachedProjectCount !== null) return cachedProjectCount;
|
| 49 |
+
const stored = localStorage.getItem('tf_project_count');
|
| 50 |
+
return stored ? parseInt(stored, 10) : 0;
|
| 51 |
+
});
|
| 52 |
|
| 53 |
useEffect(() => {
|
| 54 |
if (!user) return;
|
|
|
|
| 57 |
const API_URL = import.meta.env.VITE_API_URL;
|
| 58 |
const res = await axios.get(`${API_URL}/graphs/user/${user.id}`);
|
| 59 |
if (Array.isArray(res.data)) {
|
| 60 |
+
const count = res.data.length;
|
| 61 |
+
setProjectCount(count);
|
| 62 |
+
cachedProjectCount = count;
|
| 63 |
+
localStorage.setItem('tf_project_count', count.toString());
|
| 64 |
}
|
| 65 |
} catch (err) {
|
| 66 |
console.error('[Sidebar] Failed to fetch project count:', err);
|
src/context/ThemeContext.jsx
CHANGED
|
@@ -10,7 +10,8 @@ export const ThemeProvider = ({ children }) => {
|
|
| 10 |
|
| 11 |
useEffect(() => {
|
| 12 |
const root = document.documentElement;
|
| 13 |
-
|
|
|
|
| 14 |
root.classList.add('dark');
|
| 15 |
} else {
|
| 16 |
root.classList.remove('dark');
|
|
|
|
| 10 |
|
| 11 |
useEffect(() => {
|
| 12 |
const root = document.documentElement;
|
| 13 |
+
const isLanding = window.location.pathname === '/';
|
| 14 |
+
if (theme === 'dark' && !isLanding) {
|
| 15 |
root.classList.add('dark');
|
| 16 |
} else {
|
| 17 |
root.classList.remove('dark');
|
src/pages/LandingPage.jsx
CHANGED
|
@@ -18,6 +18,20 @@ const LandingPage = () => {
|
|
| 18 |
}
|
| 19 |
}, [user, navigate]);
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
return (
|
| 22 |
<div className="flex flex-col items-center w-full">
|
| 23 |
<HeroSection />
|
|
|
|
| 18 |
}
|
| 19 |
}, [user, navigate]);
|
| 20 |
|
| 21 |
+
useEffect(() => {
|
| 22 |
+
const root = document.documentElement;
|
| 23 |
+
const wasDark = root.classList.contains('dark');
|
| 24 |
+
if (wasDark) {
|
| 25 |
+
root.classList.remove('dark');
|
| 26 |
+
}
|
| 27 |
+
return () => {
|
| 28 |
+
const savedTheme = localStorage.getItem('theme');
|
| 29 |
+
if (savedTheme === 'dark') {
|
| 30 |
+
root.classList.add('dark');
|
| 31 |
+
}
|
| 32 |
+
};
|
| 33 |
+
}, []);
|
| 34 |
+
|
| 35 |
return (
|
| 36 |
<div className="flex flex-col items-center w-full">
|
| 37 |
<HeroSection />
|