saving token
This commit is contained in:
+14
@@ -10,6 +10,7 @@ import type { WordItem } from './training.ts';
|
|||||||
|
|
||||||
// ----- Конфигурация -----
|
// ----- Конфигурация -----
|
||||||
const API_BASE_URL = 'https://learning.micialware.ru';
|
const API_BASE_URL = 'https://learning.micialware.ru';
|
||||||
|
const SYNC_ID_STORAGE_KEY = 'japlearn_sync_id';
|
||||||
|
|
||||||
// ----- Элементы UI -----
|
// ----- Элементы UI -----
|
||||||
const container = document.getElementById('page-container') as HTMLElement;
|
const container = document.getElementById('page-container') as HTMLElement;
|
||||||
@@ -39,9 +40,19 @@ function getSyncId(): string {
|
|||||||
const input = document.getElementById('syncId') as HTMLInputElement | null;
|
const input = document.getElementById('syncId') as HTMLInputElement | null;
|
||||||
const id = input?.value.trim();
|
const id = input?.value.trim();
|
||||||
if (!id) throw new Error('Введите ID синхронизации');
|
if (!id) throw new Error('Введите ID синхронизации');
|
||||||
|
// Сохраняем в localStorage
|
||||||
|
localStorage.setItem(SYNC_ID_STORAGE_KEY, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function restoreSyncId(): void {
|
||||||
|
const saved = localStorage.getItem(SYNC_ID_STORAGE_KEY);
|
||||||
|
if (saved) {
|
||||||
|
const input = document.getElementById('syncId') as HTMLInputElement | null;
|
||||||
|
if (input) input.value = saved;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----- Рендеринг страниц -----
|
// ----- Рендеринг страниц -----
|
||||||
|
|
||||||
function renderWordsPage() {
|
function renderWordsPage() {
|
||||||
@@ -360,6 +371,9 @@ async function main() {
|
|||||||
// Стартовая страница
|
// Стартовая страница
|
||||||
switchPage('words');
|
switchPage('words');
|
||||||
|
|
||||||
|
// Восстанавливаем сохранённый ID синхронизации
|
||||||
|
restoreSyncId();
|
||||||
|
|
||||||
// Глобальные обработчики
|
// Глобальные обработчики
|
||||||
container.addEventListener('click', async (e) => {
|
container.addEventListener('click', async (e) => {
|
||||||
const target = e.target as HTMLElement;
|
const target = e.target as HTMLElement;
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ import { VitePWA } from 'vite-plugin-pwa';
|
|||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
// basicSsl(),
|
basicSsl(),
|
||||||
VitePWA({
|
VitePWA({
|
||||||
registerType: 'autoUpdate',
|
registerType: 'autoUpdate',
|
||||||
includeAssets: ['favicon.svg', 'icon-192.png', 'icon-512.png'],
|
includeAssets: ['favicon.svg', 'icon-192.png', 'icon-512.png'],
|
||||||
|
|||||||
Reference in New Issue
Block a user