import React, { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { motion, AnimatePresence } from 'framer-motion'; import { Plus, Settings, TrendingUp, Flame, Calendar, Moon, Sun } from 'lucide-react'; import { Button } from '../components/ui/button'; import { useToast } from '../components/ui/use-toast'; import HabitCard from '../components/HabitCard'; import { getHabits } from '../lib/storage'; const HomePage = () => { const navigate = useNavigate(); const { toast } = useToast(); const [habits, setHabits] = useState([]); const [isPremium] = useState(false); const [darkMode, setDarkMode] = useState(() => { return localStorage.getItem('theme') === 'dark'; }); useEffect(() => { loadHabits(); }, []); useEffect(() => { if (darkMode) { document.documentElement.classList.add('dark'); localStorage.setItem('theme', 'dark'); } else { document.documentElement.classList.remove('dark'); localStorage.setItem('theme', 'light'); } }, [darkMode]); const loadHabits = () => { const loadedHabits = getHabits(); setHabits(loadedHabits); }; const handleAddHabit = () => { if (!isPremium && habits.length >= 1000) { toast({ title: "🔒 Premium Feature", description: "Free tier limited to 1000 habits. Upgrade to unlock unlimited habits!", duration: 4000, }); return; } navigate('/add'); }; return (
Commit to yourself, one square at a time
{habits.length}
{habits.reduce((sum, h) => sum + (h.currentStreak || 0), 0)}
Create your first habit and watch your progress every day as you fill in the squares. Small steps lead to big changes!