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 io from 'socket.io-client'; // 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, getBaseUrl } 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(() => {}, []); useEffect(() => { let newSocket: any = null; const initializeSocket = async () => { const baseUrl = await getBaseUrl(); newSocket = io(baseUrl); newSocket.on('connect', () => { console.log('Connected to WebSocket server'); }); newSocket.on('full_data', (data: any) => { console.log('Received full_data from server:', data); dispatch({ type: 'metadata/setAllData', payload: { collections: data }, }); }); newSocket.on('new_clip', (data: any) => { console.log('Received new_clips from server:', data); dispatch({ type: 'metadata/addNewClip', payload: { clip: data }, }); }); }; initializeSocket(); return () => { if (newSocket) { newSocket.off('connect'); newSocket.off('full_data'); newSocket.off('new_clip'); newSocket.disconnect(); } }; }, [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 ( } /> } /> ); }