// Main app — fetches data via window.API, then renders the right shell.
//
// Flow:
// mount → loading splash
// → API.fetchAll() →
// • { authenticated: false } → NotAuthenticated (Landing, login hint)
// • { authenticated: true, hasPair: false } → Landing with create/join
// • { authenticated: true, hasPair: true } → full shell with screens
//
// Each screen receives a `reload` callback so its write actions can re-fetch.
function LoadingSplash() {
return (
💕
Вопрос дня
Загружаем…
);
}
function NotAuthenticated() {
return (
Чтобы начать играть, сначала войдите через{' '}
tgplay.ru.
);
}
function ErrorScreen({ message, onRetry }) {
return (
⚠️
Не удалось загрузить
{message}
);
}
function App() {
const { useState, useEffect, useCallback } = React;
const [screen, setScreen] = useState('today');
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const load = useCallback(async () => {
try {
const d = await window.API.fetchAll();
setData(d);
setError(null);
} catch (e) {
setError(e.message || 'Неизвестная ошибка');
} finally {
setLoading(false);
}
}, []);
// Wrapped reload: doesn't toggle the loading splash (used by write actions)
const reload = useCallback(async () => {
try {
const d = await window.API.fetchAll();
setData(d);
} catch (e) {
// Swallow — keep current data visible, the originating action will surface the error
console.warn('reload failed', e);
}
}, []);
useEffect(() => { load(); }, [load]);
if (loading) return ;
if (error) return { setLoading(true); load(); }}/>;
if (!data || !data.authenticated) return ;
// Logged in but no pair: show Landing full-bleed with topbar, no sidebar.
if (!data.hasPair) {
return (
);
}
const state = data.state;
function renderScreen() {
const props = { state, setScreen, data, reload };
switch (screen) {
case 'today': return ;
case 'reveal': return ;
case 'archive': return ;
case 'stats': return ;
case 'capsule': return ;
case 'settings': return ;
case 'onboarding': return ;
case 'landing': return ;
default: return ;
}
}
return (