get lessons list

This commit is contained in:
2024-02-29 09:18:13 +03:00
parent 5134d44e39
commit 80713f7e0f
7 changed files with 72 additions and 54 deletions

View File

@@ -16,9 +16,14 @@ import {
import arrow from "../assets/36-arrow-right.svg";
import { keycloak } from "../__data__/kc";
import { useAppSelector } from "../__data__/store";
import { api } from '../__data__/api/api'
import { isTeacher } from "../utils/user";
export const Journal = () => {
const [lessons, setLessons] = useState(null);
const user = useAppSelector((s) => s.user);
const { data, isLoading, error } = api.useLessonListQuery();
useEffect(() => {
const check = async () => {
@@ -34,7 +39,7 @@ export const Journal = () => {
console.log("check", data);
} else {
keycloak.onAuthSuccess = check
keycloak.onAuthSuccess = check;
}
};
@@ -55,9 +60,9 @@ export const Journal = () => {
const data = await rq.json();
setAnswer(data);
} else {
setAnswer({ message: 'Пользователь не авторизован' })
setAnswer({ message: "Пользователь не авторизован" });
}
}
};
const [value, setValue] = useState("");
const handleChange = useCallback(
@@ -81,36 +86,32 @@ export const Journal = () => {
return (
<StartWrapper>
<div>
<IconButton onClick={send} title="Запрос">
<ArrowImg src={arrow} />
</IconButton>
<pre>{JSON.stringify(answer, null, 4)}</pre>
</div>
<form onSubmit={handleSubmit}>
<InputWrapper>
<InputLabel htmlFor="input">Название новой лекции:</InputLabel>
<InputElement
value={value}
onChange={handleChange}
ref={inputRef}
id="input"
type="text"
autoComplete="off"
/>
<IconButton type="submit">
<ArrowImg src={arrow} />
</IconButton>
</InputWrapper>
</form>
{isTeacher(user) && (
<form onSubmit={handleSubmit}>
<InputWrapper>
<InputLabel htmlFor="input">Название новой лекции:</InputLabel>
<InputElement
value={value}
onChange={handleChange}
ref={inputRef}
id="input"
type="text"
autoComplete="off"
/>
<IconButton type="submit">
<ArrowImg src={arrow} />
</IconButton>
</InputWrapper>
</form>
)}
<ul style={{ paddingLeft: 0 }}>
{lessons?.map((lesson) => (
<LessonItem key={lesson.id}>
<Link to={`/journal/l/${lesson.id}`} style={{ display: "flex" }}>
{data?.body?.map((lesson) => (
<LessonItem key={lesson._id}>
<Link to={isTeacher(user) ? `/journal/l/${lesson._id}` : ''} style={{ display: "flex" }}>
<Lessonname>{lesson.name}</Lessonname>
<span>{dayjs(lesson.ts).format("DD MMMM YYYYг.")}</span>
<span>{dayjs(lesson.date).format("DD MMMM YYYYг.")}</span>
<span style={{ marginLeft: "auto" }}>
Участников - {lesson.padavans.length}
Участников - {lesson.students.length}
</span>
</Link>
</LessonItem>