From 69ecbea0be84b657e07b404fae6fd6b458df4980 Mon Sep 17 00:00:00 2001 From: PolishPigeon Date: Mon, 13 Jun 2022 01:11:46 +0200 Subject: [PATCH] feat: add context --- EGUI/lab3/src/App.js | 17 +++++++++++++++-- EGUI/lab3/src/context.context.jsx | 5 +++++ EGUI/lab3/src/routes/blog.jsx | 11 ++++++++++- EGUI/lab3/src/routes/login.jsx | 4 ++-- 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 EGUI/lab3/src/context.context.jsx diff --git a/EGUI/lab3/src/App.js b/EGUI/lab3/src/App.js index 8df6b461..34c2e5b1 100644 --- a/EGUI/lab3/src/App.js +++ b/EGUI/lab3/src/App.js @@ -7,10 +7,20 @@ import { Outlet, } from "react-router-dom"; import React from 'react'; +import loginContext from './context.context'; -export default function App() { +export default class App extends React.Component { + constructor(props) { + super(props); + this.state = { + login: "", + }; + } + + render() { return (
+ Lab 3 @@ -27,8 +37,11 @@ export default function App() { +
); - } + } +} + diff --git a/EGUI/lab3/src/context.context.jsx b/EGUI/lab3/src/context.context.jsx new file mode 100644 index 00000000..4badf766 --- /dev/null +++ b/EGUI/lab3/src/context.context.jsx @@ -0,0 +1,5 @@ +import { createContext } from "react"; + +const loginContext = createContext('test'); + +export default loginContext; diff --git a/EGUI/lab3/src/routes/blog.jsx b/EGUI/lab3/src/routes/blog.jsx index cfec5667..8fff8e4d 100644 --- a/EGUI/lab3/src/routes/blog.jsx +++ b/EGUI/lab3/src/routes/blog.jsx @@ -1,9 +1,18 @@ +import Login from './login'; import React from 'react'; +import loginContext from '../context.context'; export default class Blog extends React.Component { + constructor(props) { + super(props); + this.state = { + login: "", + }; + } + render() { return ( -
hello
+
You are not logged in {this.state.login}
); } } \ No newline at end of file diff --git a/EGUI/lab3/src/routes/login.jsx b/EGUI/lab3/src/routes/login.jsx index 8f51feb3..38c662ab 100644 --- a/EGUI/lab3/src/routes/login.jsx +++ b/EGUI/lab3/src/routes/login.jsx @@ -74,11 +74,11 @@ export default class Login extends React.Component { { alert("This login: \"" + this.state.login + "\" does not exist!"); return; - } - if(allData[0].password !== this.state.password) + } if(allData[0].password !== this.state.password) { alert("Wrong password!"); return; } + return this.state.login; } } \ No newline at end of file