Feat: microlearning implementation

This commit is contained in:
RaymondVerhoef
2026-05-25 18:32:45 +02:00
parent 18e98380d9
commit 042dfb2d92
4 changed files with 386 additions and 59 deletions

View File

@@ -1,17 +1,20 @@
import { pb } from '../lib/pb';
import { getOrGenerateMicroLearning, regenerateMicroLearning } from '../lib/microLearningService';
export function useMicroLearnings() {
const getMicroLearningsByTopic = async (topicId) => {
try {
const records = await pb.collection('micro_learnings').getFullList({
filter: `topic_id = "${topicId}" && status = 'published'`,
});
return records;
} catch (err) {
console.error("Error fetching micro learnings:", err);
return [];
}
/**
* Get or generate a micro learning for the given topic and type.
* Returns a PocketBase record with .content ready to render.
*/
const getOrGenerate = async (topicId, type) => {
return getOrGenerateMicroLearning(topicId, type);
};
return { getMicroLearningsByTopic };
/**
* Force regeneration of a micro learning (deletes cached version first).
*/
const regenerate = async (topicId, type) => {
return regenerateMicroLearning(topicId, type);
};
return { getOrGenerate, regenerate };
}