This commit is contained in:
louiscklaw
2025-04-21 12:15:25 +08:00
parent ac7d3883fd
commit 00a978e55a
67 changed files with 3423 additions and 136 deletions

View File

@@ -0,0 +1,46 @@
'use client';
import * as React from 'react';
// import type { LessonCategory } from '@/types/lesson-type';
import { useSelection } from '@/hooks/use-selection';
import type { Selection } from '@/hooks/use-selection';
import { LpQuestion } from './type';
function noop(): void {
return undefined;
}
export interface LpCategoriesSelectionContextValue extends Selection {}
export const LpCategoriesSelectionContext = React.createContext<LpCategoriesSelectionContextValue>({
deselectAll: noop,
deselectOne: noop,
selectAll: noop,
selectOne: noop,
selected: new Set(),
selectedAny: false,
selectedAll: false,
});
interface LpCategoriesSelectionProviderProps {
children: React.ReactNode;
lessonQuestions: LpQuestion[];
}
export function LpQuestionsSelectionProvider({
children,
lessonQuestions: lessonCategories = [],
}: LpCategoriesSelectionProviderProps): React.JSX.Element {
const customerIds = React.useMemo(() => lessonCategories.map((customer) => customer.id), [lessonCategories]);
const selection = useSelection(customerIds);
return (
<LpCategoriesSelectionContext.Provider value={{ ...selection }}>{children}</LpCategoriesSelectionContext.Provider>
);
}
export function useLpCategoriesSelection(): LpCategoriesSelectionContextValue {
return React.useContext(LpCategoriesSelectionContext);
}