Disable logging

This commit is contained in:
Andrea Fazzi 2022-09-06 14:41:32 +02:00
parent d5d6fd2e08
commit 2e79c6595f
4 changed files with 58 additions and 38 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.log

View file

@ -5,7 +5,6 @@ import (
"net/http"
"git.andreafazzi.eu/andrea/probo/hasher/sha256"
"git.andreafazzi.eu/andrea/probo/logger"
"git.andreafazzi.eu/andrea/probo/store/memory"
"github.com/sirupsen/logrus"
)
@ -13,7 +12,7 @@ import (
const port = "3000"
func main() {
logger.SetLevel(logger.DebugLevel)
// logger.SetLevel(logger.DebugLevel)
server := NewProboCollectorServer(
memory.NewMemoryProboCollectorStore(

View file

@ -8,6 +8,8 @@ const uniqueIdentifier = () =>
.toString(36)
.replace(/[^a-z]+/g, "");
const sanitizeBlockContent = (text: string) => text.replace(/((?<=::).*|.*::)/g, "").replace(/{.*}/, "").trim()
async function fetchQuizzes() {
const { status: status, content: quizzes } = await fetch(endpoint).then(res => res.json())
const ret = quizzes || []
@ -17,6 +19,19 @@ async function fetchQuizzes() {
})
}
const render = (id, slot, status: ("modified" | "saved" | "error")) => {
logseq.provideUI({
key: `${id}`,
slot,
reset: true,
template: `
${status === 'saved' ? '<button data-on-click="createOrUpdateQuiz" class="renderBtn">Save</button><span>saved</span>' : '<button data-on-click="createOrUpdateQuiz" class="renderBtn">Save</button>'}
`,
});
}
const main = () => {
console.log("logseq-probo-plugin LOADED!");
@ -37,23 +52,18 @@ const main = () => {
`{{renderer :probo_${uniqueIdentifier()}}}`
);
// const currBlock = await logseq.Editor.getCurrentBlock();
// await logseq.Editor.insertBlock(currBlock.uuid, 'Write your question here...',
// {
// sibling: false,
// before: false,
// }
// );
// await logseq.Editor.exitEditingMode();
});
logseq.App.onMacroRendererSlotted(async ({ slot, payload }) => {
const [type] = payload.arguments;
if (!type.startsWith(":probo")) return
const id = type.split("_")[1]?.trim();
const proboId = `probo_${id}`;
let status: ("modified" | "saved" | "error")
logseq.provideModel({
async createOrUpdateQuiz() {
const parentBlock = await logseq.Editor.getBlock(payload.uuid, { includeChildren: true });
@ -62,30 +72,40 @@ const main = () => {
})
const quiz = {
question: {text: parentBlock.content },
question: { text: sanitizeBlockContent(parentBlock.content) },
answers: answers
}
const res = await fetch(endpoint+'/create', { method: 'POST', body: JSON.stringify(quiz) })
if (parentBlock.properties.proboQuizUuid) {
const res = await fetch(endpoint + `/update/${parentBlock.properties.proboQuizUuid}`, { method: 'PUT', body: JSON.stringify(quiz) })
const data = await res.json();
await logseq.Editor.upsertBlockProperty(parentBlock.uuid, `probo-quiz-uuid`, data.content.ID)
render(proboId, slot, "saved")
} else {
const res = await fetch(endpoint + '/create', { method: 'POST', body: JSON.stringify(quiz) })
const data = await res.json();
await logseq.Editor.upsertBlockProperty(parentBlock.uuid, `probo-quiz-uuid`, data.content.ID)
render(proboId, slot, "saved")
}
}
});
logseq.provideStyle(`
.renderBtn {
border: 1px solid white;
border-radius: 8px;
padding: 5px;
font-size: 80%;
background-color: black;
color: white;
}
.renderBtn:hover {
background-color: white;
color: black;
}
.renderBtn {
border: 1px solid white;
border-radius: 8px;
padding: 5px;
margin-right: 5px;
font-size: 80%;
background-color: black;
color: white;
}
.renderBtn:hover {
background-color: white;
color: black;
}
`);
logseq.provideUI({

View file

@ -117,8 +117,8 @@ func (s *MemoryProboCollectorStore) createAnswerFromHash(hash string, answer *mo
func (s *MemoryProboCollectorStore) ReadAllQuizzes() ([]*models.Quiz, error) {
result := make([]*models.Quiz, 0)
for hash := range s.quizzesHashes {
result = append(result, s.getQuizFromHash(hash))
for id := range s.quizzes {
result = append(result, s.getQuizFromID(id))
}
return result, nil
}
@ -163,7 +163,7 @@ func (s *MemoryProboCollectorStore) createOrUpdateQuiz(r *client.CreateUpdateQui
})
}
if answer.Correct {
quiz.Correct = a // s.readAnswer(answerID)
quiz.Correct = a
}
quiz.Answers = append(quiz.Answers, a)
}