core/panel/App.tsx

63 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-05-16 07:30:02 +00:00
import { Component, Show, Suspense, createSignal, lazy, onMount } from 'solid-js'
2025-05-16 06:23:48 +00:00
import { isAuthenticated } from './auth'
// Ленивая загрузка компонентов
const AdminPage = lazy(() => import('./admin'))
2025-05-16 07:30:02 +00:00
const LoginPage = lazy(() => import('./login'))
2025-05-16 06:23:48 +00:00
/**
2025-05-16 07:30:02 +00:00
* Корневой компонент приложения с простой логикой отображения
2025-05-16 06:23:48 +00:00
*/
2025-05-16 07:30:02 +00:00
const App: Component = () => {
const [authenticated, setAuthenticated] = createSignal<boolean | null>(null)
const [loading, setLoading] = createSignal(true)
// Проверяем авторизацию при монтировании
onMount(() => {
const authed = isAuthenticated()
setAuthenticated(authed)
setLoading(false)
})
// Обработчик успешной авторизации
const handleLoginSuccess = () => {
setAuthenticated(true)
2025-05-16 06:23:48 +00:00
}
2025-05-16 07:30:02 +00:00
// Обработчик выхода из системы
const handleLogout = () => {
setAuthenticated(false)
2025-05-16 06:23:48 +00:00
}
return (
2025-05-16 07:30:02 +00:00
<div class="app-container">
<Suspense
fallback={
<div class="loading-screen">
<div class="loading-spinner" />
<h2>Загрузка...</h2>
</div>
}
>
<Show
when={!loading()}
fallback={
<div class="loading-screen">
<div class="loading-spinner" />
<h2>Загрузка...</h2>
</div>
}
>
{authenticated() ? (
<AdminPage onLogout={handleLogout} />
) : (
<LoginPage onLoginSuccess={handleLoginSuccess} />
)}
</Show>
2025-05-16 06:23:48 +00:00
</Suspense>
2025-05-16 07:30:02 +00:00
</div>
2025-05-16 06:23:48 +00:00
)
}
export default App