units,lesson as standalone

This commit is contained in:
2026-07-10 11:45:02 +08:00
parent 182bd93d10
commit 01a2c63b06
60 changed files with 3217 additions and 606 deletions
+16
View File
@@ -19,6 +19,8 @@ export function ClientLibraryProvider({ children }) {
// ── List state
const [units, setUnits] = useState([]);
const [unitsLoading, setUnitsLoading] = useState(false);
const [lessons, setLessons] = useState([]);
const [lessonsLoading, setLessonsLoading] = useState(false);
// ── Detail state — GET /client/units/:uuid/lessons returns unit + lessons + quiz in one call
const [unitDetail, setUnitDetail] = useState(null);
@@ -48,6 +50,18 @@ export function ClientLibraryProvider({ children }) {
}
}, []);
const getLessons = useCallback(async () => {
setLessonsLoading(true);
try {
const { data } = await api.get("/client/lessons");
setLessons(data.data ?? []);
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load lessons.");
} finally {
setLessonsLoading(false);
}
}, []);
const getUnitDetail = useCallback(async (uuid) => {
setUnitDetailLoading(true);
setUnitBlocked(false);
@@ -155,11 +169,13 @@ export function ClientLibraryProvider({ children }) {
const value = {
units, unitsLoading,
lessons, lessonsLoading,
unitDetail, unitDetailLoading, unitBlocked, unitBlockedInfo,
lesson, lessonLoading,
quiz, quizLoading,
getUnits,
getLessons,
getUnitDetail,
getLesson,
getUnitQuiz,