import { useEffect, useState } from 'react'; import './App.css'; import SectionGrid from './components/SectionGrid'; import AppModal from './components/AppModal'; import ConfirmDialog from './components/ConfirmDialog'; import Clock from './components/Clock'; import { ToastContainer, toast } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; import { IoIosAdd } from 'react-icons/io'; import CustomToast from './components/CustomToast'; import { fetchSections, addAppToSection, editAppInSection, deleteAppFromSection, } from './services/api'; function App() { const [sections, setSections] = useState([]); const [editData, setEditData] = useState(null); const [showAdd, setShowAdd] = useState(false); const [confirmData, setConfirmData] = useState(null); const [searchTerm, setSearchTerm] = useState(''); const loadSections = () => { fetchSections() .then(data => { const filtered = (data.sections || []).filter(section => (section.apps?.length ?? 0) > 0); setSections(filtered); }) .catch(err => console.error('Failed to fetch sections:', err)); }; useEffect(() => { loadSections(); }, []); const handleDelete = (app) => { setConfirmData({ message: `Are you sure you want to delete "${app.name}"?`, app, }); }; const confirmDelete = async () => { if (!confirmData?.app) return; try { await deleteAppFromSection({ section: confirmData.app.section, app: confirmData.app, }); toast(); loadSections(); } catch (err) { console.error('Failed to delete app:', err); toast.error('Failed to delete app'); } finally { setConfirmData(null); } }; const handleAddSubmit = async (data) => { try { await addAppToSection(data); toast(); setShowAdd(false); loadSections(); } catch (err) { console.error('Failed to add app:', err); toast.error('Failed to add app'); } }; const handleEditSubmit = async (data) => { try { await editAppInSection({ section: data.section, app: data.app, original_name: data.original_name || data.app.name, }); toast(); setEditData(null); loadSections(); } catch (err) { console.error('Failed to update app:', err); toast.error('Failed to update app'); } }; const filteredSections = sections.map(section => ({ ...section, apps: section.apps.filter(app => app.name.toLowerCase().includes(searchTerm.toLowerCase()) ), })).filter(section => section.apps.length > 0); return (

Navix logo Navix

{/* 🔍 Search Box */}
setSearchTerm(e.target.value)} className="search-input" />
{showAdd && ( setShowAdd(false)} sections={sections} /> )} {editData && ( setEditData(null)} sections={sections} /> )} {confirmData && ( setConfirmData(null)} /> )} {filteredSections.map((section) => ( setEditData({ ...app, section: section.name, original_name: app.name }) } onDelete={handleDelete} /> ))} setShowAdd(true)} />
); } export default App;