Skip to content
Open
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
21 changes: 9 additions & 12 deletions src/pages/schools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@ export default function Schools() {
const [loading, setLoading] = useState(true);
const router = useRouter();

useEffect(() => {
useEffect(async () => {
if (!api.AuthService.isAuthenticated()) {
router.push("/");
return;
}

api.SchoolService.getSchools()
.then((data) => {
const allSchools = data.data;

setSchools(allSchools);
setLoading(false);
})
.catch((error) => {
console.error("Erro ao buscar escolas:", error);
setLoading(false);
});
try {
const { data } = await api.SchoolService.getSchools()
setSchools(data);
} catch(error) {
console.error("Erro ao buscar escolas:", error);
} finally {
setLoading(false);
}
}, [router]);

const handleSelectSchool = (schoolId: string) => {
Expand Down
19 changes: 9 additions & 10 deletions src/pages/subject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function Subject() {
const [loading, setLoading] = useState(true);
const [subject, setSubject] = useState<{ id: string; name: string } | null>(null);

useEffect(() => {
useEffect(async () => {
if (!api.AuthService.isAuthenticated()) {
router.push("/");
return;
Expand All @@ -24,15 +24,14 @@ export default function Subject() {
return;
}

api.SubjectService.getSubject(selectedSubject)
.then((data) => {
setSubject(data.data);
setLoading(false);
})
.catch((error) => {
console.error("Erro ao buscar disciplina:", error);
setLoading(false);
});
try {
const { data } = await api.SubjectService.getSubject(selectedSubject)
setSubject(data.data);
} catch(error) {
console.error("Erro ao buscar disciplina:", error);
} finally {
setLoading(false);
}
}, [router]);

return (
Expand Down