debug(tracker): временные console.log для диагностики молчащего sync
Пользователь видит '1 из N' (от моих тестовых POST через API) но клики в браузере не увеличивают счётчик. Добавлены логи: - на boot: slug, есть ли LS, есть ли токен - на клик по пилюле: ключ - на каждый POST: тело + HTTP-статус ответа - на ошибку: response.text или fetch-exception Цель — собрать сигнал из DevTools-консоли пользователя. Уберём после диагностики (одобрено как временное).
This commit is contained in:
@@ -31,26 +31,32 @@
|
|||||||
let syncPending = false;
|
let syncPending = false;
|
||||||
let pendingExtra = null;
|
let pendingExtra = null;
|
||||||
function syncToServer(extra) {
|
function syncToServer(extra) {
|
||||||
if (typeof LS === 'undefined' || !LS.getToken || !LS.getToken()) return;
|
if (typeof LS === 'undefined' || !LS.getToken) { console.warn('[tracker] LS не загружен — пропускаем sync'); return; }
|
||||||
|
if (!LS.getToken()) { console.warn('[tracker] нет токена в localStorage — пользователь не залогинен'); return; }
|
||||||
if (syncPending) {
|
if (syncPending) {
|
||||||
pendingExtra = Object.assign(pendingExtra || {}, extra || {});
|
pendingExtra = Object.assign(pendingExtra || {}, extra || {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
syncPending = true;
|
syncPending = true;
|
||||||
|
const body = JSON.stringify({ last_para: localState.last, ...(extra || {}) });
|
||||||
|
console.log('[tracker]', slug, '→ POST', body);
|
||||||
fetch('/api/textbooks/' + slug + '/progress', {
|
fetch('/api/textbooks/' + slug + '/progress', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer ' + LS.getToken(),
|
'Authorization': 'Bearer ' + LS.getToken(),
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ last_para: localState.last, ...(extra || {}) }),
|
body,
|
||||||
|
}).then(r => {
|
||||||
|
console.log('[tracker]', slug, '← HTTP', r.status);
|
||||||
|
if (!r.ok) r.text().then(t => console.warn('[tracker] ошибка:', t));
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
syncPending = false;
|
syncPending = false;
|
||||||
if (pendingExtra) {
|
if (pendingExtra) {
|
||||||
const next = pendingExtra; pendingExtra = null;
|
const next = pendingExtra; pendingExtra = null;
|
||||||
syncToServer(next);
|
syncToServer(next);
|
||||||
}
|
}
|
||||||
}).catch(() => {});
|
}).catch(e => console.warn('[tracker] fetch упал:', e));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── 2. Initial load: merge server data into local state + push back ──
|
/* ── 2. Initial load: merge server data into local state + push back ──
|
||||||
@@ -224,6 +230,7 @@
|
|||||||
const pill = e.target.closest('.para-pill[data-para]');
|
const pill = e.target.closest('.para-pill[data-para]');
|
||||||
if (!pill) return;
|
if (!pill) return;
|
||||||
const key = pill.dataset.para;
|
const key = pill.dataset.para;
|
||||||
|
console.log('[tracker] клик по пилюле', key);
|
||||||
localState.last = key;
|
localState.last = key;
|
||||||
if (!localState.read.includes(key)) {
|
if (!localState.read.includes(key)) {
|
||||||
localState.read.push(key);
|
localState.read.push(key);
|
||||||
@@ -456,6 +463,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function boot() {
|
function boot() {
|
||||||
|
console.log('[tracker] boot, slug =', slug, '| LS:', typeof LS !== 'undefined', '| token:', typeof LS !== 'undefined' && LS.getToken && !!LS.getToken());
|
||||||
injectStyles();
|
injectStyles();
|
||||||
installBackButton();
|
installBackButton();
|
||||||
installBookmarksBtn();
|
installBookmarksBtn();
|
||||||
|
|||||||
Reference in New Issue
Block a user