From a40c6eea0a1b5c0cf965d1aea1256a9002ed45bf Mon Sep 17 00:00:00 2001 From: primakov Date: Tue, 13 Feb 2024 21:29:44 +0300 Subject: [PATCH] check 2 --- src/__data__/const.ts | 7 ++++ src/index.tsx | 8 ++--- src/pages/Journal.tsx | 78 +++++++++++++++++++++++++++---------------- 3 files changed, 58 insertions(+), 35 deletions(-) create mode 100644 src/__data__/const.ts diff --git a/src/__data__/const.ts b/src/__data__/const.ts new file mode 100644 index 0000000..d6b9faa --- /dev/null +++ b/src/__data__/const.ts @@ -0,0 +1,7 @@ +import Keycloak from 'keycloak-js'; + +export const keycloak = new Keycloak({ + url: 'https://kc.inno-js.ru', + realm: 'test', + clientId: 'jurnal' +}); \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx index 63c74a9..9a76216 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,16 +1,12 @@ import React from 'react'; import ReactDom from 'react-dom'; -import Keycloak from 'keycloak-js'; import App from './app'; +import { keycloak } from './__data__/const'; export default () => ; -const keycloak = new Keycloak({ - url: 'https://kc.inno-js.ru', - realm: 'test', - clientId: 'jurnal' -}); + const start = async () => { try { diff --git a/src/pages/Journal.tsx b/src/pages/Journal.tsx index cdfe951..5e8a858 100644 --- a/src/pages/Journal.tsx +++ b/src/pages/Journal.tsx @@ -1,6 +1,6 @@ -import React, { useCallback, useEffect, useRef, useState } from 'react'; -import dayjs from 'dayjs'; -import { Link } from 'react-router-dom' +import React, { useCallback, useEffect, useRef, useState } from "react"; +import dayjs from "dayjs"; +import { Link } from "react-router-dom"; import { ArrowImg, @@ -11,11 +11,12 @@ import { StartWrapper, LessonItem, Lessonname, -} from './style'; +} from "./style"; -import arrow from '../assets/36-arrow-right.svg'; +import arrow from "../assets/36-arrow-right.svg"; import { connect, getSocket } from "../socket"; -import { getConfigValue } from '@ijl/cli'; +import { getConfigValue } from "@ijl/cli"; +import { keycloak } from "../__data__/const"; export const Journal = () => { const [lessons, setLessons] = useState(null); @@ -23,36 +24,53 @@ export const Journal = () => { useEffect(() => { connect(); const socket = getSocket(); - socket.on('lessons', data => { - setLessons(data) - }) + socket.on("lessons", (data) => { + setLessons(data); + }); - fetch(`${getConfigValue('journal.back.url')}/check`) + const check = async () => { + if (keycloak.authenticated) { + keycloak; + const rq = await fetch(`${getConfigValue("journal.back.url")}/check`, { + headers: { + accept: "application/json", + authorization: `Bearer ${keycloak.token}`, + }, + }); + const data = await rq.json(); + + console.log("check", data); + } + }; + + check(); }, []); - const [value, setValue] = useState(''); - const handleChange = useCallback(event => { - setValue(event.target.value.toUpperCase()) - }, [setValue]); + const [value, setValue] = useState(""); + const handleChange = useCallback( + (event) => { + setValue(event.target.value.toUpperCase()); + }, + [setValue] + ); const inputRef = useRef(null); - const handleSubmit = useCallback((event) => { - event.preventDefault(); + const handleSubmit = useCallback( + (event) => { + event.preventDefault(); - const socket = getSocket(); - socket.emit('create-lesson', { lessonName: value }); - setValue('') - }, [value]) + const socket = getSocket(); + socket.emit("create-lesson", { lessonName: value }); + setValue(""); + }, + [value] + ); return (
- - Название новой лекции: - + Название новой лекции: {
    {lessons?.map((lesson) => ( - + {lesson.name} - {dayjs(lesson.ts).format('DD MMMM YYYYг.')} - Участников - {lesson.padavans.length} + {dayjs(lesson.ts).format("DD MMMM YYYYг.")} + + Участников - {lesson.padavans.length} + ))}
- ) + ); };