import React, { useEffect, useState } from 'react'; import ListViewSelector from '../Assets/ListViewSelector'; import GridSelector from '../Assets/GridSelector'; import { LoadedComponentProps } from './Types/types'; import { useUserContentItemsQuery, LoadingDots, hydrateContent, HydratedContentItem } from '@thoughtindustries/content'; import { useTranslation } from 'react-i18next'; import LearnerAccessGridView from './Views/GridView'; import LearnerAccessDisplayListView from './Views/DisplayListView'; import clsx from 'clsx'; const LoadUserLearning = ({ query, kind, sortColumn, sortDirection }: LoadedComponentProps): JSX.Element => { const [gridViewActive, setGridActive] = useState(true); const handleResize = () => { if (typeof window !== 'undefined' && window.innerWidth < 640) { setGridActive(true); } }; useEffect(() => { // Only run on client side after hydration if (typeof window !== 'undefined') { // Don't set initial state here to avoid hydration mismatch window.addEventListener('resize', handleResize); // Only update state after a small delay to ensure hydration is complete const timer = setTimeout(() => { handleResize(); }, 0); return () => { clearTimeout(timer); window.removeEventListener('resize', handleResize); }; } }, []); const { data, loading, error } = useUserContentItemsQuery({ variables: { query, kind, sortColumn, sortDirection }, fetchPolicy: 'network-only' }); const { i18n } = useTranslation(); interface ContentUiProps { item: HydratedContentItem; index?: number; } const DisplayListView = ({ item }: ContentUiProps) => { return ( // list flex container ); }; const DisplayGridView = ({ item }: ContentUiProps) => { return ( // {/* course card */} ); }; if (loading) return ; if (error) return <>{error.message}; if (!data || !data.UserContentItems) return <>; return ( <> {/* grid/list toggle */}
{/* list display button */} {/* grid display button */}
{/* title and progress */} {!gridViewActive && (
Title
Progress
)} {data.UserContentItems.map(item => { const hydratedItem = hydrateContent(i18n, item); if (hydratedItem.isCompleted) { return null; } return ( <> {gridViewActive ? ( ) : (
)} ); })}
); }; export default LoadUserLearning;