Feat: microlearning implementation
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user