Restructure with Turborepo
Run Tests on Branches / Backend Tests (push) Successful in 3m38s
Run Tests on Branches / Frontend Tests (push) Successful in 3m28s

This commit is contained in:
Antoni Nuñez Romeu
2026-07-06 15:51:53 +02:00
parent f66cafbbc3
commit 190b3d163d
277 changed files with 53253 additions and 0 deletions
+163
View File
@@ -0,0 +1,163 @@
import React, { useState, useEffect } from 'react';
import './App.css';
import HomeView from './views/HomeView';
import SearchView from './views/SearchView';
import ScannerView from './views/ScannerView';
import AlertsView from './views/AlertsView';
import ProfileView from './views/ProfileView';
import AdminView from './views/AdminView';
import LoginModal from './components/LoginModal';
import SavedNotifications from './components/SavedNotifications';
import BottomNav from './components/BottomNav';
function App() {
const [screen, setScreen] = useState('home');
const [currentUser, setCurrentUser] = useState(null);
const [authChecked, setAuthChecked] = useState(false);
const [showLogin, setShowLogin] = useState(false);
const [showSaved, setShowSaved] = useState(false);
const [screenSize, setScreenSize] = useState({
width: window.innerWidth,
height: window.innerHeight
});
// Device detection
const isMobile = screenSize.width <= 768;
const isTablet = screenSize.width > 768 && screenSize.width <= 1024;
const isDesktop = screenSize.width > 1024;
useEffect(() => {
// Set initial screen size
const handleResize = () => {
setScreenSize({
width: window.innerWidth,
height: window.innerHeight
});
};
fetch('/api/auth/check')
.then(r => r.json())
.then(data => { if (data.authenticated) setCurrentUser(data.user); })
.catch(() => {})
.finally(() => setAuthChecked(true));
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
function handleLogin(user) {
setCurrentUser(user);
setShowLogin(false);
}
async function handleLogout() {
await fetch('/api/auth/logout', { method: 'POST' }).catch(() => {});
setCurrentUser(null);
setScreen('home');
}
function handleProfileSaved(updated) {
setCurrentUser(prev => ({ ...prev, ...updated }));
}
function handleAdminClick() {
setScreen('admin');
}
const isLoggedIn = Boolean(currentUser);
function handleNavChange(tab) {
if (tab === 'home') { setScreen('home'); return; }
if (tab === 'search') { setScreen('search'); return; }
if (tab === 'scan') { setScreen('scan'); return; }
if (tab === 'alerts') {
if (currentUser) setScreen('alerts');
else setShowLogin(true);
return;
}
if (tab === 'profile') {
if (currentUser) setScreen('profile');
else setShowLogin(true);
return;
}
}
let activeView;
let deviceClass = isMobile ? 'mobile-view' : 'desktop-view';
switch (screen) {
case 'profile':
activeView = (
<ProfileView
currentUser={currentUser}
onProfileSaved={handleProfileSaved}
onShowSaved={() => setShowSaved(true)}
onLogout={handleLogout}
onAdminClick={handleAdminClick}
/>
);
break;
case 'alerts':
activeView = <AlertsView />;
break;
case 'search':
activeView = (
<SearchView
currentUser={currentUser}
onLoginRequest={() => setShowLogin(true)}
/>
);
break;
case 'scan':
activeView = (
<ScannerView
onClose={() => setScreen('home')}
onSelectMedicine={(name) => {
setScreen('home');
}}
/>
);
break;
case 'admin':
activeView = <AdminView />;
break;
default:
activeView = (
<HomeView
currentUser={currentUser}
onLoginRequest={() => setShowLogin(true)}
onScanClick={() => setScreen('scan')}
onSearchClick={() => setScreen('search')}
/>
);
break;
}
return (
<div className={`app ${deviceClass}`}>
<div className="app-content">
{activeView}
</div>
<BottomNav
activeTab={screen}
onChange={handleNavChange}
isLoggedIn={Boolean(currentUser)}
badgeCount={currentUser ? 2 : 0}
/>
{showLogin && (
<LoginModal
onLogin={handleLogin}
onClose={() => setShowLogin(false)}
/>
)}
{showSaved && currentUser && (
<SavedNotifications onClose={() => setShowSaved(false)} />
)}
</div>
);
}
export default App;