11'use client' ;
22
33import { api } from '@/api/api' ;
4+ import { CDN_URL } from '@/constants/constants' ;
45import { authAtom } from '@/store/auth' ;
6+ import { classroomsAtom } from '@/store/classrooms' ;
57import type { IClassroom } from '@/types/IClassroomCard' ;
68import {
79 Avatar ,
@@ -18,39 +20,19 @@ import {
1820 useDisclosure
1921} from '@chakra-ui/react' ;
2022import { useAtom } from 'jotai' ;
21- import { useEffect , useState } from 'react' ;
2223import { FiPlus , FiUsers } from 'react-icons/fi' ;
2324import ClassroomCard from '../general/ClassroomCard' ;
2425import CreateClassModal from '../modals/CreateClassModal' ;
2526import EditAccountModal from '../modals/EditAccountModal' ;
26- import { CDN_URL } from '@/constants/constants' ;
2727
2828export default function ProfileScreen ( ) {
2929 const [ auth ] = useAtom ( authAtom ) ;
30+ const [ classrooms ] = useAtom ( classroomsAtom ) ;
3031 const { isOpen : isCreateOpen , onOpen : onCreateOpen , onClose : onCreateClose } = useDisclosure ( ) ;
3132 const { isOpen : isEditOpen , onOpen : onEditOpen , onClose : onEditClose } = useDisclosure ( ) ;
32- const [ classrooms , setClassrooms ] = useState < IClassroom [ ] > ( [ ] ) ;
33- const [ isLoading , setIsLoading ] = useState ( true ) ;
3433
3534 const { user } = auth ;
3635
37- useEffect ( ( ) => {
38- const fetchClassrooms = async ( ) => {
39- try {
40- const data = await api . classroom . getAll ( ) ;
41- setClassrooms ( data ) ;
42- } catch ( error ) {
43- console . error ( 'Failed to fetch classrooms:' , error ) ;
44- } finally {
45- setIsLoading ( false ) ;
46- }
47- } ;
48-
49- if ( user ) {
50- fetchClassrooms ( ) ;
51- }
52- } , [ user ] ) ;
53-
5436 if ( typeof location !== 'undefined' && ! user && ! auth . isLoading ) location . href = '/' ;
5537
5638 return user ? (
@@ -92,7 +74,7 @@ export default function ProfileScreen() {
9274 < Heading size = 'lg' mb = { 6 } >
9375 Clases Destacadas
9476 </ Heading >
95- { isLoading ? (
77+ { classrooms === null ? (
9678 < Flex h = '200px' align = 'center' justify = 'center' >
9779 < Spinner size = 'lg' />
9880 </ Flex >
@@ -126,7 +108,7 @@ export default function ProfileScreen() {
126108 </ VStack >
127109 </ Container >
128110
129- < CreateClassModal isOpen = { isCreateOpen } onClose = { onCreateClose } onClassroomCreated = { setClassrooms } />
111+ < CreateClassModal isOpen = { isCreateOpen } onClose = { onCreateClose } />
130112 < EditAccountModal isOpen = { isEditOpen } onClose = { onEditClose } />
131113 </ Box >
132114 ) : (
0 commit comments