mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
units,lesson as standalone
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user