From 2dc33598d80358dd4c8b618cb0d42aa2054f2005 Mon Sep 17 00:00:00 2001
From: Roman Sergienko <romasergienko@outlook.com>
Date: Fri, 04 Dec 2026 08:23:53 +0000
Subject: [PATCH] Use KeyboardButton with web_app for /panel command to open Mini App

---
 web/templates/base.html |   65 +++++++++++++++++++++++++-------
 1 files changed, 50 insertions(+), 15 deletions(-)

diff --git a/web/templates/base.html b/web/templates/base.html
index b5f36cb..172bc8b 100644
--- a/web/templates/base.html
+++ b/web/templates/base.html
@@ -2,7 +2,8 @@
 <html lang="ru" class="dark">
 <head>
     <meta charset="utf-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
+    <script src="https://telegram.org/js/telegram-web-app.js"></script>
     <title>{% block title %}Amadeus{% endblock %}</title>
     <script>
         // Применяем сохранённую тему до отрисовки, чтобы не мигало.
@@ -32,12 +33,16 @@
 </head>
 <body class="min-h-screen bg-gray-50 text-gray-900 dark:bg-gray-950 dark:text-gray-100 font-sans antialiased">
 <div class="flex min-h-screen">
-    <aside class="hidden md:flex w-64 shrink-0 flex-col border-r border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900">
-        <div class="h-16 flex items-center gap-2 px-5 border-b border-gray-200 dark:border-gray-800">
-            <span class="inline-flex h-8 w-8 items-center justify-center rounded-lg bg-brand-600 text-white font-bold">A</span>
+    <!-- Сайдбар: только на десктопе -->
+    <aside class="hidden w-64 shrink-0 flex-col border-r border-gray-200 bg-white dark:border-gray-800 dark:bg-gray-900 md:flex">
+        <div class="flex h-16 items-center gap-2 border-b border-gray-200 px-5 dark:border-gray-800">
+            <span class="relative inline-flex h-8 w-8 items-center justify-center overflow-hidden rounded-lg bg-brand-600 font-bold text-white">
+                A
+                <img src="/avatar/bot" alt="" class="absolute inset-0 h-full w-full object-cover" onerror="this.remove()">
+            </span>
             <span class="text-lg font-semibold">Amadeus</span>
         </div>
-        <nav class="flex-1 p-3 space-y-1 text-sm">
+        <nav class="flex-1 space-y-1 overflow-y-auto p-3 text-sm">
             {% set items = [
                 ("dash", "/", "Дашборд"),
                 ("chats", "/chats", "Чаты"),
@@ -47,18 +52,18 @@
             ] %}
             {% for key, href, label in items %}
             <a href="{{ href }}"
-               class="flex items-center rounded-lg px-3 py-2 transition
+               class="flex items-center rounded-lg px-3 py-2.5 transition
                {% if active == key %}bg-brand-600 text-white shadow{% else %}text-gray-600 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-800{% endif %}">
                 {{ label }}
             </a>
             {% endfor %}
         </nav>
-        <div class="p-3 border-t border-gray-200 dark:border-gray-800">
+        <div class="border-t border-gray-200 p-3 dark:border-gray-800">
             <div class="flex items-center gap-3">
                 {% if user and user.photo_url %}
                 <img src="{{ user.photo_url }}" class="h-9 w-9 rounded-full object-cover" alt="">
                 {% else %}
-                <span class="inline-flex h-9 w-9 items-center justify-center rounded-full bg-gray-200 dark:bg-gray-700 text-sm font-medium">
+                <span class="inline-flex h-9 w-9 items-center justify-center rounded-full bg-gray-200 text-sm font-medium dark:bg-gray-700">
                     {{ (user.first_name or "?")[:1] }}
                 </span>
                 {% endif %}
@@ -67,25 +72,55 @@
                     <div class="truncate text-xs text-gray-500">{% if user.username %}@{{ user.username }}{% else %}id {{ user.user_id }}{% endif %}</div>
                 </div>
             </div>
-            <a href="/logout" class="mt-3 block text-center rounded-lg border border-gray-200 dark:border-gray-700 px-3 py-1.5 text-sm hover:bg-gray-100 dark:hover:bg-gray-800">Выйти</a>
+            <a href="/logout" class="mt-3 block rounded-lg border border-gray-200 px-3 py-1.5 text-center text-sm hover:bg-gray-100 dark:border-gray-700 dark:hover:bg-gray-800">Выйти</a>
+            <div class="mt-2 text-center text-[11px] text-gray-400">Amadeus v{{ version }}</div>
         </div>
     </aside>
 
-    <div class="flex-1 flex flex-col min-w-0">
-        <header class="h-16 flex items-center justify-between gap-4 px-6 border-b border-gray-200 dark:border-gray-800 bg-white/70 dark:bg-gray-900/70 backdrop-blur">
-            <h1 class="text-lg font-semibold truncate">{% block header %}{% endblock %}</h1>
+    <div class="flex min-w-0 flex-1 flex-col">
+        <header class="sticky top-0 z-20 flex h-14 items-center justify-between gap-3 border-b border-gray-200 bg-white/80 px-4 backdrop-blur dark:border-gray-800 dark:bg-gray-900/80 md:h-16 md:px-6">
+            <div class="flex min-w-0 items-center gap-3">
+                <span class="relative inline-flex h-8 w-8 items-center justify-center overflow-hidden rounded-lg bg-brand-600 font-bold text-white md:hidden">
+                    A
+                    <img src="/avatar/bot" alt="" class="absolute inset-0 h-full w-full object-cover" onerror="this.remove()">
+                </span>
+                <h1 class="truncate text-base font-semibold md:text-lg">{% block header %}{% endblock %}</h1>
+            </div>
             <div class="flex items-center gap-2">
-                <button id="theme-toggle" class="rounded-lg border border-gray-200 dark:border-gray-700 px-3 py-1.5 text-sm hover:bg-gray-100 dark:hover:bg-gray-800">Тема</button>
-                <a href="/logout" class="md:hidden rounded-lg border border-gray-200 dark:border-gray-700 px-3 py-1.5 text-sm">Выйти</a>
+                <button id="theme-toggle" class="rounded-lg border border-gray-200 px-3 py-1.5 text-sm hover:bg-gray-100 dark:border-gray-700 dark:hover:bg-gray-800">Тема</button>
+                <a href="/logout" class="rounded-lg border border-gray-200 px-3 py-1.5 text-sm hover:bg-gray-100 dark:border-gray-700 dark:hover:bg-gray-800 md:hidden">Выйти</a>
             </div>
         </header>
-        <main class="p-6 space-y-6">
+        <main class="space-y-6 p-4 pb-24 md:p-6 md:pb-6">
             {% block content %}{% endblock %}
         </main>
     </div>
 </div>
 
+<!-- Нижняя навигация: только на мобильных, со значками -->
+<nav class="fixed inset-x-0 bottom-0 z-30 grid grid-cols-5 border-t border-gray-200 bg-white/95 pb-[env(safe-area-inset-bottom)] backdrop-blur dark:border-gray-800 dark:bg-gray-900/95 md:hidden">
+    {% set nav = [
+        ("dash", "/", "Главная", "M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125A1.125 1.125 0 005.625 21H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125a1.125 1.125 0 001.125-1.125V9.75"),
+        ("chats", "/chats", "Чаты", "M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 01-.825-.242m9.345-8.334a2.126 2.126 0 00-.476-.095 48.64 48.64 0 00-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0011.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155"),
+        ("users", "/users", "Люди", "M15 19.128a9.38 9.38 0 002.625.372 9.337 9.337 0 004.121-.952 4.125 4.125 0 00-7.533-2.493M15 19.128v-.003c0-1.113-.285-2.16-.786-3.07M15 19.128v.106A12.318 12.318 0 018.624 21c-2.331 0-4.512-.645-6.374-1.766l-.001-.109a6.375 6.375 0 0111.964-3.07M12 6.375a3.375 3.375 0 11-6.75 0 3.375 3.375 0 016.75 0zm8.25 2.25a2.625 2.625 0 11-5.25 0 2.625 2.625 0 015.25 0z"),
+        ("captcha", "/captcha", "Капчи", "M9 12.75L11.25 15 15 9.75M21 12c0 1.268-.63 2.39-1.593 3.068a3.745 3.745 0 01-1.043 3.296 3.745 3.745 0 01-3.296 1.043A3.745 3.745 0 0112 21c-1.268 0-2.39-.63-3.068-1.593a3.746 3.746 0 01-3.296-1.043 3.745 3.745 0 01-1.043-3.296A3.745 3.745 0 013 12c0-1.268.63-2.39 1.593-3.068a3.745 3.745 0 011.043-3.296 3.746 3.746 0 013.296-1.043A3.746 3.746 0 0112 3c1.268 0 2.39.63 3.068 1.593a3.746 3.746 0 013.296 1.043 3.746 3.746 0 011.043 3.296A3.745 3.745 0 0121 12z"),
+        ("log", "/log", "Журнал", "M8.25 6.75h7.5M8.25 12h7.5m-7.5 5.25h4.5M3.75 6.75h.008v.008H3.75V6.75zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0zM3.75 12h.008v.008H3.75V12zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0zm-.375 5.25h.008v.008H3.75v-.008zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z")
+    ] %}
+    {% for key, href, label, icon in nav %}
+    <a href="{{ href }}" class="flex flex-col items-center justify-center gap-0.5 py-2 text-[10px]
+        {% if active == key %}text-brand-600 dark:text-brand-400{% else %}text-gray-500 dark:text-gray-400{% endif %}">
+        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.8">
+            <path stroke-linecap="round" stroke-linejoin="round" d="{{ icon }}"/>
+        </svg>
+        <span class="{% if active == key %}font-medium{% endif %}">{{ label }}</span>
+    </a>
+    {% endfor %}
+</nav>
+
 <script>
+    // Авторизация создаётся сервером до отображения панели по подписанным initData.
+    if (window.Telegram && window.Telegram.WebApp) window.Telegram.WebApp.ready();
+
     // Переключатель тёмной/светлой темы.
     document.getElementById("theme-toggle").addEventListener("click", function () {
         const root = document.documentElement;

--
Gitblit v1.9.3