refactor(course-outline): replace thunks with react query, add typed APIs, and improve type usages (#2900)

* Replaces configure xblock and section highlights redux functions with react-query.
* Replaces section highlights thunks with react query
* Replaces duplicate block thunks
* Removes add subsection, unit redux functions
* Replaces scrollTo redux state to react-query based state.
* Replaces paste unit block redux functions
* Removes a lot of redux related functions as a result.
* Reduces API calls without compromising data integrity.
This commit is contained in:
Navin Karkera
2026-02-27 19:53:46 +05:30
committed by GitHub
parent 815b80a944
commit 060f7d4618
34 changed files with 705 additions and 802 deletions

View File

@@ -130,3 +130,38 @@ export const useCourseDetails = (courseId: string) => {
status,
};
};
/**
* Create a global state function for a query.
*/
export function createGlobalState<T>(
queryKeyFn: (queryKeyArgs?: any) => unknown[],
initialData: T | null = null,
) {
return (queryKeyArgs?: any) => {
const queryClient = useQueryClient();
const queryKey = queryKeyFn(queryKeyArgs);
const { data } = useQuery({
queryKey,
queryFn: () => Promise.resolve(initialData),
refetchInterval: false,
refetchOnMount: false,
refetchOnWindowFocus: false,
refetchOnReconnect: false,
refetchIntervalInBackground: false,
});
function setData(x: Partial<T>) {
queryClient.setQueryData(queryKey, x);
}
async function resetData() {
await queryClient.invalidateQueries({
queryKey,
});
}
return { data, setData, resetData };
};
}