journal.pl/src/pages/UserPage.tsx

63 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-04-16 12:18:29 +03:00
import React, { useCallback, useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
2024-03-01 11:43:31 +03:00
import { ArrowImg, IconButton, InputElement, InputLabel, InputWrapper, LessonItem, Lessonname, MainWrapper, StartWrapper } from './style';
2023-04-16 12:18:29 +03:00
import arrow from '../assets/36-arrow-right.svg';
2024-03-01 11:43:31 +03:00
import { api } from '../__data__/api/api';
import dayjs from 'dayjs';
2023-04-16 12:18:29 +03:00
export const UserPage = () => {
const [socketId, setSocketId] = useState(null);
2023-04-16 12:30:42 +03:00
const [error, setError] = useState(null);
2024-03-01 11:43:31 +03:00
const { lessonId, accessId } = useParams();
const acc = api.useGetAccessQuery({ accessCode: accessId })
const ls = api.useLessonByIdQuery(lessonId, {
pollingInterval: 1000,
skipPollingIfUnfocused: true
});
2023-04-16 12:18:29 +03:00
useEffect(() => {
2024-02-28 23:43:36 +03:00
// socket.on('connect', () => {
// const id = localStorage.getItem('socketId');
// if (!id) {
// localStorage.setItem('socketId', socket.id);
// setSocketId(socket.id);
// } else {
// setSocketId(id);
// }
2023-04-16 12:18:29 +03:00
2024-02-28 23:43:36 +03:00
// const name = localStorage.getItem('name');
// if (name) {
// const socket = getSocket();
// socket.emit('add', { socketId: id || socket.id, name, lessonid: lessonId });
// }
// })
// socket.on('error', data => {
// setError(data)
// })
2023-04-16 12:18:29 +03:00
}, []);
const [value, setValue] = useState(localStorage.getItem('name') || '');
2023-04-16 12:30:42 +03:00
2023-04-16 12:18:29 +03:00
return (
<MainWrapper>
<StartWrapper>
2024-03-01 11:43:31 +03:00
{acc.isLoading && <h1>Отправляем запрос</h1>}
{acc.isSuccess && <h1>Успешно</h1>}
<h1>Тема занятия - {ls.data?.body?.name}</h1>
<span>{dayjs(ls.data?.body?.date).format('DD MMMM YYYYг.')}</span>
<ul style={{ paddingLeft: 0 }}>
{ls.data?.body?.students?.map((student, index) => (
<LessonItem key={index}>
2024-03-01 12:03:16 +03:00
<Lessonname>{student.name || student.preferred_username}</Lessonname>
2024-03-01 11:43:31 +03:00
</LessonItem>
))}
</ul>
2023-04-16 12:18:29 +03:00
</StartWrapper>
</MainWrapper>
)
}