Fiz da seguinte maneira:
import ui from "./ui.js";
import api from "./api.js";
document.addEventListener("DOMContentLoaded", () => {
ui.exibirPensamentosNaTela();
const formularioPensamento = document.getElementById("pensamento-form");
formularioPensamento.addEventListener("submit", manipularSubmissaoFormulario);
const botaoCancelar = document.getElementById("botao-cancelar");
botaoCancelar.addEventListener("click", () => {
document.getElementById("pensamento-conteudo").value = "";
document.getElementById("pensamento-autoria").value = "";
});
})
async function manipularSubmissaoFormulario(event) {
event.preventDefault();
const id = document.getElementById("pensamento-id").value;
const conteudo = document.getElementById("pensamento-conteudo").value;
const autoria = document.getElementById("pensamento-autoria").value;
try {
await api.salvarPensamento({conteudo, autoria});
ui.exibirPensamentosNaTela();
} catch (error) {
alert("Erro ao salvar pensamento");
}
}