test: testing
All checks were successful
Update changelog / changelog (push) Successful in 28s

This commit is contained in:
Pc
2026-01-04 14:36:29 +01:00
parent 3c1d66ba48
commit 13909c46f6
2 changed files with 54 additions and 26 deletions

View File

@@ -7,19 +7,43 @@ import { KittyGame } from './components/KittyGame';
import { FlappyCat } from './components/FlappyCat';
import { useAuth } from './hooks/useAuth';
// Eksportujemy typ, aby inne pliki mogły go użyć
export type View = 'home' | 'login' | 'history' | 'jump-game' | 'flappy-game';
const getSubdomain = () => {
const hostname = window.location.hostname;
const parts = hostname.split('.');
if (parts.length <= 2) return null;
return parts[0];
};
function App() {
const [url, setUrl] = useState('');
const [view, setView] = useState<View>('home');
const { isAuthenticated, logout } = useAuth();
const subdomain = getSubdomain();
/**
* STAN POCHODNY (Derived State)
* Rozwiązuje błąd "cascading renders". Jeśli użytkownik jest na subdomenie
* i nie jest zalogowany, automatycznie renderujemy widok logowania,
* ale nie nadpisujemy stanu 'view' w nieskończoność.
*/
const activeView = (subdomain && !isAuthenticated) ? 'login' : view;
const renderView = () => {
switch (view) {
switch (activeView) {
case 'login':
return <LoginView onBack={() => setView('home')} onSuccess={() => setView('home')} />;
return (
<LoginView
onBack={() => setView('home')}
onSuccess={() => setView('home')}
/>
);
case 'history':
// Strażnik dostępu dla widoku historii
if (!isAuthenticated) {
return <LoginView onBack={() => setView('home')} onSuccess={() => setView('home')} />;
}
return <HistoryView onBack={() => setView('home')} />;
case 'jump-game':
return <KittyGame onBack={() => setView('home')} />;
@@ -37,7 +61,12 @@ function App() {
isAuthenticated={isAuthenticated}
onLogout={logout}
/>
<main>{renderView()}</main>
<main>
{/* Jeśli użytkownik jest zalogowany (SSO), activeView od razu
pokaże Generator, zamiast LoginView.
*/}
{renderView()}
</main>
</div>
);
}