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

Commit 4abbfd1

Browse files
committed
fix spinners + fix join HTTP method
1 parent 90788ed commit 4abbfd1

7 files changed

Lines changed: 41 additions & 178 deletions

File tree

src/api/api.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const api = {
2121
},
2222

2323
getById: async (id: string): Promise<IClassroom> => {
24-
const res = await fetch(`${API_URL}/classrooms/${id}`, {
24+
const res = await fetch(`${API_URL}/classrooms/${encodeURIComponent(id)}`, {
2525
headers: {
2626
...getAuthHeaders()
2727
}
@@ -57,7 +57,7 @@ export const api = {
5757
thumbnailId: number;
5858
}
5959
): Promise<{ id: string }> => {
60-
const res = await fetch(`${API_URL}/classrooms/${id}`, {
60+
const res = await fetch(`${API_URL}/classrooms/${encodeURIComponent(id)}`, {
6161
method: 'PUT',
6262
headers: {
6363
'Content-Type': 'application/json',
@@ -71,7 +71,8 @@ export const api = {
7171
},
7272

7373
join: async (code: string): Promise<IClassroom> => {
74-
const res = await fetch(`${API_URL}/classrooms/join/${code}`, {
74+
const res = await fetch(`${API_URL}/classrooms/join/${encodeURIComponent(code)}`, {
75+
method: 'POST',
7576
headers: {
7677
...getAuthHeaders()
7778
}
@@ -84,7 +85,7 @@ export const api = {
8485

8586
activities: {
8687
getByClassroom: async (classroomId: string): Promise<IActivity[]> => {
87-
const res = await fetch(`${API_URL}/classrooms/${classroomId}/activities`, {
88+
const res = await fetch(`${API_URL}/classrooms/${encodeURIComponent(classroomId)}/activities`, {
8889
headers: {
8990
...getAuthHeaders()
9091
}
@@ -95,11 +96,14 @@ export const api = {
9596
},
9697

9798
getById: async (classroomId: string, activityId: string): Promise<IActivity> => {
98-
const res = await fetch(`${API_URL}/classrooms/${classroomId}/activities/${activityId}`, {
99-
headers: {
100-
...getAuthHeaders()
99+
const res = await fetch(
100+
`${API_URL}/classrooms/${encodeURIComponent(classroomId)}/activities/${encodeURIComponent(activityId)}`,
101+
{
102+
headers: {
103+
...getAuthHeaders()
104+
}
101105
}
102-
});
106+
);
103107

104108
if (!res.ok) throw new Error('Failed to fetch activity');
105109
return res.json();
@@ -122,7 +126,7 @@ export const api = {
122126
};
123127
}
124128
): Promise<{ id: string }> => {
125-
const res = await fetch(`${API_URL}/classrooms/${classroomId}/activities`, {
129+
const res = await fetch(`${API_URL}/classrooms/${encodeURIComponent(classroomId)}/activities`, {
126130
method: 'POST',
127131
headers: {
128132
'Content-Type': 'application/json',
@@ -153,14 +157,17 @@ export const api = {
153157
};
154158
}
155159
): Promise<IActivity> => {
156-
const res = await fetch(`${API_URL}/classrooms/${classroomId}/activities/${activityId}`, {
157-
method: 'PUT',
158-
headers: {
159-
'Content-Type': 'application/json',
160-
...getAuthHeaders()
161-
},
162-
body: JSON.stringify(data)
163-
});
160+
const res = await fetch(
161+
`${API_URL}/classrooms/${encodeURIComponent(classroomId)}/activities/${encodeURIComponent(activityId)}`,
162+
{
163+
method: 'PUT',
164+
headers: {
165+
'Content-Type': 'application/json',
166+
...getAuthHeaders()
167+
},
168+
body: JSON.stringify(data)
169+
}
170+
);
164171

165172
if (!res.ok) throw new Error('Failed to update activity');
166173
return res.json();

src/components/screens/ActivityScreen.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
Link,
1818
ListItem,
1919
OrderedList,
20+
Spinner,
2021
Text,
2122
UnorderedList,
2223
VStack,
@@ -79,7 +80,7 @@ export default function ActivityScreen({
7980
if (isLoading) {
8081
return (
8182
<Flex h='100%' align='center' justify='center'>
82-
<Text>Cargando...</Text>
83+
<Spinner size='xl' borderWidth='4px' />
8384
</Flex>
8485
);
8586
}

src/components/screens/ClassScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default function ClassScreen({ id }: Readonly<{ id: string }>) {
7575
if (isLoading) {
7676
return (
7777
<Flex h='100%' align='center' justify='center'>
78-
<Spinner size='lg' />
78+
<Spinner size='xl' borderWidth='4px' />
7979
</Flex>
8080
);
8181
}

src/components/screens/ClassesScreen.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22

33
import { api } from '@/api/api';
44
import type { IClassroom } from '@/types/IClassroomCard';
5-
import { Box, Button, Container, Flex, Grid, Heading, SimpleGrid, Text, useDisclosure } from '@chakra-ui/react';
5+
import {
6+
Box,
7+
Button,
8+
Container,
9+
Flex,
10+
Grid,
11+
Heading,
12+
SimpleGrid,
13+
Spinner,
14+
Text,
15+
useDisclosure
16+
} from '@chakra-ui/react';
617
import { useEffect, useState } from 'react';
718
import { FiPlus, FiUsers } from 'react-icons/fi';
819
import ClassroomCard from '../general/ClassroomCard';
@@ -61,7 +72,7 @@ export default function ClassesScreen() {
6172
<Container maxW='container.xl' py={8}>
6273
{isLoading ? (
6374
<Flex h='200px' align='center' justify='center'>
64-
<Text>Cargando...</Text>
75+
<Spinner size='xl' borderWidth='4px' />
6576
</Flex>
6677
) : classrooms.length > 0 ? (
6778
<SimpleGrid columns={{ base: 1, sm: 2, md: 3, lg: 4 }} spacing={6}>

src/components/screens/IndexScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default function IndexScreen() {
8585
</Heading>
8686
{isLoading ? (
8787
<Flex h='200px' align='center' justify='center'>
88-
<Spinner size='lg' />
88+
<Spinner size='xl' borderWidth='4px' />
8989
</Flex>
9090
) : classrooms.length > 0 ? (
9191
<SimpleGrid columns={{ base: 1, sm: 2, md: 3, lg: 4 }} spacing={6}>

src/mocks/activities.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/mocks/classrooms.ts

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)