Update files
This commit is contained in:
parent
ec23fdbf94
commit
723b6824ea
|
|
@ -97,51 +97,72 @@ export default function App() {
|
||||||
const chatSocketRef = useRef(null);
|
const chatSocketRef = useRef(null);
|
||||||
const chatListRef = useRef(null);
|
const chatListRef = useRef(null);
|
||||||
|
|
||||||
const telegramApp = typeof window !== 'undefined' ? window.Telegram?.WebApp : null;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
|
||||||
|
const waitForInitData = async () => {
|
||||||
|
const start = Date.now();
|
||||||
|
const timeout = 5000;
|
||||||
|
|
||||||
|
while (Date.now() - start < timeout) {
|
||||||
|
const app = window.Telegram?.WebApp;
|
||||||
|
if (app?.initData && app.initData.length > 0) {
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||||
|
}
|
||||||
|
throw new Error('Telegram initData не передан (timeout)');
|
||||||
|
};
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
try {
|
try {
|
||||||
if (telegramApp) {
|
const telegramApp = window.Telegram?.WebApp;
|
||||||
telegramApp.disableVerticalSwipes();
|
|
||||||
telegramApp.ready();
|
if (!telegramApp) {
|
||||||
telegramApp.expand();
|
throw new Error('Откройте модераторский интерфейс из Telegram (бот @rbachbot).');
|
||||||
}
|
}
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
telegramApp.disableVerticalSwipes?.();
|
||||||
|
telegramApp.ready?.();
|
||||||
|
telegramApp.expand?.();
|
||||||
|
|
||||||
const initData = telegramApp?.initData || '';
|
const app = await waitForInitData();
|
||||||
|
if (cancelled) return;
|
||||||
|
|
||||||
|
const initData = app.initData || '';
|
||||||
|
|
||||||
|
if (!initData) {
|
||||||
|
throw new Error('Откройте модераторский интерфейс из Telegram (бот @rbachbot).');
|
||||||
|
}
|
||||||
|
|
||||||
if (initData) {
|
|
||||||
const response = await verifyAuth();
|
const response = await verifyAuth();
|
||||||
|
if (cancelled) return;
|
||||||
|
|
||||||
setUser(response.data.user);
|
setUser(response.data.user);
|
||||||
setError(null);
|
setError(null);
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setError('Откройте модераторский интерфейс из Telegram (бот @rbachbot).');
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (cancelled) return;
|
||||||
console.error('Ошибка инициализации модератора:', err);
|
console.error('Ошибка инициализации модератора:', err);
|
||||||
const serverMessage = err?.response?.data?.error;
|
const serverMessage = err?.response?.data?.error || err?.message;
|
||||||
setError(serverMessage || 'Нет доступа. Убедитесь, что вы добавлены как администратор.');
|
setError(serverMessage || 'Нет доступа. Убедитесь, что вы добавлены как администратор.');
|
||||||
} finally {
|
} finally {
|
||||||
|
if (!cancelled) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
const telegramApp = window.Telegram?.WebApp;
|
||||||
|
telegramApp?.MainButton?.setText?.('Закрыть');
|
||||||
|
telegramApp?.MainButton?.show?.();
|
||||||
|
telegramApp?.MainButton?.onClick?.(() => telegramApp.close());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (telegramApp) {
|
|
||||||
telegramApp.MainButton.setText('Закрыть');
|
|
||||||
telegramApp.MainButton.show();
|
|
||||||
telegramApp.MainButton.onClick(() => telegramApp.close());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
telegramApp?.MainButton?.hide();
|
cancelled = true;
|
||||||
|
window.Telegram?.WebApp?.MainButton?.hide?.();
|
||||||
};
|
};
|
||||||
}, [telegramApp]);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (tab === 'users') {
|
if (tab === 'users') {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue