fix(modal): блокировка прокрутки фона, фокус и адаптивный шаг весов
Модальные окна фиксируют прокрутку страницы, числовые поля получают фокус и адаптивный шаг веса, кардио и строки подходов получают сортировку и время подхода.
This commit is contained in:
@@ -22,7 +22,7 @@ export function addSet(workoutId, exerciseId) {
|
||||
w.id
|
||||
);
|
||||
|
||||
showSetDialog(lastSet, history, (setData) => {
|
||||
showSetDialog(null, history, (setData) => {
|
||||
if (!setData) return;
|
||||
|
||||
setData.id = genId();
|
||||
@@ -32,6 +32,9 @@ export function addSet(workoutId, exerciseId) {
|
||||
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
}, {
|
||||
prefill: lastSet,
|
||||
historyLabel: ex.name,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -62,7 +65,7 @@ export function editSet(workoutId, exerciseId, setId) {
|
||||
|
||||
saveState();
|
||||
renderMainScreen();
|
||||
});
|
||||
}, { historyLabel: ex.name });
|
||||
}
|
||||
|
||||
export function deleteSet(workoutId, exerciseId, setId) {
|
||||
|
||||
@@ -1,19 +1,30 @@
|
||||
import { showModal, closeModal, stepperHtml } from './modal-base.js';
|
||||
import { state } from '../state.js';
|
||||
|
||||
let _cb = null;
|
||||
|
||||
export function showCardioDialog(existing, callback) {
|
||||
_cb = callback;
|
||||
const e = existing || {};
|
||||
const types = [
|
||||
['вело', '🚴 Вело'],
|
||||
['ходьба', '🚶 Ходьба'],
|
||||
['бег', '🏃 Бег'],
|
||||
['эллипс', '⚡ Эллипс'],
|
||||
['гребля', '🚣 Гребля'],
|
||||
];
|
||||
// Популярные типы — выше: считаем, сколько раз каждый уже использовался
|
||||
const counts = {};
|
||||
state.workouts.forEach(w => (w.cardio || []).forEach(c => {
|
||||
counts[c.type] = (counts[c.type] || 0) + 1;
|
||||
}));
|
||||
const orderedTypes = [...types].sort((a, b) => (counts[b[0]] || 0) - (counts[a[0]] || 0));
|
||||
|
||||
showModal(`<div class="modal-content">
|
||||
<h3 class="modal-title">${existing ? 'Редактировать' : 'Новое'} кардио</h3>
|
||||
<div class="field-row">
|
||||
<div class="field-group"><label>Тип</label><select id="m-ct">
|
||||
<option value="вело" ${e.type==='вело'?'selected':''}>🚴 Вело</option>
|
||||
<option value="ходьба" ${e.type==='ходьба'?'selected':''}>🚶 Ходьба</option>
|
||||
<option value="бег" ${e.type==='бег'?'selected':''}>🏃 Бег</option>
|
||||
<option value="эллипс" ${e.type==='эллипс'?'selected':''}>⚡ Эллипс</option>
|
||||
<option value="гребля" ${e.type==='гребля'?'selected':''}>🚣 Гребля</option>
|
||||
${orderedTypes.map(([v, label]) => `<option value="${v}" ${e.type === v ? 'selected' : ''}>${label}</option>`).join('')}
|
||||
</select></div>
|
||||
<div class="field-group"><label>Назначение</label><select id="m-cp">
|
||||
<option value="warmup" ${e.purpose==='warmup'?'selected':''}>🔥 Разминка</option>
|
||||
|
||||
@@ -2,32 +2,76 @@ const container = () => document.getElementById('modal-container');
|
||||
|
||||
export function showModal(html) {
|
||||
container().innerHTML = `<div class="modal-overlay" onclick="ModalBase.closeOnBg(event)">${html}</div>`;
|
||||
const content = container().querySelector('.modal-content');
|
||||
if (content) content.scrollTop = 0;
|
||||
// Под модалкой страница не скроллится — иначе клавиатура «уводит» вёрстку
|
||||
document.body.classList.add('modal-open');
|
||||
}
|
||||
|
||||
export function closeModal() {
|
||||
container().innerHTML = '';
|
||||
document.body.classList.remove('modal-open');
|
||||
}
|
||||
|
||||
export function closeOnBg(e) {
|
||||
if (e.target.classList.contains('modal-overlay')) closeModal();
|
||||
}
|
||||
|
||||
export function stepperHtml(id, value, step, placeholder, inputmode = 'decimal') {
|
||||
/**
|
||||
* Фокус в числовом поле: выделяем текущее значение целиком, чтобы ввод с
|
||||
* клавиатуры сразу перезаписывал цифру; и подстраховываем скролл — мобильная
|
||||
* клавиатура часто перекрывает поле, а страница под модалкой не крутится.
|
||||
*/
|
||||
export function focusInput(el) {
|
||||
requestAnimationFrame(() => {
|
||||
try { el.select(); } catch (e) { /* не для всех типов select недоступен */ }
|
||||
});
|
||||
setTimeout(() => {
|
||||
el.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
||||
}, 350);
|
||||
}
|
||||
|
||||
/**
|
||||
* Адаптивный шаг веса: лёгкие веса шагами мельче, тяжёлые — крупнее.
|
||||
*/
|
||||
export function weightStep(current) {
|
||||
const v = Math.abs(parseFloat(current) || 0);
|
||||
if (v < 12) return 1;
|
||||
if (v < 40) return 2.5;
|
||||
return 5;
|
||||
}
|
||||
|
||||
// inputmode='decimal'/'numeric' не даёт стрелкам и колесу мыши менять значение —
|
||||
// пересчитываем шаг по факту ввода, чтобы «+/-» продолжали идти по адаптивной сетке
|
||||
export function onStepperChange(id) {
|
||||
const input = document.getElementById(id);
|
||||
if (input && input.dataset.adaptive === 'weight') {
|
||||
input.step = weightStep(input.value);
|
||||
}
|
||||
}
|
||||
|
||||
export function stepperHtml(id, value, step, placeholder, inputmode = 'decimal', adaptive = false) {
|
||||
const v = value !== '' && value != null ? value : '';
|
||||
const stepVal = adaptive ? weightStep(v) : step;
|
||||
const adaptiveAttr = adaptive ? ` data-adaptive="weight" onchange="ModalBase.onStepperChange('${id}')"` : '';
|
||||
return `<div class="stepper-field">
|
||||
<button type="button" class="stepper-btn" onclick="ModalBase.stepValue('${id}', -${step})">−</button>
|
||||
<input type="number" id="${id}" step="${step}" value="${v}" placeholder="${placeholder}" inputmode="${inputmode}">
|
||||
<button type="button" class="stepper-btn" onclick="ModalBase.stepValue('${id}', ${step})">+</button>
|
||||
<button type="button" class="stepper-btn" onclick="ModalBase.stepValue('${id}', -${stepVal}, ${adaptive})">−</button>
|
||||
<input type="number" id="${id}" step="${stepVal}" value="${v}" placeholder="${placeholder}" inputmode="${inputmode}"
|
||||
onfocus="ModalBase.focusInput(this)"${adaptiveAttr}>
|
||||
<button type="button" class="stepper-btn" onclick="ModalBase.stepValue('${id}', ${stepVal}, ${adaptive})">+</button>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
export function stepValue(id, delta) {
|
||||
export function stepValue(id, delta, adaptive = false) {
|
||||
const input = document.getElementById(id);
|
||||
if (!input) return;
|
||||
const current = parseFloat(input.value) || 0;
|
||||
const step = parseFloat(input.step) || 1;
|
||||
const newVal = Math.max(0, current + delta);
|
||||
const deltaAbs = Math.abs(delta);
|
||||
// Для адаптивных полей шаг берём по текущему значению, а не по step из кнопки
|
||||
const step = adaptive ? weightStep(current) : (parseFloat(input.step) || deltaAbs || 1);
|
||||
const newVal = Math.max(0, current + (delta > 0 ? step : -step));
|
||||
input.value = parseFloat((Math.round(newVal / step) * step).toFixed(4));
|
||||
input.dispatchEvent(new Event('change'));
|
||||
}
|
||||
|
||||
window.ModalBase = {
|
||||
@@ -35,5 +79,8 @@ window.ModalBase = {
|
||||
closeModal,
|
||||
close: closeModal,
|
||||
closeOnBg,
|
||||
focusInput,
|
||||
onStepperChange,
|
||||
weightStep,
|
||||
stepValue
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/* === Modal === */
|
||||
body.modal-open { overflow: hidden; }
|
||||
.modal-overlay {
|
||||
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
||||
background: rgba(0,0,0,0.85); z-index: 100; display: flex;
|
||||
@@ -23,3 +24,12 @@
|
||||
.autocomplete-item:last-child { border-bottom: none; }
|
||||
.autocomplete-item:active { background: var(--surface); }
|
||||
.autocomplete-item .freq { float: right; font-size: 0.75rem; color: var(--text-secondary); }
|
||||
|
||||
/* === Чекбоксы состава сета === */
|
||||
.group-check-list { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow-y: auto; }
|
||||
.group-check {
|
||||
display: flex; align-items: center; gap: 8px; padding: 10px 12px;
|
||||
background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
|
||||
font-size: 0.95rem; cursor: pointer;
|
||||
}
|
||||
.group-check input { width: auto; }
|
||||
|
||||
@@ -27,13 +27,14 @@
|
||||
/* === Sets === */
|
||||
.sets-table { margin-bottom: 12px; }
|
||||
.set-row {
|
||||
display: grid; grid-template-columns: 30px 1fr 1fr auto auto; gap: 6px;
|
||||
display: grid; grid-template-columns: 30px 1fr 1fr auto auto auto; gap: 6px;
|
||||
align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.95rem;
|
||||
}
|
||||
.set-row:last-child { border-bottom: none; }
|
||||
.set-number { color: var(--text-secondary); font-size: 0.8rem; text-align: center; }
|
||||
.set-cell { text-align: center; font-weight: 600; }
|
||||
.set-cell.dropset { color: var(--warning); font-size: 0.85rem; }
|
||||
.set-time { color: var(--text-secondary); font-size: 0.72rem; white-space: nowrap; }
|
||||
.set-rating { color: var(--warning); font-size: 0.85rem; }
|
||||
.set-actions { display: flex; gap: 4px; }
|
||||
|
||||
@@ -55,6 +56,51 @@
|
||||
.history-hint-date { color: var(--text-secondary); font-size: 0.75rem; }
|
||||
.history-hint-sets { color: var(--text); font-weight: 500; }
|
||||
|
||||
/* === История подходов: номер подхода, вес, вариант === */
|
||||
.history-hint-sets { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px 12px; }
|
||||
.history-hint-set { white-space: nowrap; }
|
||||
.history-hint-name {
|
||||
width: 100%;
|
||||
text-align: right;
|
||||
color: var(--primary);
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
|
||||
/* === Сет (суперсет): подходы участников по раундам === */
|
||||
.circuit-card {
|
||||
background-color: var(--surface); border-radius: var(--radius); margin-bottom: 10px;
|
||||
border: 1px solid var(--primary); overflow: hidden;
|
||||
}
|
||||
.circuit-header {
|
||||
padding: 12px 14px; display: flex; justify-content: space-between; align-items: center;
|
||||
flex-wrap: wrap; gap: 8px; border-bottom: 1px solid var(--border);
|
||||
background: rgba(187, 134, 252, 0.07);
|
||||
}
|
||||
.circuit-name { font-weight: 700; color: var(--primary); }
|
||||
.circuit-members { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
|
||||
.circuit-controls { display: flex; gap: 6px; }
|
||||
.circuit-rounds { padding: 8px 12px; }
|
||||
.circuit-round {
|
||||
display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
|
||||
padding: 6px 0; border-bottom: 1px dotted var(--border);
|
||||
}
|
||||
.circuit-round:last-child { border-bottom: none; }
|
||||
.round-num {
|
||||
min-width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: #000;
|
||||
font-size: 0.75rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
|
||||
}
|
||||
.circuit-chip {
|
||||
background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
|
||||
padding: 4px 8px; font-size: 0.82rem; cursor: pointer;
|
||||
}
|
||||
.circuit-chip b { color: var(--primary); font-weight: 600; }
|
||||
.circuit-chip .circuit-val { margin: 0 4px; }
|
||||
.circuit-chip .circuit-stars { color: var(--warning); font-size: 0.75rem; }
|
||||
.circuit-chip.empty { opacity: 0.45; cursor: default; }
|
||||
.circuit-add { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); }
|
||||
.circuit-unlink-foot { margin-left: auto; color: var(--danger); border-color: var(--danger); }
|
||||
.dropset-row { grid-template-columns: 30px 1fr auto auto auto; }
|
||||
|
||||
/* === Finish block === */
|
||||
.finish-block { margin-top: 30px; padding: 16px; background: linear-gradient(to bottom, transparent, rgba(207, 102, 121, 0.1)); border-top: 2px solid var(--danger); }
|
||||
.finish-block h3 { color: var(--danger); margin-bottom: 10px; }
|
||||
|
||||
Reference in New Issue
Block a user