Refactor plugin
This commit is contained in:
parent
cb56e4c56f
commit
d5d6fd2e08
1 changed files with 8 additions and 13 deletions
|
@ -57,23 +57,18 @@ const main = () => {
|
|||
logseq.provideModel({
|
||||
async createOrUpdateQuiz() {
|
||||
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 }
|
||||
})
|
||||
|
||||
const quiz = {
|
||||
question: {text: parentBlock.children[0].content },
|
||||
question: {text: parentBlock.content },
|
||||
answers: answers
|
||||
}
|
||||
const question = { text: child.content }
|
||||
return { question: question, answers: answers, uuid: child.uuid }
|
||||
});
|
||||
quizzes.forEach(async (quiz, i) => {
|
||||
|
||||
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)
|
||||
})
|
||||
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue