From 28ffe0046479091e3fc277bc71e1aed6917b6204 Mon Sep 17 00:00:00 2001 From: Beesquit Date: Wed, 3 Sep 2025 17:43:44 +0300 Subject: [PATCH] nice --- src/App.tsx | 85 ++++++++++++++++--------------- src/components/FormField.css | 1 - src/index.css | 7 ++- src/pages/login/login.css | 36 +++++++++---- src/pages/login/login.tsx | 95 ++++++++++++++++++----------------- src/pages/login/old login.css | 66 ------------------------ src/pages/login/old login.tsx | 89 -------------------------------- 7 files changed, 126 insertions(+), 253 deletions(-) delete mode 100644 src/pages/login/old login.css delete mode 100644 src/pages/login/old login.tsx diff --git a/src/App.tsx b/src/App.tsx index b3c418c..52e942c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { BrowserRouter as Router, Routes, Route, Navigate, Outlet, useLocation } from 'react-router-dom'; +import { BrowserRouter as Router, Routes, Route, Outlet, useLocation, useNavigate } from 'react-router-dom'; import {useEffect, useState } from "react"; import { ToastContainer } from "react-toastify"; @@ -20,49 +20,14 @@ import Settings from "./pages/settings/settings" import useAuth from './auth/auth'; -function App() { - const theme = themeFromSourceColor(argbFromHex("ffddaf")); - const systemDark = window.matchMedia("(prefers-color-scheme: dark)").matches; - applyTheme(theme, { target: document.body, dark: systemDark }); - return ( - - <> - - - - } /> - } /> - - }> - } /> - } /> - } /> - - - 404} /> - - - - - ); -} - - const PrivateRoute = () => { const { token, loading } = useAuth(); + const navigate = useNavigate(); const location = useLocation(); const [checked, setChecked] = useState(false); const [isValid, setIsValid] = useState(false); + useEffect(() => { const checkAuth = async () => { if (!token) { @@ -83,10 +48,48 @@ const PrivateRoute = () => { return
Checking server availability...
; } + if (!isValid) { + navigate(`/login?to=${location.pathname}`); + } + else { + return + } +} + + +function App() { + const theme = themeFromSourceColor(argbFromHex("ffddaf")); + const systemDark = window.matchMedia("(prefers-color-scheme: dark)").matches; + applyTheme(theme, { target: document.body, dark: systemDark }); return ( - isValid - ? - : + + <> + + + + } /> + } /> + + }> + } /> + } /> + } /> + + + 404} /> + + + + ); } diff --git a/src/components/FormField.css b/src/components/FormField.css index 252460b..710c866 100644 --- a/src/components/FormField.css +++ b/src/components/FormField.css @@ -5,7 +5,6 @@ } .form-field input { - width: 100%; padding: 12px; border: 2px solid #ddd; border-radius: 8px; diff --git a/src/index.css b/src/index.css index de709c2..5bb4408 100644 --- a/src/index.css +++ b/src/index.css @@ -20,5 +20,10 @@ } body { - display: flex; + margin: 0; + padding: 0; + width: 100vw; + max-width: 100%; + height: 100vh; + max-height: 100%; } diff --git a/src/pages/login/login.css b/src/pages/login/login.css index 036d87c..192dc5c 100644 --- a/src/pages/login/login.css +++ b/src/pages/login/login.css @@ -1,16 +1,34 @@ -.login-div { +.login { display: flex; - height: 100%; - justify-content: flex-end; - align-items: center; - border: 1px solid green; + width: 100vw; + height: 100vh; + max-width:100%; + justify-content: space-between; } -.login-right-div { +.login-right { display: flex; height: 100%; - justify-content: flex-end; - align-items: center; flex-direction: column; - border: 1px solid blue; + justify-content: center; + margin-left: auto; + margin-right: 5vw; + margin-left: 5vw; +} + +.login-left { + overflow: hidden; + display: flex; + background-color: black; + height: 100%; + justify-content: center; + margin-right: auto; +} + + +.login-block { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; } diff --git a/src/pages/login/login.tsx b/src/pages/login/login.tsx index 0e32568..5569a96 100644 --- a/src/pages/login/login.tsx +++ b/src/pages/login/login.tsx @@ -41,52 +41,55 @@ const Login = () => { }; return ( -
-

- Login -

-
- setUsername(e.target.value)} - required - showError={usernameEmpty} - errorMessage="Please enter your username" - className="test1" - /> - setPassword(e.target.value)} - required - showError={passwordEmpty} - errorMessage="Please enter your password" - className="test2" - /> - - +
+
+ +
+
+
+

+ Login +

+
+ setUsername(e.target.value)} + required + showError={usernameEmpty} + errorMessage="Please enter your username" + /> + setPassword(e.target.value)} + required + showError={passwordEmpty} + errorMessage="Please enter your password" + /> + + +
+
); }; diff --git a/src/pages/login/old login.css b/src/pages/login/old login.css deleted file mode 100644 index fc3c9cd..0000000 --- a/src/pages/login/old login.css +++ /dev/null @@ -1,66 +0,0 @@ -div { - margin: auto; - text-align:center; -} - - -input { - margin: auto; - text-align: center; -} - - -button { - /* margin: auto; */ - background-color: var(--background_dark); - color: var(--text_dark); - border: 2px solid black; - border-color: var(--buttons-main-color); - padding: 16px 32px; - text-align: center; - text-decoration: none; - font-size: 16px; - cursor: pointer; - border-radius: 12px; - transition-duration: 0.4s; -} - -button:hover { - background-color: var(--buttons-main-color); - color: var(--text_dark); -} - -button:active { - background-color: var(--buttons-press-color); - color: var(--text_dark); -} - -button span { - cursor: pointer; - display: inline-block; - position: relative; - transition: 0.5s; -} - -button span:after { - /* content: '\00bb'; */ - content: '\2317'; - position: absolute; - opacity: 0; - top: 0; - right: -20px; - transition: 0.5s; -} - -button:hover span { - padding-right: 25px; -} - -button:hover span:after { - opacity: 1; - right: 0; -} - -.bold-text { - font-weight: bold; -} diff --git a/src/pages/login/old login.tsx b/src/pages/login/old login.tsx deleted file mode 100644 index 4b69b43..0000000 --- a/src/pages/login/old login.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import React from "react" -import './login.css' -import { useLocation, useNavigate } from 'react-router-dom'; - -const Login = () => { - state = { - username: "", - password: "", - } - - const { setAuth } = useContext(AuthContext); // используем контекст для получения значений isAuthenticated и setAuth - - const navigate = useNavigate(); // используем хук useNavigate для навигации по маршрутам - const location = useLocation(); // используем хук useLocation для получения текущего маршрута - - // получаем маршрут, на который нужно перенаправить пользователя после авторизации - const from = location.state?.from?.pathname || '/'; - - validateString = (text:string) => { - return text ? text : false - } - - return ( -
-
- this.setState({username: e.target.value})} - onBlur={(e) => this.setState({username: e.target.value})} - /> -
-
- this.setState({password: e.target.value})} - onBlur={(e) => this.setState({password: e.target.value})} - color="#FF0000" - /> -
-
- Your username is: {this.state.username} -
-
- { - (() => { - const r: string | boolean = this.validateString(this.state.username); - if (r) { - return r - } - return "invalid"; - })() - } -
-
- Your password is: {this.state.password} -
-
- { - (() => { - const r: string | boolean = this.validateString(this.state.password); - if (r) { - return r - } - return "invalid"; - })() - } -
- -
- ) -} - -export default Login;