Skip to content
This repository was archived by the owner on Jun 12, 2025. It is now read-only.
Merged

Dev #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const withBundleAnalyzer = nextBundleAnalyzer({

let configExport = nextConfig;

if (process.env.NODE_ENV === 'production') {
if (process.env['NODE_ENV'] === 'production') {
console.log('Loaded production config');
configExport = million.next(nextConfig, { auto: true });
}
Expand Down
12 changes: 11 additions & 1 deletion src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,20 @@ export const api = {
}
});

if (!res.ok) throw new Error('Failed to fetch classroom');
if (!res.ok) throw new Error('Failed to fetch classroom members');
return res.json();
},

getProfessor: async (id: string): Promise<IUser> => {
const res = await fetch(`${API_URL}/classrooms/${encodeURIComponent(id)}/professor`, {
headers: {
...getAuthHeaders()
}
});

if (!res.ok) throw new Error('Failed to fetch classroom professor');
return res.json();
},

create: async (data: {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/general/ClassroomCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function ClassroomCard({ item }: Readonly<{ item: IClassroom }>)
<Flex justify='space-between' align='center'>
<Flex align='center' gap={2}>
<FiUsers />
<Text fontSize='sm'>24 estudiantes</Text>
<Text fontSize='sm'>{item.memberCount} estudiantes</Text>
</Flex>
<Button
size='sm'
Expand Down
5 changes: 4 additions & 1 deletion src/components/modals/CreateActivityModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { api } from '@/api/api';
import { authAtom } from '@/store/auth';
import type { IActivity } from '@/types/IActivity';
import {
Button,
Expand All @@ -21,6 +22,7 @@ import {
VStack,
useToast
} from '@chakra-ui/react';
import { useAtom } from 'jotai';
import { useState } from 'react';
import { FiPlus, FiTrash } from 'react-icons/fi';

Expand All @@ -37,6 +39,7 @@ export default function CreateActivityModal({
classroomId,
onActivityCreated
}: Readonly<CreateActivityModalProps>) {
const [auth] = useAtom(authAtom);
const [isLoading, setIsLoading] = useState(false);
const [formData, setFormData] = useState({
title: '',
Expand Down Expand Up @@ -71,7 +74,7 @@ export default function CreateActivityModal({
id,
...formData,
classroomId,
owner: 'Ángel',
owner: auth.user?.id ?? '',
createdAt: new Date().toISOString()
};

Expand Down
7 changes: 6 additions & 1 deletion src/components/modals/CreateClassModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { api } from '@/api/api';
import { authAtom } from '@/store/auth';
import type { IClassroom } from '@/types/IClassroomCard';
import {
Button,
Expand All @@ -19,6 +20,7 @@ import {
VStack,
useToast
} from '@chakra-ui/react';
import { useAtom } from 'jotai';
import { useEffect, useState } from 'react';

interface CreateClassModalProps {
Expand All @@ -34,6 +36,8 @@ export default function CreateClassModal({ isOpen, onClose, onClassroomCreated }
description: '',
thumbnailId: 1
});
const [auth] = useAtom(authAtom);

const toast = useToast();

useEffect(() => {
Expand Down Expand Up @@ -67,7 +71,8 @@ export default function CreateClassModal({ isOpen, onClose, onClassroomCreated }
id,
...formData,
code: id.slice(0, 6).toUpperCase(),
owner: 'Ángel'
owner: auth.user?.id ?? '',
memberCount: 1
};

onClassroomCreated?.([newClassroom]);
Expand Down
20 changes: 9 additions & 11 deletions src/components/screens/ClassScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { api } from '@/api/api';
import { CDN_URL } from '@/constants/constants';
import type { IActivity } from '@/types/IActivity';
import type { IClassroom } from '@/types/IClassroomCard';
import type { IUser } from '@/types/IUser';
import {
Avatar,
Box,
Expand Down Expand Up @@ -31,28 +32,30 @@ import { useEffect, useState } from 'react';
import { FiCode, FiFileText, FiPlus, FiUsers } from 'react-icons/fi';
import ActivityCard from '../general/ActivityCard';
import CreateActivityModal from '../modals/CreateActivityModal';
import type { IUser } from '@/types/IUser';

export default function ClassScreen({ id }: Readonly<{ id: string }>) {
const [classroom, setClassroom] = useState<IClassroom | null>(null);
const [isLoading, setIsLoading] = useState(true);
const router = useRouter();
const [classActivities, setClassActivities] = useState<IActivity[]>([]);
const [classMembers, setClassMembers] = useState<IUser[]>([]);
const [professor, setProfessor] = useState<IUser | null>(null);
const [isMembersLoading, setIsMembersLoading] = useState(false);
const { isOpen, onOpen, onClose } = useDisclosure();
const toast = useToast();

useEffect(() => {
const fetchData = async () => {
try {
const [classroomData, activitiesData] = await Promise.all([
const [classroomData, activitiesData, professorData] = await Promise.all([
api.classroom.getById(id),
api.activities.getByClassroom(id)
api.activities.getByClassroom(id),
api.classroom.getProfessor(id)
]);

setClassroom(classroomData);
setClassActivities(activitiesData);
setProfessor(professorData);
} catch (error) {
toast({
title: 'Error',
Expand All @@ -76,7 +79,6 @@ export default function ClassScreen({ id }: Readonly<{ id: string }>) {
};

const handleTabChange = async (index: number) => {
// Index 1 is the "Estudiantes" tab
if (index === 1 && classMembers.length === 0) {
setIsMembersLoading(true);
try {
Expand Down Expand Up @@ -150,7 +152,7 @@ export default function ClassScreen({ id }: Readonly<{ id: string }>) {
<Flex gap={6} color='gray.400'>
<Flex align='center' gap={2}>
<Icon as={FiUsers} />
<Text>{classMembers.length || '...'} estudiantes</Text>
<Text>{classroom.memberCount} estudiantes</Text>
</Flex>
<Flex align='center' gap={2}>
<Icon as={FiCode} />
Expand All @@ -160,12 +162,8 @@ export default function ClassScreen({ id }: Readonly<{ id: string }>) {
</Stack>

<VStack spacing={2} align='center'>
<Avatar
size='xl'
name={classroom.owner}
src='https://avatars.githubusercontent.com/u/57068341?v=4'
/>
<Text color='gray.300'>Ángel</Text>
<Avatar size='xl' name={professor?.username} src={professor?.avatar ?? ''} />
<Text color='gray.300'>{professor?.username}</Text>
</VStack>
</Grid>
</Container>
Expand Down
2 changes: 1 addition & 1 deletion src/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const CDN_URL = 'https://evogd-cdn.tnfangel.com';
export const API_URL =
process.env.NODE_ENV === 'development' ? 'http://localhost:4000' : 'https://evogd-api.tnfangel.com';
process.env['NODE_ENV'] === 'development' ? 'http://localhost:4000' : 'https://evogd-api.tnfangel.com';
1 change: 1 addition & 0 deletions src/types/IClassroomCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface IClassroom {
thumbnailId: number;
code: string;
owner: string;
memberCount: number;
}