import { MemoryRouter as Router, Routes, Route } from 'react-router-dom'; import { useEffect, useState } from 'react'; import { Provider } from 'react-redux'; import Dialog from '@mui/material/Dialog'; import { ThemeProvider, createTheme } from '@mui/material/styles'; import DialogTitle from '@mui/material/DialogTitle'; import DialogContent from '@mui/material/DialogContent'; import DialogActions from '@mui/material/DialogActions'; // import 'tailwindcss/tailwind.css'; import './App.css'; import ClipList from './components/ClipList'; import { useAppDispatch, useAppSelector } from './hooks'; import { store } from '../redux/main'; import { useNavigate } from 'react-router-dom'; import SettingsPage from './Settings'; import apiFetch from './api'; function MainPage() { const dispatch = useAppDispatch(); const collections = useAppSelector((state) => state.collections.map((col) => col.name), ); const [selectedCollection, setSelectedCollection] = useState( collections[0] || 'Uncategorized', ); const [newCollectionOpen, setNewCollectionOpen] = useState(false); const [newCollectionName, setNewCollectionName] = useState(''); const navigate = useNavigate(); useEffect(() => { const fetchMetadata = async () => { try { const response = await apiFetch('meta'); const data = await response.json(); dispatch({ type: 'metadata/setAllData', payload: data }); } catch (error) { console.error('Error fetching metadata:', error); } }; fetchMetadata(); const intervalId = setInterval(fetchMetadata, 5000); return () => clearInterval(intervalId); }, [dispatch]); useEffect(() => { // Update selected collection if collections change if (collections.length > 0 && !collections.includes(selectedCollection)) { setSelectedCollection(collections[0]); } }, [collections, selectedCollection]); const handleNewCollectionSave = () => { if ( newCollectionName.trim() && !collections.includes(newCollectionName.trim()) ) { dispatch({ type: 'metadata/addCollection', payload: newCollectionName.trim(), }); setSelectedCollection(newCollectionName.trim()); fetch('http://localhost:5010/meta/collections/add', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: newCollectionName.trim() }), }) .then((res) => res.json()) .catch((err) => console.error('Error creating collection:', err)); } setNewCollectionOpen(false); setNewCollectionName(''); }; return (
{/* Left Nav Bar - sticky */} setNewCollectionOpen(false)} slotProps={{ paper: { sx: { backgroundColor: '#1a1a1a', color: 'white' } }, }} > Edit Clip Name setNewCollectionName(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') handleNewCollectionSave(); }} aria-label="New collection name" /> {/* Main Content */}
); } export default function App() { const theme = createTheme({ colorSchemes: { light: false, dark: { palette: { primary: { main: '#6e44ba', // plum dark: '#6e44ba', // plum contrastText: '#ffffff', }, secondary: { main: '#4f3186', // plumDark dark: '#4f3186', // plumDark contrastText: '#ffffff', }, }, }, }, // colorSchemes: { // light: false, // dark: true, // }, }); return ( } /> } /> ); }