UI: таббар скрыт пока не залогинился
- index.html: <nav id="tabbar" hidden> - app.js: updateTabbar() — скрыть/показать по loggedIn - emailLogin: onLogin() после успеха - settings.logout: onLogout() + POST /auth/logout - backend: POST /auth/logout — чистит cookie
This commit is contained in:
parent
2af273ffbe
commit
0fa3dcc573
@ -14,7 +14,7 @@
|
|||||||
<button id="mode-toggle" title="Переключить режим">📱 Мобильный</button>
|
<button id="mode-toggle" title="Переключить режим">📱 Мобильный</button>
|
||||||
<div id="mobile-frame">
|
<div id="mobile-frame">
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<nav id="tabbar">
|
<nav id="tabbar" hidden>
|
||||||
<button class="tab" data-view="map">
|
<button class="tab" data-view="map">
|
||||||
<svg viewBox="0 0 24 24" width="24" height="24"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5a2.5 2.5 0 0 1 0-5 2.5 2.5 0 0 1 0 5z"/></svg>
|
<svg viewBox="0 0 24 24" width="24" height="24"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5a2.5 2.5 0 0 1 0-5 2.5 2.5 0 0 1 0 5z"/></svg>
|
||||||
<span>Карта</span>
|
<span>Карта</span>
|
||||||
|
|||||||
@ -54,6 +54,9 @@ const App = {
|
|||||||
this.showWelcome();
|
this.showWelcome();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// таббар виден только после авторизации
|
||||||
|
this.updateTabbar();
|
||||||
|
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
if (e.key === 'Enter' && !e.shiftKey && document.activeElement?.id === 'msg-input') return;
|
if (e.key === 'Enter' && !e.shiftKey && document.activeElement?.id === 'msg-input') return;
|
||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape') {
|
||||||
@ -73,6 +76,25 @@ const App = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateTabbar() {
|
||||||
|
// таббар виден только если залогинен (есть access token или мы в Telegram WebApp)
|
||||||
|
const tb = document.getElementById('tabbar');
|
||||||
|
if (!tb) return;
|
||||||
|
const loggedIn = !!(API.Store.access || API.Store.user || (TG_APP.isAvailable && TG_APP.user));
|
||||||
|
tb.hidden = !loggedIn;
|
||||||
|
},
|
||||||
|
|
||||||
|
onLogin() {
|
||||||
|
API.Store.load();
|
||||||
|
this.updateTabbar();
|
||||||
|
},
|
||||||
|
|
||||||
|
onLogout() {
|
||||||
|
API.Store.clear();
|
||||||
|
this.updateTabbar();
|
||||||
|
this.showWelcome();
|
||||||
|
},
|
||||||
|
|
||||||
async checkConsent() {
|
async checkConsent() {
|
||||||
try {
|
try {
|
||||||
const s = await API.ConsentApi.status();
|
const s = await API.ConsentApi.status();
|
||||||
@ -245,8 +267,9 @@ const App = {
|
|||||||
try {
|
try {
|
||||||
await API.Auth.loginEmail(email, pass);
|
await API.Auth.loginEmail(email, pass);
|
||||||
await API.Auth.me();
|
await API.Auth.me();
|
||||||
|
this.onLogin(); // показать таббар
|
||||||
// для email-логина согласия можно проверить, но юзер их уже дал
|
// для email-логина согласия можно проверить, но юзер их уже дал
|
||||||
await this.maybeOnboard();
|
this.maybeOnboard();
|
||||||
this.showView('map');
|
this.showView('map');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
TG_APP.showAlert('Ошибка: ' + e.message);
|
TG_APP.showAlert('Ошибка: ' + e.message);
|
||||||
@ -305,6 +328,9 @@ const App = {
|
|||||||
const root = document.getElementById('app');
|
const root = document.getElementById('app');
|
||||||
if (window.ChatView?.cleanup) window.ChatView.cleanup();
|
if (window.ChatView?.cleanup) window.ChatView.cleanup();
|
||||||
|
|
||||||
|
// обновить видимость таббара (не виден пока не залогинился)
|
||||||
|
this.updateTabbar();
|
||||||
|
|
||||||
// мгновенный placeholder — чтоб UI не висел при тяжёлом render
|
// мгновенный placeholder — чтоб UI не висел при тяжёлом render
|
||||||
if (root) {
|
if (root) {
|
||||||
root.innerHTML = '<div class="view" style="display:flex;justify-content:center;padding:40px;"><div class="loader"></div></div>';
|
root.innerHTML = '<div class="view" style="display:flex;justify-content:center;padding:40px;"><div class="loader"></div></div>';
|
||||||
|
|||||||
@ -25,7 +25,9 @@ const SettingsView = {
|
|||||||
document.getElementById('logout').onclick = async () => {
|
document.getElementById('logout').onclick = async () => {
|
||||||
const ok = await TG_APP.showConfirm('Выйти из BuhApp?');
|
const ok = await TG_APP.showConfirm('Выйти из BuhApp?');
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
API.Store.clear();
|
// очистим cookie на бэкенде (best-effort, без await)
|
||||||
|
try { await fetch('https://api.buhapp.mygoodservice.ru/api/v1/auth/logout', { method: 'POST', credentials: 'include' }); } catch {}
|
||||||
|
App.onLogout();
|
||||||
location.reload();
|
location.reload();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user