f1tness_parser/frontend/js/parse.js

23 lines
993 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { alert, api } from './common.js';
import { trainingsView } from './trainings-view.js';
const form = document.getElementById('parse-form');
const result = document.getElementById('result');
form.addEventListener('submit', async (event) => {
event.preventDefault();
result.replaceChildren(alert('info', 'Разбираю…'));
try {
const trainings = await api('/parser/parse/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
data: document.getElementById('training-data').value,
format: document.getElementById('format').value,
}),
});
result.replaceChildren(trainings.length ? trainingsView(trainings) : alert('warning', 'Тренировки не найдены'));
} catch (error) {
result.replaceChildren(alert('danger', `Не удалось разобрать заметку: ${error.message}`));
}
});