Refactor plugin

This commit is contained in:
Andrea Fazzi 2022-06-29 18:45:26 +02:00
parent cb56e4c56f
commit d5d6fd2e08

View file

@ -57,23 +57,18 @@ const main = () => {
logseq.provideModel({ logseq.provideModel({
async createOrUpdateQuiz() { async createOrUpdateQuiz() {
const parentBlock = await logseq.Editor.getBlock(payload.uuid, { includeChildren: true }); const parentBlock = await logseq.Editor.getBlock(payload.uuid, { includeChildren: true });
const answers = child.children.map((answer: BlockEntity, i: number) => { const answers = parentBlock.children.map((answer: BlockEntity, i: number) => {
return { text: answer.content, correct: (i == 0) ? true : false } return { text: answer.content, correct: (i == 0) ? true : false }
}) })
const quiz = { const quiz = {
question: {text: parentBlock.children[0].content }, question: {text: parentBlock.content },
answers: answers answers: answers
} }
const question = { text: child.content }
return { question: question, answers: answers, uuid: child.uuid } const res = await fetch(endpoint+'/create', { method: 'POST', body: JSON.stringify(quiz) })
}); const data = await res.json();
quizzes.forEach(async (quiz, i) => { await logseq.Editor.upsertBlockProperty(parentBlock.uuid, `probo-quiz-uuid`, data.content.ID)
const res = await fetch(endpoint+'/create', { method: 'POST', body: JSON.stringify(quiz) })
const data = await res.json();
const block = await logseq.Editor.getBlock(quiz.uuid)
await logseq.Editor.upsertBlockProperty(parentBlock.uuid, `probo-quiz-uuid`, data.content.ID)
})
} }
}); });