Skip to content

Commit

Permalink
feat: add teachers data to presenters page
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirezaYousefpourM committed Nov 25, 2023
1 parent c45b70c commit a21ea5a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions frontend/src/pages/presenters/PresentersPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import usePresenterPage from './usePresentersPage.js';
import '../../css/Presenters.css';

export default function PresenterPage() {
const { teachers } = usePresenterPage();
const { renderedData } = usePresenterPage();
const navigate = useNavigate();

const navToPresenterDetailPage = (id) => () => {
navigate(`${id}`, {
state: {
teachersArray: teachers,
teachersArray: renderedData,
},
});
};

if (teachers) {
if (renderedData) {
return (
<Stack>
<Typography variant="h1" fontSize="60px" sx={{ textAlign: 'center', pb: 5 }}>
Expand All @@ -30,7 +30,7 @@ export default function PresenterPage() {
className="presenters-container"
gap={5}
>
{teachers.map((item, index) => (
{renderedData.map((item, index) => (
<PresenterCard
key={index}
name={item.name}
Expand Down
15 changes: 8 additions & 7 deletions frontend/src/pages/presenters/usePresentersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { useEffect, useState } from 'react';
import { useAPI } from '../../providers/APIProvider/APIProvider';

export default function usePresenterPage() {
const { teachersData, getTeachersData } = useAPI();
const [teachers, setTeachers] = useState();
const { teachersData, getTeachersData, presenterData, getPresenterData } = useAPI();
const [renderedData, setRenderedData] = useState();
useEffect(() => {
getTeachersData();
}, []);
getPresenterData()
}, [getPresenterData, getTeachersData]);

useEffect(() => {
if (teachersData == null) return;
setTeachers(teachersData);
}, [teachersData]);
if (teachersData == null || presenterData == null) return;
setRenderedData(teachersData.concat(presenterData));
}, [presenterData, teachersData]);

return {
teachers,
renderedData,
};
}
3 changes: 1 addition & 2 deletions frontend/src/providers/APIProvider/APIProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export function APIProvider({children}) {
}, [currentYear, service])

const getTeachersData = useCallback(async () => {
await service.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.presenter}`)
await service.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.teacher}`)
.then(response => setTeachersData(response.data))
}, [currentYear, service])

Expand Down Expand Up @@ -278,7 +278,6 @@ export function APIProvider({children}) {
if (!Helper.checkTokenValidity(accessToken)) {
updateAccessTokenWithRefreshToken()
}
service.defaults.headers.common['Authorization'] = getAccessTokenHeader();
}, [accessToken, refreshToken, service.defaults.headers.common, updateAccessTokenWithRefreshToken])


Expand Down

0 comments on commit a21ea5a

Please sign in to comment.