Initial commit: Edu Helper (Docker, React, Express, Prisma)
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
@@ -0,0 +1,73 @@
|
||||
# React + TypeScript + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
||||
|
||||
## React Compiler
|
||||
|
||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
|
||||
```js
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
|
||||
// Remove tseslint.configs.recommended and replace with this
|
||||
tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
tseslint.configs.stylisticTypeChecked,
|
||||
|
||||
// Other configs...
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
// Enable lint rules for React
|
||||
reactX.configs['recommended-typescript'],
|
||||
// Enable lint rules for React DOM
|
||||
reactDom.configs.recommended,
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
@@ -0,0 +1,23 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
reactHooks.configs.flat.recommended,
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
},
|
||||
])
|
||||
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>frontend</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+5089
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"html2canvas": "^1.4.1",
|
||||
"jspdf": "^4.2.1",
|
||||
"lucide-react": "^1.7.0",
|
||||
"react": "^19.2.4",
|
||||
"react-dom": "^19.2.4",
|
||||
"react-markdown": "^10.1.0",
|
||||
"react-router-dom": "^7.13.2",
|
||||
"remark-gfm": "^4.0.1",
|
||||
"tailwind-merge": "^3.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.4",
|
||||
"@tailwindcss/vite": "^4.2.2",
|
||||
"@types/node": "^24.12.0",
|
||||
"@types/react": "^19.2.14",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^6.0.1",
|
||||
"eslint": "^9.39.4",
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"eslint-plugin-react-refresh": "^0.5.2",
|
||||
"globals": "^17.4.0",
|
||||
"tailwindcss": "^4.2.2",
|
||||
"typescript": "~5.9.3",
|
||||
"typescript-eslint": "^8.57.0",
|
||||
"vite": "^8.0.1"
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 9.3 KiB |
@@ -0,0 +1,24 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<symbol id="bluesky-icon" viewBox="0 0 16 17">
|
||||
<g clip-path="url(#bluesky-clip)"><path fill="#08060d" d="M7.75 7.735c-.693-1.348-2.58-3.86-4.334-5.097-1.68-1.187-2.32-.981-2.74-.79C.188 2.065.1 2.812.1 3.251s.241 3.602.398 4.13c.52 1.744 2.367 2.333 4.07 2.145-2.495.37-4.71 1.278-1.805 4.512 3.196 3.309 4.38-.71 4.987-2.746.608 2.036 1.307 5.91 4.93 2.746 2.72-2.746.747-4.143-1.747-4.512 1.702.189 3.55-.4 4.07-2.145.156-.528.397-3.691.397-4.13s-.088-1.186-.575-1.406c-.42-.19-1.06-.395-2.741.79-1.755 1.24-3.64 3.752-4.334 5.099"/></g>
|
||||
<defs><clipPath id="bluesky-clip"><path fill="#fff" d="M.1.85h15.3v15.3H.1z"/></clipPath></defs>
|
||||
</symbol>
|
||||
<symbol id="discord-icon" viewBox="0 0 20 19">
|
||||
<path fill="#08060d" d="M16.224 3.768a14.5 14.5 0 0 0-3.67-1.153c-.158.286-.343.67-.47.976a13.5 13.5 0 0 0-4.067 0c-.128-.306-.317-.69-.476-.976A14.4 14.4 0 0 0 3.868 3.77C1.546 7.28.916 10.703 1.231 14.077a14.7 14.7 0 0 0 4.5 2.306q.545-.748.965-1.587a9.5 9.5 0 0 1-1.518-.74q.191-.14.372-.293c2.927 1.369 6.107 1.369 8.999 0q.183.152.372.294-.723.437-1.52.74.418.838.963 1.588a14.6 14.6 0 0 0 4.504-2.308c.37-3.911-.63-7.302-2.644-10.309m-9.13 8.234c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.894 0 1.614.82 1.599 1.82.001 1-.705 1.82-1.6 1.82m5.91 0c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.893 0 1.614.82 1.599 1.82 0 1-.706 1.82-1.6 1.82"/>
|
||||
</symbol>
|
||||
<symbol id="documentation-icon" viewBox="0 0 21 20">
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="m15.5 13.333 1.533 1.322c.645.555.967.833.967 1.178s-.322.623-.967 1.179L15.5 18.333m-3.333-5-1.534 1.322c-.644.555-.966.833-.966 1.178s.322.623.966 1.179l1.534 1.321"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M17.167 10.836v-4.32c0-1.41 0-2.117-.224-2.68-.359-.906-1.118-1.621-2.08-1.96-.599-.21-1.349-.21-2.848-.21-2.623 0-3.935 0-4.983.369-1.684.591-3.013 1.842-3.641 3.428C3 6.449 3 7.684 3 10.154v2.122c0 2.558 0 3.838.706 4.726q.306.383.713.671c.76.536 1.79.64 3.581.66"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M3 10a2.78 2.78 0 0 1 2.778-2.778c.555 0 1.209.097 1.748-.047.48-.129.854-.503.982-.982.145-.54.048-1.194.048-1.749a2.78 2.78 0 0 1 2.777-2.777"/>
|
||||
</symbol>
|
||||
<symbol id="github-icon" viewBox="0 0 19 19">
|
||||
<path fill="#08060d" fill-rule="evenodd" d="M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844" clip-rule="evenodd"/>
|
||||
</symbol>
|
||||
<symbol id="social-icon" viewBox="0 0 20 20">
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M12.5 6.667a4.167 4.167 0 1 0-8.334 0 4.167 4.167 0 0 0 8.334 0"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M2.5 16.667a5.833 5.833 0 0 1 8.75-5.053m3.837.474.513 1.035c.07.144.257.282.414.309l.93.155c.596.1.736.536.307.965l-.723.73a.64.64 0 0 0-.152.531l.207.903c.164.715-.213.991-.84.618l-.872-.52a.63.63 0 0 0-.577 0l-.872.52c-.624.373-1.003.094-.84-.618l.207-.903a.64.64 0 0 0-.152-.532l-.723-.729c-.426-.43-.289-.864.306-.964l.93-.156a.64.64 0 0 0 .412-.31l.513-1.034c.28-.562.735-.562 1.012 0"/>
|
||||
</symbol>
|
||||
<symbol id="x-icon" viewBox="0 0 19 19">
|
||||
<path fill="#08060d" fill-rule="evenodd" d="M1.893 1.98c.052.072 1.245 1.769 2.653 3.77l2.892 4.114c.183.261.333.48.333.486s-.068.089-.152.183l-.522.593-.765.867-3.597 4.087c-.375.426-.734.834-.798.905a1 1 0 0 0-.118.148c0 .01.236.017.664.017h.663l.729-.83c.4-.457.796-.906.879-.999a692 692 0 0 0 1.794-2.038c.034-.037.301-.34.594-.675l.551-.624.345-.392a7 7 0 0 1 .34-.374c.006 0 .93 1.306 2.052 2.903l2.084 2.965.045.063h2.275c1.87 0 2.273-.003 2.266-.021-.008-.02-1.098-1.572-3.894-5.547-2.013-2.862-2.28-3.246-2.273-3.266.008-.019.282-.332 2.085-2.38l2-2.274 1.567-1.782c.022-.028-.016-.03-.65-.03h-.674l-.3.342a871 871 0 0 1-1.782 2.025c-.067.075-.405.458-.75.852a100 100 0 0 1-.803.91c-.148.172-.299.344-.99 1.127-.304.343-.32.358-.345.327-.015-.019-.904-1.282-1.976-2.808L6.365 1.85H1.8zm1.782.91 8.078 11.294c.772 1.08 1.413 1.973 1.425 1.984.016.017.241.02 1.05.017l1.03-.004-2.694-3.766L7.796 5.75 5.722 2.852l-1.039-.004-1.039-.004z" clip-rule="evenodd"/>
|
||||
</symbol>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.9 KiB |
@@ -0,0 +1,49 @@
|
||||
import { BrowserRouter, Routes, Route, Navigate, Outlet } from "react-router-dom";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { AuthProvider, useAuth } from "@/context/AuthContext";
|
||||
import Layout from "@/components/Layout";
|
||||
import HomePage from "@/pages/HomePage";
|
||||
import QuestionsPage from "@/pages/QuestionsPage";
|
||||
import TextbookPage from "@/pages/TextbookPage";
|
||||
import TestPage from "@/pages/TestPage";
|
||||
import ReportPage from "@/pages/ReportPage";
|
||||
import ArchivePage from "@/pages/ArchivePage";
|
||||
import SettingsPage from "@/pages/SettingsPage";
|
||||
import LoginPage from "@/pages/LoginPage";
|
||||
|
||||
function RequireAuth() {
|
||||
const { user, loading } = useAuth();
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-background">
|
||||
<Loader2 className="animate-spin text-primary" size={28} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (!user) return <Navigate to="/login" replace />;
|
||||
return <Outlet />;
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<AuthProvider>
|
||||
<Routes>
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<Route element={<RequireAuth />}>
|
||||
<Route element={<Layout />}>
|
||||
<Route path="/" element={<HomePage />} />
|
||||
<Route path="/questions" element={<QuestionsPage />} />
|
||||
<Route path="/textbook" element={<TextbookPage />} />
|
||||
<Route path="/test" element={<TestPage />} />
|
||||
<Route path="/report" element={<ReportPage />} />
|
||||
<Route path="/archive" element={<ArchivePage />} />
|
||||
<Route path="/settings" element={<SettingsPage />} />
|
||||
</Route>
|
||||
</Route>
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
</AuthProvider>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 8.5 KiB |
@@ -0,0 +1,108 @@
|
||||
import { NavLink, Outlet, useLocation } from "react-router-dom";
|
||||
import {
|
||||
MessageCircle,
|
||||
HelpCircle,
|
||||
BookOpen,
|
||||
ClipboardList,
|
||||
FileText,
|
||||
Settings,
|
||||
Sparkles,
|
||||
Archive,
|
||||
LogOut,
|
||||
} from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
const baseNavItems = [
|
||||
{ to: "/", icon: MessageCircle, label: "Чат" },
|
||||
{ to: "/questions", icon: HelpCircle, label: "Вопросы" },
|
||||
{ to: "/textbook", icon: BookOpen, label: "Учебник" },
|
||||
{ to: "/test", icon: ClipboardList, label: "Тест" },
|
||||
{ to: "/report", icon: FileText, label: "Зал" },
|
||||
{ to: "/archive", icon: Archive, label: "Архив" },
|
||||
] as const;
|
||||
|
||||
export default function Layout() {
|
||||
const location = useLocation();
|
||||
const { user, logout } = useAuth();
|
||||
const isTutor = user?.role === "TUTOR";
|
||||
|
||||
const navItems = isTutor
|
||||
? [...baseNavItems, { to: "/settings", icon: Settings, label: "Настройки" } as const]
|
||||
: [...baseNavItems];
|
||||
|
||||
return (
|
||||
<div className="flex h-screen bg-background">
|
||||
<aside className="w-[220px] border-r border-border/60 flex flex-col shrink-0 bg-sidebar">
|
||||
<div className="p-5 pb-4">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<div className="w-8 h-8 rounded-lg bg-primary flex items-center justify-center animate-pulse-glow">
|
||||
<Sparkles size={16} className="text-white" />
|
||||
</div>
|
||||
<span className="text-[15px] font-semibold tracking-tight text-foreground">
|
||||
EduHelper
|
||||
</span>
|
||||
</div>
|
||||
{user && (
|
||||
<p className="text-[11px] text-muted-foreground mt-2 truncate" title={user.username}>
|
||||
{user.displayName || user.username}
|
||||
{isTutor ? (
|
||||
<span className="block text-[10px] opacity-70">наставник</span>
|
||||
) : (
|
||||
<span className="block text-[10px] opacity-70">ученик</span>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<nav className="flex-1 px-3 space-y-0.5">
|
||||
{navItems.map(({ to, icon: Icon, label }, i) => {
|
||||
const isActive =
|
||||
to === "/" ? location.pathname === "/" : location.pathname.startsWith(to);
|
||||
|
||||
return (
|
||||
<NavLink
|
||||
key={to}
|
||||
to={to}
|
||||
style={{ animationDelay: `${i * 40}ms` }}
|
||||
className={cn(
|
||||
"flex items-center gap-2.5 rounded-xl px-3 py-2.5 text-[13px] font-medium transition-all duration-200 animate-slide-in",
|
||||
isActive
|
||||
? "bg-sidebar-active text-primary shadow-sm"
|
||||
: "text-muted-foreground hover:bg-muted/60 hover:text-foreground"
|
||||
)}
|
||||
>
|
||||
<Icon size={17} strokeWidth={isActive ? 2 : 1.7} />
|
||||
{label}
|
||||
</NavLink>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
<div className="p-3 pb-4 space-y-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="w-full justify-start text-muted-foreground text-[13px]"
|
||||
onClick={() => logout()}
|
||||
>
|
||||
<LogOut size={16} className="mr-2" />
|
||||
Выйти
|
||||
</Button>
|
||||
<div className="rounded-xl bg-accent/50 p-3 text-center">
|
||||
<p className="text-[11px] text-muted-foreground leading-relaxed">
|
||||
Powered by DeepSeek
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<main className="flex-1 overflow-y-auto">
|
||||
<div className="max-w-3xl mx-auto px-6 py-6 animate-fade-in" key={location.pathname}>
|
||||
<Outlet />
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import { useRef } from "react";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface MarkdownProps {
|
||||
children: string;
|
||||
className?: string;
|
||||
exportable?: boolean;
|
||||
exportTitle?: string;
|
||||
}
|
||||
|
||||
export default function Markdown({
|
||||
children,
|
||||
className = "",
|
||||
exportable = false,
|
||||
exportTitle = "document",
|
||||
}: MarkdownProps) {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
|
||||
async function exportPdf() {
|
||||
const el = ref.current;
|
||||
if (!el) return;
|
||||
|
||||
const { default: html2canvas } = await import("html2canvas");
|
||||
const { default: jsPDF } = await import("jspdf");
|
||||
|
||||
const canvas = await html2canvas(el, {
|
||||
scale: 2,
|
||||
useCORS: true,
|
||||
backgroundColor: "#ffffff",
|
||||
});
|
||||
|
||||
const imgData = canvas.toDataURL("image/png");
|
||||
const imgWidth = 190;
|
||||
const pageHeight = 277;
|
||||
const imgHeight = (canvas.height * imgWidth) / canvas.width;
|
||||
|
||||
const pdf = new jsPDF("p", "mm", "a4");
|
||||
let heightLeft = imgHeight;
|
||||
let position = 10;
|
||||
|
||||
pdf.addImage(imgData, "PNG", 10, position, imgWidth, imgHeight);
|
||||
heightLeft -= pageHeight;
|
||||
|
||||
while (heightLeft > 0) {
|
||||
position = heightLeft - imgHeight + 10;
|
||||
pdf.addPage();
|
||||
pdf.addImage(imgData, "PNG", 10, position, imgWidth, imgHeight);
|
||||
heightLeft -= pageHeight;
|
||||
}
|
||||
|
||||
pdf.save(`${exportTitle}.pdf`);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative group">
|
||||
{exportable && (
|
||||
<button
|
||||
onClick={exportPdf}
|
||||
className="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity duration-200 text-xs bg-primary text-primary-foreground px-3 py-1.5 rounded-lg shadow-sm hover:bg-primary/90 cursor-pointer z-10"
|
||||
>
|
||||
PDF
|
||||
</button>
|
||||
)}
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("prose prose-sm max-w-none text-[14px]", className)}
|
||||
>
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm]}
|
||||
components={{
|
||||
table: ({ children, ...props }) => (
|
||||
<div className="overflow-x-auto rounded-lg my-3">
|
||||
<table {...props}>{children}</table>
|
||||
</div>
|
||||
),
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { type ButtonHTMLAttributes, forwardRef } from "react";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-xl text-sm font-medium transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 cursor-pointer active:scale-[0.98]",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"bg-primary text-primary-foreground shadow-sm hover:bg-primary/90 hover:shadow-md hover:shadow-primary/20",
|
||||
destructive:
|
||||
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
||||
outline:
|
||||
"border border-input bg-background hover:bg-accent hover:text-accent-foreground hover:border-primary/30",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground hover:bg-muted",
|
||||
ghost:
|
||||
"hover:bg-accent hover:text-accent-foreground",
|
||||
link:
|
||||
"text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-10 px-4 py-2",
|
||||
sm: "h-9 rounded-lg px-3 text-xs",
|
||||
lg: "h-11 rounded-xl px-6",
|
||||
icon: "h-10 w-10",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export interface ButtonProps
|
||||
extends ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {}
|
||||
|
||||
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, ...props }, ref) => (
|
||||
<button className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />
|
||||
)
|
||||
);
|
||||
Button.displayName = "Button";
|
||||
|
||||
export { Button, buttonVariants };
|
||||
@@ -0,0 +1,43 @@
|
||||
import { type HTMLAttributes, forwardRef } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const Card = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"rounded-2xl border bg-card text-card-foreground shadow-sm glow-card",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
Card.displayName = "Card";
|
||||
|
||||
const CardHeader = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<div ref={ref} className={cn("flex flex-col space-y-1.5 p-5 pb-3", className)} {...props} />
|
||||
)
|
||||
);
|
||||
CardHeader.displayName = "CardHeader";
|
||||
|
||||
const CardTitle = forwardRef<HTMLHeadingElement, HTMLAttributes<HTMLHeadingElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<h3
|
||||
ref={ref}
|
||||
className={cn("text-base font-semibold leading-none tracking-tight", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
CardTitle.displayName = "CardTitle";
|
||||
|
||||
const CardContent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<div ref={ref} className={cn("p-5 pt-0", className)} {...props} />
|
||||
)
|
||||
);
|
||||
CardContent.displayName = "CardContent";
|
||||
|
||||
export { Card, CardHeader, CardTitle, CardContent };
|
||||
@@ -0,0 +1,19 @@
|
||||
import { type InputHTMLAttributes, forwardRef } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const Input = forwardRef<HTMLInputElement, InputHTMLAttributes<HTMLInputElement>>(
|
||||
({ className, type, ...props }, ref) => (
|
||||
<input
|
||||
type={type}
|
||||
className={cn(
|
||||
"flex h-10 w-full rounded-xl border border-input bg-background px-3.5 py-2 text-sm transition-all duration-200 placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/20 focus-visible:border-primary/40 disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
Input.displayName = "Input";
|
||||
|
||||
export { Input };
|
||||
@@ -0,0 +1,15 @@
|
||||
import { type LabelHTMLAttributes, forwardRef } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const Label = forwardRef<HTMLLabelElement, LabelHTMLAttributes<HTMLLabelElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<label
|
||||
ref={ref}
|
||||
className={cn("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
Label.displayName = "Label";
|
||||
|
||||
export { Label };
|
||||
@@ -0,0 +1,18 @@
|
||||
import { type TextareaHTMLAttributes, forwardRef } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const Textarea = forwardRef<HTMLTextAreaElement, TextareaHTMLAttributes<HTMLTextAreaElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<textarea
|
||||
className={cn(
|
||||
"flex min-h-[80px] w-full rounded-xl border border-input bg-background px-3.5 py-3 text-sm transition-all duration-200 placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/20 focus-visible:border-primary/40 disabled:cursor-not-allowed disabled:opacity-50 resize-none",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
);
|
||||
Textarea.displayName = "Textarea";
|
||||
|
||||
export { Textarea };
|
||||
@@ -0,0 +1,68 @@
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import { API_BASE, apiFetch } from "@/lib/utils";
|
||||
|
||||
export type UserRole = "TUTOR" | "STUDENT";
|
||||
|
||||
export interface AuthUser {
|
||||
id: number;
|
||||
username: string;
|
||||
role: UserRole;
|
||||
displayName: string | null;
|
||||
}
|
||||
|
||||
interface AuthState {
|
||||
user: AuthUser | null;
|
||||
loading: boolean;
|
||||
refresh: () => Promise<void>;
|
||||
logout: () => Promise<void>;
|
||||
setUser: (u: AuthUser | null) => void;
|
||||
}
|
||||
|
||||
const AuthContext = createContext<AuthState | null>(null);
|
||||
|
||||
export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const [user, setUser] = useState<AuthUser | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
try {
|
||||
const data = await apiFetch<{ user: AuthUser }>("/auth/me", { skipAuthRedirect: true });
|
||||
setUser(data.user);
|
||||
} catch {
|
||||
setUser(null);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
refresh();
|
||||
}, [refresh]);
|
||||
|
||||
const logout = useCallback(async () => {
|
||||
await fetch(`${API_BASE}/auth/logout`, { method: "POST", credentials: "include" });
|
||||
setUser(null);
|
||||
window.location.assign("/login");
|
||||
}, []);
|
||||
|
||||
const value = useMemo(
|
||||
() => ({ user, loading, refresh, logout, setUser }),
|
||||
[user, loading, refresh, logout]
|
||||
);
|
||||
|
||||
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
||||
}
|
||||
|
||||
export function useAuth(): AuthState {
|
||||
const ctx = useContext(AuthContext);
|
||||
if (!ctx) throw new Error("useAuth must be used within AuthProvider");
|
||||
return ctx;
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
@theme {
|
||||
--color-background: #ffffff;
|
||||
--color-foreground: #0f172a;
|
||||
--color-primary: #4f46e5;
|
||||
--color-primary-foreground: #ffffff;
|
||||
--color-secondary: #f8fafc;
|
||||
--color-secondary-foreground: #1e293b;
|
||||
--color-muted: #f1f5f9;
|
||||
--color-muted-foreground: #64748b;
|
||||
--color-accent: #eef2ff;
|
||||
--color-accent-foreground: #3730a3;
|
||||
--color-destructive: #ef4444;
|
||||
--color-destructive-foreground: #ffffff;
|
||||
--color-border: #e2e8f0;
|
||||
--color-input: #e2e8f0;
|
||||
--color-ring: #4f46e5;
|
||||
--color-card: #ffffff;
|
||||
--color-card-foreground: #0f172a;
|
||||
--color-sidebar: #fafbfc;
|
||||
--color-sidebar-active: #eef2ff;
|
||||
--color-glow: rgba(79, 70, 229, 0.15);
|
||||
--color-glow-strong: rgba(79, 70, 229, 0.25);
|
||||
--radius-sm: 0.375rem;
|
||||
--radius-md: 0.5rem;
|
||||
--radius-lg: 0.75rem;
|
||||
--radius-xl: 1rem;
|
||||
--radius-2xl: 1.25rem;
|
||||
}
|
||||
|
||||
@keyframes fade-in {
|
||||
from { opacity: 0; transform: translateY(8px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
@keyframes slide-in-left {
|
||||
from { opacity: 0; transform: translateX(-12px); }
|
||||
to { opacity: 1; transform: translateX(0); }
|
||||
}
|
||||
|
||||
@keyframes pulse-glow {
|
||||
0%, 100% { box-shadow: 0 0 15px var(--color-glow); }
|
||||
50% { box-shadow: 0 0 30px var(--color-glow-strong); }
|
||||
}
|
||||
|
||||
@keyframes typing-dot {
|
||||
0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
|
||||
30% { opacity: 1; transform: scale(1); }
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% { background-position: -200% 0; }
|
||||
100% { background-position: 200% 0; }
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
0%, 100% { transform: translateY(0); }
|
||||
50% { transform: translateY(-4px); }
|
||||
}
|
||||
|
||||
* {
|
||||
border-color: var(--color-border);
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
background-color: var(--color-background);
|
||||
color: var(--color-foreground);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
letter-spacing: -0.011em;
|
||||
}
|
||||
|
||||
.animate-fade-in {
|
||||
animation: fade-in 0.4s ease-out both;
|
||||
}
|
||||
|
||||
.animate-slide-in {
|
||||
animation: slide-in-left 0.3s ease-out both;
|
||||
}
|
||||
|
||||
.animate-pulse-glow {
|
||||
animation: pulse-glow 2.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.animate-float {
|
||||
animation: float 3s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.glow-card {
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.glow-card:hover {
|
||||
box-shadow:
|
||||
0 0 0 1px rgba(79, 70, 229, 0.08),
|
||||
0 4px 20px rgba(79, 70, 229, 0.08),
|
||||
0 1px 3px rgba(0, 0, 0, 0.04);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.glass {
|
||||
background: rgba(255, 255, 255, 0.85);
|
||||
backdrop-filter: blur(12px);
|
||||
-webkit-backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.typing-indicator span {
|
||||
display: inline-block;
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-primary);
|
||||
margin: 0 2px;
|
||||
}
|
||||
|
||||
.typing-indicator span:nth-child(1) { animation: typing-dot 1.4s ease-in-out infinite 0s; }
|
||||
.typing-indicator span:nth-child(2) { animation: typing-dot 1.4s ease-in-out infinite 0.2s; }
|
||||
.typing-indicator span:nth-child(3) { animation: typing-dot 1.4s ease-in-out infinite 0.4s; }
|
||||
|
||||
.shimmer {
|
||||
background: linear-gradient(90deg, transparent 0%, rgba(79, 70, 229, 0.04) 50%, transparent 100%);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.prose h1, .prose h2, .prose h3, .prose h4 {
|
||||
color: var(--color-foreground);
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.prose p {
|
||||
line-height: 1.7;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.prose code {
|
||||
background: var(--color-muted);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.875em;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.prose pre {
|
||||
background: #1e293b;
|
||||
color: #e2e8f0;
|
||||
border-radius: 0.75rem;
|
||||
padding: 1rem;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.prose table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 1em 0;
|
||||
font-size: 0.85em;
|
||||
display: table;
|
||||
overflow-x: auto;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.prose thead {
|
||||
background: var(--color-muted);
|
||||
}
|
||||
|
||||
.prose th, .prose td {
|
||||
border: 1px solid var(--color-border);
|
||||
padding: 10px 14px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
line-height: 1.5;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.prose th {
|
||||
font-weight: 600;
|
||||
color: var(--color-foreground);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.prose td code {
|
||||
font-size: 0.82em;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.prose tr:nth-child(even) {
|
||||
background: var(--color-secondary);
|
||||
}
|
||||
|
||||
.prose tr:hover {
|
||||
background: var(--color-accent);
|
||||
}
|
||||
|
||||
@keyframes spin-glow {
|
||||
0% { transform: rotate(0deg); filter: drop-shadow(0 0 3px var(--color-glow)); }
|
||||
50% { filter: drop-shadow(0 0 8px var(--color-glow-strong)); }
|
||||
100% { transform: rotate(360deg); filter: drop-shadow(0 0 3px var(--color-glow)); }
|
||||
}
|
||||
|
||||
.animate-spin-glow {
|
||||
animation: spin-glow 2s linear infinite;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: #cbd5e1;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: #94a3b8;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { type ClassValue, clsx } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
export const API_BASE = "/api";
|
||||
|
||||
export type ApiFetchOptions = RequestInit & {
|
||||
skipAuthRedirect?: boolean;
|
||||
};
|
||||
|
||||
export async function apiFetch<T>(path: string, options?: ApiFetchOptions): Promise<T> {
|
||||
const { skipAuthRedirect, ...init } = options || {};
|
||||
|
||||
const res = await fetch(`${API_BASE}${path}`, {
|
||||
credentials: "include",
|
||||
headers: { "Content-Type": "application/json", ...(init.headers || {}) },
|
||||
...init,
|
||||
});
|
||||
|
||||
if (res.status === 401) {
|
||||
if (
|
||||
typeof window !== "undefined" &&
|
||||
!window.location.pathname.startsWith("/login") &&
|
||||
!skipAuthRedirect
|
||||
) {
|
||||
window.location.assign("/login");
|
||||
}
|
||||
const err = await res.json().catch(() => ({ error: "Network error" }));
|
||||
throw new Error(err.error || `HTTP ${res.status}`);
|
||||
}
|
||||
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({ error: "Network error" }));
|
||||
throw new Error(err.error || `HTTP ${res.status}`);
|
||||
}
|
||||
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export function getGreeting(): string {
|
||||
const hour = new Date().getHours();
|
||||
if (hour < 12) return "Доброе утро";
|
||||
if (hour < 18) return "Добрый день";
|
||||
return "Добрый вечер";
|
||||
}
|
||||
|
||||
export function todayDate(): string {
|
||||
return new Date().toISOString().split("T")[0];
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
@@ -0,0 +1,342 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { Search, HelpCircle, BookOpen, Image as ImageIcon, ChevronDown, Trash2 } from "lucide-react";
|
||||
import { apiFetch } from "@/lib/utils";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import Markdown from "@/components/Markdown";
|
||||
|
||||
type Tab = "questions" | "textbooks" | "hall";
|
||||
|
||||
interface Question {
|
||||
id: number;
|
||||
text: string;
|
||||
answer: string | null;
|
||||
date: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
interface Textbook {
|
||||
id: number;
|
||||
topic: string;
|
||||
content: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
interface HallPhoto {
|
||||
id: number;
|
||||
date: string;
|
||||
imageUrl: string;
|
||||
createdAt: string;
|
||||
fileName: string;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
function groupByDate<T extends { date?: string; createdAt: string }>(
|
||||
items: T[],
|
||||
dateKey: "date" | "createdAt" = "createdAt"
|
||||
): Record<string, T[]> {
|
||||
const groups: Record<string, T[]> = {};
|
||||
for (const item of items) {
|
||||
const d = dateKey === "date" && "date" in item && item.date
|
||||
? item.date
|
||||
: item.createdAt.split("T")[0];
|
||||
if (!groups[d]) groups[d] = [];
|
||||
groups[d].push(item);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
function formatDate(d: string): string {
|
||||
const date = new Date(d);
|
||||
const today = new Date();
|
||||
const yesterday = new Date();
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
|
||||
if (d === today.toISOString().split("T")[0]) return "Сегодня";
|
||||
if (d === yesterday.toISOString().split("T")[0]) return "Вчера";
|
||||
return date.toLocaleDateString("ru", { day: "numeric", month: "long", year: "numeric" });
|
||||
}
|
||||
|
||||
export default function ArchivePage() {
|
||||
const { user } = useAuth();
|
||||
const canDeleteQuestions = user?.role === "STUDENT";
|
||||
const canManageHallPhotos = user?.username?.toLowerCase() === "konstantin";
|
||||
const [tab, setTab] = useState<Tab>("questions");
|
||||
const [search, setSearch] = useState("");
|
||||
const [questions, setQuestions] = useState<Question[]>([]);
|
||||
const [textbooks, setTextbooks] = useState<Textbook[]>([]);
|
||||
const [hall, setHall] = useState<HallPhoto[]>([]);
|
||||
const [expandedTextbook, setExpandedTextbook] = useState<number | null>(null);
|
||||
const [expandedQuestion, setExpandedQuestion] = useState<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
loadAll();
|
||||
}, []);
|
||||
|
||||
async function loadAll() {
|
||||
try { setQuestions(await apiFetch<Question[]>("/questions")); } catch {}
|
||||
try { setTextbooks(await apiFetch<Textbook[]>("/textbooks")); } catch {}
|
||||
try { setHall(await apiFetch<HallPhoto[]>("/reports")); } catch {}
|
||||
}
|
||||
|
||||
async function deleteQuestion(id: number) {
|
||||
if (!canDeleteQuestions || !confirm("Удалить этот вопрос безвозвратно?")) return;
|
||||
try {
|
||||
await apiFetch(`/questions/${id}`, { method: "DELETE" });
|
||||
setQuestions((prev) => prev.filter((q) => q.id !== id));
|
||||
} catch (err: unknown) {
|
||||
alert(err instanceof Error ? err.message : "Ошибка");
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteHallPhoto(id: number) {
|
||||
if (!canManageHallPhotos || !confirm("Удалить это фото?")) return;
|
||||
try {
|
||||
await apiFetch(`/reports/${id}`, { method: "DELETE" });
|
||||
setHall((prev) => prev.filter((h) => h.id !== id));
|
||||
} catch (err: unknown) {
|
||||
alert(err instanceof Error ? err.message : "Ошибка");
|
||||
}
|
||||
}
|
||||
|
||||
const tabs: { key: Tab; label: string; icon: typeof HelpCircle; count: number }[] = [
|
||||
{ key: "questions", label: "Вопросы", icon: HelpCircle, count: questions.length },
|
||||
{ key: "textbooks", label: "Учебники", icon: BookOpen, count: textbooks.length },
|
||||
{ key: "hall", label: "Зал", icon: ImageIcon, count: hall.length },
|
||||
];
|
||||
|
||||
const filteredQuestions = questions.filter(
|
||||
(q) => q.text.toLowerCase().includes(search.toLowerCase()) ||
|
||||
(q.answer && q.answer.toLowerCase().includes(search.toLowerCase()))
|
||||
);
|
||||
|
||||
const filteredTextbooks = textbooks.filter(
|
||||
(t) => t.topic.toLowerCase().includes(search.toLowerCase()) ||
|
||||
t.content.toLowerCase().includes(search.toLowerCase())
|
||||
);
|
||||
|
||||
const filteredHall = hall.filter((r) =>
|
||||
r.date.toLowerCase().includes(search.toLowerCase())
|
||||
);
|
||||
|
||||
const questionGroups = groupByDate(filteredQuestions, "date");
|
||||
const textbookGroups = groupByDate(filteredTextbooks);
|
||||
const hallGroups = groupByDate(filteredHall, "date");
|
||||
|
||||
const sortedDates = (groups: Record<string, unknown[]>) =>
|
||||
Object.keys(groups).sort((a, b) => b.localeCompare(a));
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold tracking-tight">Архив</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">Все материалы, сгруппированные по дням</p>
|
||||
</div>
|
||||
|
||||
{/* Tabs */}
|
||||
<div className="flex gap-1 p-1 bg-muted rounded-xl">
|
||||
{tabs.map(({ key, label, icon: Icon, count }) => (
|
||||
<button
|
||||
key={key}
|
||||
onClick={() => { setTab(key); setSearch(""); }}
|
||||
className={`flex-1 flex items-center justify-center gap-2 py-2 rounded-lg text-xs font-medium transition-all duration-200 cursor-pointer ${
|
||||
tab === key
|
||||
? "bg-background text-foreground shadow-sm"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
>
|
||||
<Icon size={14} />
|
||||
{label}
|
||||
<span className={`text-[10px] px-1.5 py-0.5 rounded-full ${
|
||||
tab === key ? "bg-primary/10 text-primary" : "bg-muted-foreground/10"
|
||||
}`}>
|
||||
{count}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Search */}
|
||||
<div className="relative">
|
||||
<Search size={15} className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
placeholder={`Поиск по ${tab === "questions" ? "вопросам" : tab === "textbooks" ? "учебникам" : "фото"}...`}
|
||||
className="pl-9"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Questions */}
|
||||
{tab === "questions" && (
|
||||
<div className="space-y-5">
|
||||
{sortedDates(questionGroups).map((date) => (
|
||||
<div key={date} className="animate-fade-in">
|
||||
<h3 className="text-xs font-medium text-muted-foreground uppercase tracking-wider mb-2">
|
||||
{formatDate(date)}
|
||||
<span className="ml-2 text-[10px] opacity-60">({questionGroups[date].length})</span>
|
||||
</h3>
|
||||
<div className="space-y-2">
|
||||
{questionGroups[date].map((q) => (
|
||||
<Card key={q.id}>
|
||||
<CardContent className="pt-4 pb-4">
|
||||
<div className="flex items-start gap-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setExpandedQuestion(expandedQuestion === q.id ? null : q.id)}
|
||||
className="flex-1 min-w-0 text-left flex items-start justify-between gap-2 cursor-pointer"
|
||||
>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium">{q.text}</p>
|
||||
{q.answer && expandedQuestion !== q.id && (
|
||||
<p className="text-xs text-muted-foreground mt-1 line-clamp-1">{q.answer.slice(0, 100)}...</p>
|
||||
)}
|
||||
</div>
|
||||
{q.answer && (
|
||||
<ChevronDown
|
||||
size={15}
|
||||
className={`text-muted-foreground shrink-0 mt-0.5 transition-transform duration-200 ${
|
||||
expandedQuestion === q.id ? "rotate-180" : ""
|
||||
}`}
|
||||
/>
|
||||
)}
|
||||
</button>
|
||||
{canDeleteQuestions && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 shrink-0 text-destructive"
|
||||
title="Удалить вопрос"
|
||||
type="button"
|
||||
onClick={() => deleteQuestion(q.id)}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{expandedQuestion === q.id && q.answer && (
|
||||
<div className="mt-3 pt-3 border-t animate-fade-in">
|
||||
<Markdown className="text-[13px]">{q.answer}</Markdown>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{filteredQuestions.length === 0 && (
|
||||
<p className="text-center text-sm text-muted-foreground py-12">
|
||||
{search ? "Ничего не найдено" : "Нет вопросов"}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Textbooks */}
|
||||
{tab === "textbooks" && (
|
||||
<div className="space-y-5">
|
||||
{sortedDates(textbookGroups).map((date) => (
|
||||
<div key={date} className="animate-fade-in">
|
||||
<h3 className="text-xs font-medium text-muted-foreground uppercase tracking-wider mb-2">
|
||||
{formatDate(date)}
|
||||
</h3>
|
||||
<div className="space-y-2">
|
||||
{textbookGroups[date].map((tb) => (
|
||||
<Card key={tb.id}>
|
||||
<CardContent className="pt-4 pb-4">
|
||||
<button
|
||||
onClick={() => setExpandedTextbook(expandedTextbook === tb.id ? null : tb.id)}
|
||||
className="w-full text-left flex items-center justify-between cursor-pointer"
|
||||
>
|
||||
<span className="text-sm font-medium">{tb.topic}</span>
|
||||
<ChevronDown
|
||||
size={15}
|
||||
className={`text-muted-foreground shrink-0 transition-transform duration-200 ${
|
||||
expandedTextbook === tb.id ? "rotate-180" : ""
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
{expandedTextbook === tb.id && (
|
||||
<div className="mt-3 pt-3 border-t animate-fade-in">
|
||||
<Markdown className="text-[13px]">{tb.content}</Markdown>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{filteredTextbooks.length === 0 && (
|
||||
<p className="text-center text-sm text-muted-foreground py-12">
|
||||
{search ? "Ничего не найдено" : "Нет учебников"}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Hall */}
|
||||
{tab === "hall" && (
|
||||
<div className="space-y-5">
|
||||
{sortedDates(hallGroups).map((date) => (
|
||||
<div key={date} className="animate-fade-in">
|
||||
<h3 className="text-xs font-medium text-muted-foreground uppercase tracking-wider mb-2">
|
||||
{formatDate(date)}
|
||||
</h3>
|
||||
<div className="grid grid-cols-2 md:grid-cols-3 gap-3">
|
||||
{hallGroups[date].map((r) => {
|
||||
const label = r.displayName || r.fileName;
|
||||
return (
|
||||
<div
|
||||
key={r.id}
|
||||
className="relative flex flex-col rounded-xl overflow-hidden border bg-accent/20 hover:shadow-sm transition"
|
||||
>
|
||||
<div className="relative">
|
||||
<button
|
||||
type="button"
|
||||
className="block w-full"
|
||||
onClick={() => window.open(r.imageUrl, "_blank", "noopener,noreferrer")}
|
||||
>
|
||||
<img src={r.imageUrl} alt={label} className="w-full h-36 object-cover" />
|
||||
</button>
|
||||
{canManageHallPhotos && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="destructive"
|
||||
size="icon"
|
||||
className="absolute top-2 right-2 h-8 w-8 opacity-90 shadow-md"
|
||||
title="Удалить"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
deleteHallPhoto(r.id);
|
||||
}}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<p
|
||||
className="text-[11px] px-2 py-1.5 text-muted-foreground truncate border-t bg-background/95"
|
||||
title={label}
|
||||
>
|
||||
{label}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{filteredHall.length === 0 && (
|
||||
<p className="text-center text-sm text-muted-foreground py-12">
|
||||
{search ? "Ничего не найдено" : "Нет фото"}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { Send, Trash2, Sparkles } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { getGreeting, apiFetch, API_BASE } from "@/lib/utils";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import Markdown from "@/components/Markdown";
|
||||
|
||||
interface ChatMsg {
|
||||
id?: number;
|
||||
role: "user" | "assistant";
|
||||
content: string;
|
||||
}
|
||||
|
||||
export default function HomePage() {
|
||||
const { user } = useAuth();
|
||||
const [messages, setMessages] = useState<ChatMsg[]>([]);
|
||||
const [input, setInput] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const bottomRef = useRef<HTMLDivElement>(null);
|
||||
const inputRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
apiFetch<ChatMsg[]>("/chat/history").then(setMessages).catch(() => {});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||
}, [messages]);
|
||||
|
||||
function autoResize() {
|
||||
const el = inputRef.current;
|
||||
if (el) {
|
||||
el.style.height = "auto";
|
||||
el.style.height = Math.min(el.scrollHeight, 150) + "px";
|
||||
}
|
||||
}
|
||||
|
||||
async function sendMessage() {
|
||||
if (!input.trim() || loading) return;
|
||||
const text = input.trim();
|
||||
setInput("");
|
||||
if (inputRef.current) inputRef.current.style.height = "auto";
|
||||
setMessages((prev) => [...prev, { role: "user", content: text }]);
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/chat`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ message: text }),
|
||||
});
|
||||
|
||||
const reader = res.body?.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let assistantContent = "";
|
||||
setMessages((prev) => [...prev, { role: "assistant", content: "" }]);
|
||||
|
||||
while (reader) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
const chunk = decoder.decode(value);
|
||||
const lines = chunk.split("\n").filter((l) => l.startsWith("data: "));
|
||||
|
||||
for (const line of lines) {
|
||||
const data = line.slice(6);
|
||||
if (data === "[DONE]") break;
|
||||
try {
|
||||
const parsed = JSON.parse(data);
|
||||
if (parsed.content) {
|
||||
assistantContent += parsed.content;
|
||||
setMessages((prev) => {
|
||||
const updated = [...prev];
|
||||
updated[updated.length - 1] = { role: "assistant", content: assistantContent };
|
||||
return updated;
|
||||
});
|
||||
}
|
||||
} catch { /* skip */ }
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
setMessages((prev) => [
|
||||
...prev,
|
||||
{ role: "assistant", content: `Ошибка: ${err.message}` },
|
||||
]);
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
async function clearHistory() {
|
||||
await apiFetch("/chat/history", { method: "DELETE" });
|
||||
setMessages([]);
|
||||
}
|
||||
|
||||
function handleKeyDown(e: React.KeyboardEvent) {
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
sendMessage();
|
||||
}
|
||||
}
|
||||
|
||||
const isEmpty = messages.length === 0;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-[calc(100vh-3rem)]">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold tracking-tight">
|
||||
{getGreeting()}
|
||||
{user?.displayName ? `, ${user.displayName}` : user?.username ? `, ${user.username}` : ""}
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground mt-0.5">
|
||||
Чем могу помочь сегодня?
|
||||
</p>
|
||||
</div>
|
||||
{!isEmpty && (
|
||||
<Button variant="ghost" size="sm" onClick={clearHistory} className="text-muted-foreground">
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Messages */}
|
||||
<div className="flex-1 overflow-y-auto py-4 space-y-5">
|
||||
{isEmpty && (
|
||||
<div className="flex flex-col items-center justify-center h-full text-center animate-fade-in">
|
||||
<div className="w-14 h-14 rounded-2xl bg-accent flex items-center justify-center mb-5 animate-float">
|
||||
<Sparkles size={26} className="text-primary" />
|
||||
</div>
|
||||
<h2 className="text-lg font-semibold mb-2">ИИ-ассистент</h2>
|
||||
<p className="text-sm text-muted-foreground max-w-sm leading-relaxed">
|
||||
Задайте любой вопрос — я постараюсь объяснить максимально понятно
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{messages.map((msg, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="animate-fade-in"
|
||||
style={{ animationDelay: `${Math.min(i * 30, 200)}ms` }}
|
||||
>
|
||||
{msg.role === "user" ? (
|
||||
<div className="flex justify-end">
|
||||
<div className="max-w-[75%] bg-primary text-primary-foreground rounded-2xl rounded-br-md px-4 py-2.5 text-[14px] leading-relaxed shadow-sm">
|
||||
{msg.content}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex gap-3">
|
||||
<div className={`w-7 h-7 rounded-lg bg-accent flex items-center justify-center shrink-0 mt-0.5 ${
|
||||
loading && i === messages.length - 1 ? "" : ""
|
||||
}`}>
|
||||
<Sparkles
|
||||
size={14}
|
||||
className={`text-primary ${loading && i === messages.length - 1 ? "animate-spin-glow" : ""}`}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
{msg.content ? (
|
||||
<Markdown>{msg.content}</Markdown>
|
||||
) : (
|
||||
<div className="typing-indicator flex items-center gap-1 py-3">
|
||||
<span /><span /><span />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<div ref={bottomRef} />
|
||||
</div>
|
||||
|
||||
{/* Input */}
|
||||
<div className="pt-3 pb-1">
|
||||
<div className="relative flex items-end gap-2 rounded-2xl border bg-background p-2 shadow-sm transition-shadow focus-within:shadow-md focus-within:shadow-primary/5 focus-within:border-primary/30">
|
||||
<textarea
|
||||
ref={inputRef}
|
||||
value={input}
|
||||
onChange={(e) => { setInput(e.target.value); autoResize(); }}
|
||||
onKeyDown={handleKeyDown}
|
||||
placeholder="Напишите сообщение..."
|
||||
disabled={loading}
|
||||
rows={1}
|
||||
className="flex-1 resize-none bg-transparent px-2 py-1.5 text-sm outline-none placeholder:text-muted-foreground disabled:opacity-50 max-h-[150px]"
|
||||
/>
|
||||
<Button
|
||||
onClick={sendMessage}
|
||||
disabled={loading || !input.trim()}
|
||||
size="icon"
|
||||
className="shrink-0 h-8 w-8 rounded-xl"
|
||||
>
|
||||
<Send size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Loader2, Sparkles } from "lucide-react";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import { API_BASE } from "@/lib/utils";
|
||||
|
||||
export default function LoginPage() {
|
||||
const navigate = useNavigate();
|
||||
const { user, loading, setUser } = useAuth();
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading && user) navigate("/", { replace: true });
|
||||
}, [loading, user, navigate]);
|
||||
|
||||
async function onSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setError("");
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/auth/login`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ username: username.trim(), password }),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
setError(data.error || `Ошибка ${res.status}`);
|
||||
return;
|
||||
}
|
||||
setUser(data.user);
|
||||
navigate("/", { replace: true });
|
||||
} catch {
|
||||
setError("Сеть недоступна");
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-background">
|
||||
<Loader2 className="animate-spin text-primary" size={28} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-background p-4">
|
||||
<Card className="w-full max-w-md border-border/80 shadow-lg">
|
||||
<CardHeader className="text-center space-y-2">
|
||||
<div className="mx-auto w-10 h-10 rounded-xl bg-primary flex items-center justify-center">
|
||||
<Sparkles size={20} className="text-white" />
|
||||
</div>
|
||||
<CardTitle className="text-lg">EduHelper</CardTitle>
|
||||
<p className="text-sm text-muted-foreground">Войдите, чтобы продолжить</p>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={onSubmit} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="username">Имя пользователя</Label>
|
||||
<Input
|
||||
id="username"
|
||||
autoComplete="username"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
disabled={submitting}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="password">Пароль</Label>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
disabled={submitting}
|
||||
/>
|
||||
</div>
|
||||
{error && <p className="text-sm text-destructive">{error}</p>}
|
||||
<Button type="submit" className="w-full" disabled={submitting || !username.trim() || !password}>
|
||||
{submitting ? <Loader2 size={16} className="animate-spin" /> : "Войти"}
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { Loader2, Sparkles, Plus, Send, Search, Trash2 } from "lucide-react";
|
||||
import { apiFetch, todayDate, API_BASE } from "@/lib/utils";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import Markdown from "@/components/Markdown";
|
||||
|
||||
interface Question {
|
||||
id: number;
|
||||
text: string;
|
||||
answer: string | null;
|
||||
date: string;
|
||||
}
|
||||
|
||||
export default function QuestionsPage() {
|
||||
const { user } = useAuth();
|
||||
const canDeleteOwn = user?.role === "STUDENT";
|
||||
const [fields, setFields] = useState<string[]>([]);
|
||||
const [saved, setSaved] = useState<Question[]>([]);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [answeringId, setAnsweringId] = useState<number | null>(null);
|
||||
const [search, setSearch] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
loadQuestions();
|
||||
}, []);
|
||||
|
||||
async function loadQuestions() {
|
||||
try {
|
||||
const data = await apiFetch<Question[]>(`/questions?date=${todayDate()}`);
|
||||
setSaved(data);
|
||||
updateFieldCount(data.length);
|
||||
} catch {
|
||||
updateFieldCount(0);
|
||||
}
|
||||
}
|
||||
|
||||
function updateFieldCount(savedCount: number) {
|
||||
const needed = Math.max(1, 5 - savedCount);
|
||||
setFields(Array(needed).fill(""));
|
||||
}
|
||||
|
||||
function updateField(index: number, value: string) {
|
||||
setFields((prev) => { const c = [...prev]; c[index] = value; return c; });
|
||||
}
|
||||
|
||||
async function saveQuestions() {
|
||||
const nonEmpty = fields.filter((f) => f.trim());
|
||||
if (nonEmpty.length === 0) return;
|
||||
|
||||
setSaving(true);
|
||||
try {
|
||||
const data = await apiFetch<Question[]>("/questions", {
|
||||
method: "POST", body: JSON.stringify({ questions: nonEmpty }),
|
||||
});
|
||||
const newSaved = [...saved, ...data];
|
||||
setSaved(newSaved);
|
||||
updateFieldCount(newSaved.length);
|
||||
} catch (err: any) { alert(err.message); }
|
||||
setSaving(false);
|
||||
}
|
||||
|
||||
async function getAnswer(question: Question) {
|
||||
if (question.answer || answeringId === question.id) return;
|
||||
setAnsweringId(question.id);
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/questions/${question.id}/answer`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
});
|
||||
const reader = res.body?.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let fullAnswer = "";
|
||||
|
||||
while (reader) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
for (const line of decoder.decode(value).split("\n").filter((l) => l.startsWith("data: "))) {
|
||||
const data = line.slice(6);
|
||||
if (data === "[DONE]") break;
|
||||
try {
|
||||
const parsed = JSON.parse(data);
|
||||
if (parsed.content) {
|
||||
fullAnswer += parsed.content;
|
||||
setSaved((prev) => prev.map((q) => q.id === question.id ? { ...q, answer: fullAnswer } : q));
|
||||
}
|
||||
} catch { /* skip */ }
|
||||
}
|
||||
}
|
||||
} catch (err: any) { alert(err.message); }
|
||||
setAnsweringId(null);
|
||||
}
|
||||
|
||||
async function deleteQuestion(id: number) {
|
||||
if (!canDeleteOwn || !confirm("Удалить этот вопрос безвозвратно?")) return;
|
||||
try {
|
||||
await apiFetch(`/questions/${id}`, { method: "DELETE" });
|
||||
const next = saved.filter((q) => q.id !== id);
|
||||
setSaved(next);
|
||||
updateFieldCount(next.length);
|
||||
} catch (err: any) {
|
||||
alert(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
const unanswered = saved.filter((q) =>
|
||||
!q.answer && (!search || q.text.toLowerCase().includes(search.toLowerCase()))
|
||||
);
|
||||
const answered = saved.filter((q) =>
|
||||
q.answer && (!search || q.text.toLowerCase().includes(search.toLowerCase()) || q.answer.toLowerCase().includes(search.toLowerCase()))
|
||||
);
|
||||
const todaySavedCount = saved.length;
|
||||
const remaining = Math.max(0, 5 - todaySavedCount);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold tracking-tight">Ежедневные вопросы</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
{remaining > 0
|
||||
? `Ещё ${remaining} из 5 обязательных вопросов`
|
||||
: `Норма выполнена (${todaySavedCount} вопросов)`}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* New questions form */}
|
||||
<Card>
|
||||
<CardContent className="pt-5 space-y-3">
|
||||
{fields.map((val, i) => (
|
||||
<div key={i} className="animate-fade-in" style={{ animationDelay: `${i * 50}ms` }}>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs font-medium text-muted-foreground w-4 text-right shrink-0">
|
||||
{todaySavedCount + i + 1}
|
||||
</span>
|
||||
<Input
|
||||
value={val}
|
||||
onChange={(e) => updateField(i, e.target.value)}
|
||||
placeholder={`Вопрос...`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div className="flex gap-2 pt-2 ml-6">
|
||||
<Button variant="outline" size="sm" onClick={() => setFields((p) => [...p, ""])}>
|
||||
<Plus size={14} />
|
||||
Ещё
|
||||
</Button>
|
||||
<Button size="sm" onClick={saveQuestions} disabled={saving || fields.every((f) => !f.trim())}>
|
||||
{saving ? <Loader2 size={14} className="animate-spin" /> : <Send size={14} />}
|
||||
Сохранить
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Search */}
|
||||
{saved.length > 0 && (
|
||||
<div className="relative">
|
||||
<Search size={15} className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
placeholder="Поиск по вопросам..."
|
||||
className="pl-9"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Unanswered first */}
|
||||
{unanswered.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h2 className="text-xs font-medium text-muted-foreground uppercase tracking-wider">
|
||||
Ожидают ответа ({unanswered.length})
|
||||
</h2>
|
||||
{unanswered.map((q, i) => (
|
||||
<Card key={q.id} className="animate-fade-in border-orange-200/60" style={{ animationDelay: `${i * 40}ms` }}>
|
||||
<CardContent className="pt-5 space-y-3">
|
||||
<p className="text-[14px] font-medium">{q.text}</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => getAnswer(q)}
|
||||
disabled={answeringId === q.id}
|
||||
>
|
||||
{answeringId === q.id ? (
|
||||
<>
|
||||
<Sparkles size={13} className="animate-spin-glow" />
|
||||
Генерация...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Sparkles size={13} />
|
||||
Получить ответ
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
{canDeleteOwn && (
|
||||
<Button variant="ghost" size="sm" className="text-destructive" onClick={() => deleteQuestion(q.id)}>
|
||||
<Trash2 size={13} />
|
||||
Удалить
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Answered below */}
|
||||
{answered.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h2 className="text-xs font-medium text-muted-foreground uppercase tracking-wider">
|
||||
С ответами ({answered.length})
|
||||
</h2>
|
||||
{answered.map((q, i) => (
|
||||
<Card key={q.id} className="animate-fade-in" style={{ animationDelay: `${i * 40}ms` }}>
|
||||
<CardContent className="pt-5 space-y-3">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<p className="text-[14px] font-medium flex-1">{q.text}</p>
|
||||
{canDeleteOwn && (
|
||||
<Button variant="ghost" size="icon" className="shrink-0 text-destructive h-8 w-8" onClick={() => deleteQuestion(q.id)} title="Удалить вопрос">
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<div className="bg-accent/50 rounded-xl p-4">
|
||||
<Markdown className="text-[13px]" exportable exportTitle={`question-${q.id}`}>{q.answer!}</Markdown>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { API_BASE, apiFetch, todayDate } from "@/lib/utils";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import { Calendar, ImagePlus, Loader2, Trash2 } from "lucide-react";
|
||||
|
||||
interface HallPhoto {
|
||||
id: number;
|
||||
date: string;
|
||||
createdAt: string;
|
||||
imageUrl: string;
|
||||
fileName: string;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
export default function ReportPage() {
|
||||
const { user } = useAuth();
|
||||
const canManagePhotos =
|
||||
user?.username?.toLowerCase() === "konstantin";
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const [photos, setPhotos] = useState<HallPhoto[]>([]);
|
||||
const [selectedDate, setSelectedDate] = useState(todayDate());
|
||||
const [uploading, setUploading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
loadPhotos();
|
||||
}, []);
|
||||
|
||||
async function loadPhotos() {
|
||||
try {
|
||||
setPhotos(await apiFetch<HallPhoto[]>("/reports"));
|
||||
} catch {
|
||||
setPhotos([]);
|
||||
}
|
||||
}
|
||||
|
||||
async function onFileChange(e: React.ChangeEvent<HTMLInputElement>) {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
const formData = new FormData();
|
||||
formData.append("photo", file);
|
||||
formData.append("date", selectedDate);
|
||||
|
||||
setUploading(true);
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/reports/upload`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: formData,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({ error: "Ошибка загрузки" }));
|
||||
throw new Error(err.error || `HTTP ${res.status}`);
|
||||
}
|
||||
await loadPhotos();
|
||||
} catch (err: any) {
|
||||
alert(err.message);
|
||||
} finally {
|
||||
setUploading(false);
|
||||
e.target.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
async function deletePhoto(id: number) {
|
||||
if (!confirm("Удалить это фото?")) return;
|
||||
try {
|
||||
await apiFetch(`/reports/${id}`, { method: "DELETE" });
|
||||
await loadPhotos();
|
||||
} catch (err: unknown) {
|
||||
alert(err instanceof Error ? err.message : "Ошибка");
|
||||
}
|
||||
}
|
||||
|
||||
const grouped = useMemo(() => {
|
||||
const g: Record<string, HallPhoto[]> = {};
|
||||
for (const p of photos) {
|
||||
if (!g[p.date]) g[p.date] = [];
|
||||
g[p.date].push(p);
|
||||
}
|
||||
return g;
|
||||
}, [photos]);
|
||||
|
||||
const sortedDates = Object.keys(grouped).sort((a, b) => b.localeCompare(a));
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between gap-2 flex-wrap">
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold tracking-tight">Зал</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
{canManagePhotos
|
||||
? "Загружайте фото и просматривайте их по датам"
|
||||
: "Просмотр фото ученика по датам"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{canManagePhotos && (
|
||||
<Card>
|
||||
<CardContent className="pt-5 flex flex-wrap items-end gap-3">
|
||||
<div className="space-y-1">
|
||||
<label className="text-xs text-muted-foreground">Дата</label>
|
||||
<Input type="date" value={selectedDate} onChange={(e) => setSelectedDate(e.target.value)} />
|
||||
</div>
|
||||
<div className="flex flex-col justify-end gap-0">
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onChange={onFileChange}
|
||||
disabled={uploading}
|
||||
className="sr-only"
|
||||
tabIndex={-1}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={uploading}
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
>
|
||||
{uploading ? <Loader2 size={15} className="animate-spin" /> : <ImagePlus size={15} />}
|
||||
Прикрепить фото
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{sortedDates.map((date) => (
|
||||
<div key={date} className="space-y-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Calendar size={14} className="text-muted-foreground" />
|
||||
<h2 className="text-sm font-medium">{date}</h2>
|
||||
<span className="text-xs text-muted-foreground">({grouped[date].length})</span>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 md:grid-cols-3 gap-3">
|
||||
{grouped[date].map((p) => {
|
||||
const label = p.displayName || p.fileName;
|
||||
return (
|
||||
<div
|
||||
key={p.id}
|
||||
className="relative group flex flex-col rounded-xl overflow-hidden border bg-accent/20 hover:shadow-sm transition"
|
||||
>
|
||||
<div className="relative">
|
||||
<button
|
||||
type="button"
|
||||
className="block w-full text-left"
|
||||
onClick={() => window.open(p.imageUrl, "_blank", "noopener,noreferrer")}
|
||||
>
|
||||
<img
|
||||
src={p.imageUrl}
|
||||
alt={label}
|
||||
loading="lazy"
|
||||
className="w-full h-40 object-cover group-hover:scale-[1.02] transition"
|
||||
/>
|
||||
</button>
|
||||
{canManagePhotos && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="destructive"
|
||||
size="icon"
|
||||
className="absolute top-2 right-2 h-8 w-8 opacity-90 shadow-md"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
deletePhoto(p.id);
|
||||
}}
|
||||
title="Удалить"
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<p
|
||||
className="text-[11px] px-2 py-1.5 text-muted-foreground truncate border-t bg-background/95"
|
||||
title={label}
|
||||
>
|
||||
{label}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{photos.length === 0 && (
|
||||
<div className="text-center py-12 text-sm text-muted-foreground">
|
||||
{canManagePhotos
|
||||
? "Пока нет фото. Добавьте первое изображение."
|
||||
: "Пока нет фото."}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Save, Loader2, CheckCircle2, Key, MessageSquare } from "lucide-react";
|
||||
import { apiFetch } from "@/lib/utils";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import { Navigate } from "react-router-dom";
|
||||
|
||||
const PROMPT_FIELDS = [
|
||||
{
|
||||
key: "prompt_answer",
|
||||
label: "Промпт для ответов на вопросы",
|
||||
description: "Используется при нажатии «Получить ответ» в разделе вопросов",
|
||||
placeholder:
|
||||
"Ты — помощник-репетитор. Ответь на вопрос ученика максимально подробно и понятно...",
|
||||
},
|
||||
{
|
||||
key: "prompt_textbook",
|
||||
label: "Промпт для генерации учебника",
|
||||
description: "Используется при генерации учебника по теме",
|
||||
placeholder:
|
||||
"Составь учебный материал по указанной теме. Объясняй просто, с примерами из жизни...",
|
||||
},
|
||||
{
|
||||
key: "prompt_test",
|
||||
label: "Промпт для генерации теста",
|
||||
description: "Используется при создании теста из 10 вопросов",
|
||||
placeholder:
|
||||
"Сгенерируй тест из 10 вопросов с 4 вариантами ответа. Верни JSON-массив...",
|
||||
},
|
||||
{
|
||||
key: "prompt_report",
|
||||
label: "Промпт для ежедневного отчёта",
|
||||
description: "Используется при генерации отчёта за день",
|
||||
placeholder:
|
||||
'Составь отчёт в формате: "Алексей Михайлович, добрый вечер, за сегодня я узнал..."',
|
||||
},
|
||||
];
|
||||
|
||||
export default function SettingsPage() {
|
||||
const { user } = useAuth();
|
||||
if (user?.role !== "TUTOR") {
|
||||
return <Navigate to="/" replace />;
|
||||
}
|
||||
|
||||
const [apiKey, setApiKey] = useState("");
|
||||
const [prompts, setPrompts] = useState<Record<string, string>>({});
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [saved, setSaved] = useState(false);
|
||||
|
||||
useEffect(() => { loadSettings(); }, []);
|
||||
|
||||
async function loadSettings() {
|
||||
try {
|
||||
const data = await apiFetch<Record<string, string>>("/settings/raw");
|
||||
setApiKey(data.deepseek_api_key || "");
|
||||
const p: Record<string, string> = {};
|
||||
for (const f of PROMPT_FIELDS) p[f.key] = data[f.key] || "";
|
||||
setPrompts(p);
|
||||
} catch { /* first time */ }
|
||||
}
|
||||
|
||||
async function saveSettings() {
|
||||
setSaving(true);
|
||||
setSaved(false);
|
||||
const settings: Record<string, string> = { deepseek_api_key: apiKey };
|
||||
for (const [k, v] of Object.entries(prompts)) {
|
||||
if (v.trim()) settings[k] = v.trim();
|
||||
}
|
||||
try {
|
||||
await apiFetch("/settings", { method: "PUT", body: JSON.stringify(settings) });
|
||||
setSaved(true);
|
||||
setTimeout(() => setSaved(false), 3000);
|
||||
} catch (err: any) { alert(err.message); }
|
||||
setSaving(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold tracking-tight">Настройки</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">API-ключ и промпты для ИИ-ассистента</p>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<Key size={15} className="text-primary" />
|
||||
API-ключ DeepSeek
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2">
|
||||
<Input
|
||||
type="password"
|
||||
value={apiKey}
|
||||
onChange={(e) => setApiKey(e.target.value)}
|
||||
placeholder="sk-..."
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Получите на{" "}
|
||||
<a href="https://platform.deepseek.com" target="_blank" className="text-primary hover:underline">
|
||||
platform.deepseek.com
|
||||
</a>
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<MessageSquare size={15} className="text-primary" />
|
||||
Промпты
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-5">
|
||||
{PROMPT_FIELDS.map((field) => (
|
||||
<div key={field.key} className="space-y-1.5">
|
||||
<Label htmlFor={field.key} className="text-[13px]">{field.label}</Label>
|
||||
<p className="text-xs text-muted-foreground">{field.description}</p>
|
||||
<Textarea
|
||||
id={field.key}
|
||||
value={prompts[field.key] || ""}
|
||||
onChange={(e) => setPrompts((p) => ({ ...p, [field.key]: e.target.value }))}
|
||||
placeholder={field.placeholder}
|
||||
className="min-h-[90px] text-[13px]"
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Button onClick={saveSettings} disabled={saving} className="w-full">
|
||||
{saving ? (
|
||||
<Loader2 size={15} className="animate-spin" />
|
||||
) : saved ? (
|
||||
<CheckCircle2 size={15} />
|
||||
) : (
|
||||
<Save size={15} />
|
||||
)}
|
||||
{saved ? "Сохранено" : "Сохранить настройки"}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { Loader2, ClipboardList, CheckCircle2, XCircle, RotateCcw, MessageSquare } from "lucide-react";
|
||||
import { apiFetch } from "@/lib/utils";
|
||||
|
||||
interface TestQuestion {
|
||||
question: string;
|
||||
options: Record<string, string>;
|
||||
correct: string;
|
||||
}
|
||||
|
||||
interface Test {
|
||||
id: number;
|
||||
topic: string;
|
||||
questions: string;
|
||||
createdAt: string;
|
||||
results: TestResult[];
|
||||
}
|
||||
|
||||
interface TestResult {
|
||||
id?: number;
|
||||
score: number;
|
||||
total: number;
|
||||
/** false для наставника — результат не сохраняется в БД */
|
||||
persisted?: boolean;
|
||||
}
|
||||
|
||||
type Phase = "setup" | "generating" | "taking" | "results";
|
||||
|
||||
export default function TestPage() {
|
||||
const [phase, setPhase] = useState<Phase>("setup");
|
||||
const [topic, setTopic] = useState("");
|
||||
const [fromQuestions, setFromQuestions] = useState(false);
|
||||
const [testId, setTestId] = useState<number | null>(null);
|
||||
const [questions, setQuestions] = useState<TestQuestion[]>([]);
|
||||
const [answers, setAnswers] = useState<Record<string, string>>({});
|
||||
const [result, setResult] = useState<TestResult | null>(null);
|
||||
const [tests, setTests] = useState<Test[]>([]);
|
||||
const [currentQ, setCurrentQ] = useState(0);
|
||||
|
||||
useEffect(() => { loadTests(); }, []);
|
||||
|
||||
async function loadTests() {
|
||||
try { setTests(await apiFetch<Test[]>("/tests")); } catch { /* empty */ }
|
||||
}
|
||||
|
||||
async function generateTest() {
|
||||
setPhase("generating");
|
||||
try {
|
||||
const body: Record<string, unknown> = fromQuestions
|
||||
? { fromQuestions: true }
|
||||
: { topic: topic.trim() };
|
||||
|
||||
if (!fromQuestions && !topic.trim()) {
|
||||
alert("Введите тему");
|
||||
setPhase("setup");
|
||||
return;
|
||||
}
|
||||
|
||||
const test = await apiFetch<Test>("/tests/generate", {
|
||||
method: "POST", body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
setTestId(test.id);
|
||||
setQuestions(JSON.parse(test.questions));
|
||||
setAnswers({});
|
||||
setCurrentQ(0);
|
||||
setPhase("taking");
|
||||
} catch (err: any) { alert(err.message); setPhase("setup"); }
|
||||
}
|
||||
|
||||
async function submitTest() {
|
||||
if (!testId) return;
|
||||
try {
|
||||
const res = await apiFetch<TestResult>(`/tests/${testId}/submit`, {
|
||||
method: "POST", body: JSON.stringify({ answers }),
|
||||
});
|
||||
setResult(res);
|
||||
setPhase("results");
|
||||
loadTests();
|
||||
} catch (err: any) { alert(err.message); }
|
||||
}
|
||||
|
||||
function reset() {
|
||||
setPhase("setup");
|
||||
setTopic("");
|
||||
setFromQuestions(false);
|
||||
setQuestions([]);
|
||||
setAnswers({});
|
||||
setResult(null);
|
||||
setTestId(null);
|
||||
setCurrentQ(0);
|
||||
}
|
||||
|
||||
function retakeTest(test: Test) {
|
||||
setTestId(test.id);
|
||||
setQuestions(JSON.parse(test.questions));
|
||||
setAnswers({});
|
||||
setCurrentQ(0);
|
||||
setResult(null);
|
||||
setPhase("taking");
|
||||
}
|
||||
|
||||
if (phase === "generating") {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center py-24 gap-4 animate-fade-in">
|
||||
<div className="w-12 h-12 rounded-2xl bg-accent flex items-center justify-center animate-pulse-glow">
|
||||
<Loader2 size={22} className="animate-spin text-primary" />
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">Генерируем тест из 10 вопросов...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (phase === "taking") {
|
||||
const q = questions[currentQ];
|
||||
const progress = Object.keys(answers).length;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold tracking-tight">
|
||||
Вопрос {currentQ + 1} из {questions.length}
|
||||
</h1>
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Отвечено: {progress}/{questions.length}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="w-full bg-muted rounded-full h-1.5 overflow-hidden">
|
||||
<div
|
||||
className="bg-primary h-full rounded-full transition-all duration-500 ease-out"
|
||||
style={{ width: `${(progress / questions.length) * 100}%` }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Card className="animate-fade-in" key={currentQ}>
|
||||
<CardContent className="pt-5 space-y-4">
|
||||
<p className="text-[15px] font-medium leading-relaxed">{q.question}</p>
|
||||
<div className="space-y-2">
|
||||
{Object.entries(q.options).map(([key, text]) => (
|
||||
<button
|
||||
key={key}
|
||||
onClick={() => setAnswers((p) => ({ ...p, [q.question]: key }))}
|
||||
className={`w-full text-left p-3.5 rounded-xl border transition-all duration-200 cursor-pointer text-sm ${
|
||||
answers[q.question] === key
|
||||
? "bg-primary text-primary-foreground border-primary shadow-sm shadow-primary/20"
|
||||
: "hover:bg-secondary/80 hover:border-primary/20"
|
||||
}`}
|
||||
>
|
||||
<span className="font-medium mr-2 opacity-60">{key.toUpperCase()}</span>
|
||||
{text}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div className="flex justify-between">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setCurrentQ((c) => Math.max(0, c - 1))}
|
||||
disabled={currentQ === 0}
|
||||
>
|
||||
Назад
|
||||
</Button>
|
||||
<div className="flex gap-2">
|
||||
{currentQ < questions.length - 1 ? (
|
||||
<Button onClick={() => setCurrentQ((c) => c + 1)}>
|
||||
Далее
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
onClick={submitTest}
|
||||
disabled={progress < questions.length}
|
||||
>
|
||||
Завершить тест
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (phase === "results" && result) {
|
||||
const pct = Math.round((result.score / result.total) * 100);
|
||||
const isGood = pct >= 70;
|
||||
|
||||
return (
|
||||
<div className="space-y-6 animate-fade-in">
|
||||
<Card className={isGood ? "border-green-200" : "border-orange-200"}>
|
||||
<CardContent className="pt-6 text-center space-y-4">
|
||||
<div className={`text-5xl font-bold ${isGood ? "text-green-600" : "text-orange-500"}`}>
|
||||
{result.score}/{result.total}
|
||||
</div>
|
||||
<p className="text-muted-foreground">
|
||||
{pct >= 90 ? "Превосходно!" : pct >= 70 ? "Хороший результат" : pct >= 50 ? "Неплохо, но стоит повторить" : "Нужно подтянуть материал"}
|
||||
</p>
|
||||
<div className="w-full bg-muted rounded-full h-2 overflow-hidden max-w-xs mx-auto">
|
||||
<div
|
||||
className={`h-full rounded-full transition-all duration-1000 ease-out ${isGood ? "bg-green-500" : "bg-orange-400"}`}
|
||||
style={{ width: `${pct}%` }}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div className="space-y-2">
|
||||
{questions.map((q, i) => {
|
||||
const userAnswer = answers[q.question];
|
||||
const isCorrect = userAnswer === q.correct;
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
className={`flex items-start gap-3 p-3.5 rounded-xl border text-sm animate-fade-in ${
|
||||
isCorrect ? "border-green-200 bg-green-50/50" : "border-red-200 bg-red-50/50"
|
||||
}`}
|
||||
style={{ animationDelay: `${i * 50}ms` }}
|
||||
>
|
||||
{isCorrect
|
||||
? <CheckCircle2 size={17} className="text-green-600 mt-0.5 shrink-0" />
|
||||
: <XCircle size={17} className="text-red-500 mt-0.5 shrink-0" />}
|
||||
<div>
|
||||
<p className="font-medium">{q.question}</p>
|
||||
{!isCorrect && (
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Правильно: {q.correct}) {q.options[q.correct]}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<Button onClick={reset} variant="outline" className="w-full">
|
||||
<RotateCcw size={15} />
|
||||
Новый тест
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold tracking-tight">Тестирование</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">Проверьте знания — 10 вопросов с вариантами ответов</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<button
|
||||
onClick={() => setFromQuestions(false)}
|
||||
className={`p-5 rounded-2xl border text-center transition-all duration-200 cursor-pointer ${
|
||||
!fromQuestions
|
||||
? "bg-accent border-primary/20 shadow-sm shadow-primary/5"
|
||||
: "hover:bg-secondary/60"
|
||||
}`}
|
||||
>
|
||||
<ClipboardList size={22} className={`mx-auto mb-2 ${!fromQuestions ? "text-primary" : "text-muted-foreground"}`} />
|
||||
<span className="text-sm font-medium block">По теме</span>
|
||||
<span className="text-xs text-muted-foreground">Укажите тему теста</span>
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setFromQuestions(true)}
|
||||
className={`p-5 rounded-2xl border text-center transition-all duration-200 cursor-pointer ${
|
||||
fromQuestions
|
||||
? "bg-accent border-primary/20 shadow-sm shadow-primary/5"
|
||||
: "hover:bg-secondary/60"
|
||||
}`}
|
||||
>
|
||||
<MessageSquare size={22} className={`mx-auto mb-2 ${fromQuestions ? "text-primary" : "text-muted-foreground"}`} />
|
||||
<span className="text-sm font-medium block">По моим вопросам</span>
|
||||
<span className="text-xs text-muted-foreground">На основе заданных ранее</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{!fromQuestions && (
|
||||
<Input
|
||||
value={topic}
|
||||
onChange={(e) => setTopic(e.target.value)}
|
||||
placeholder="Тема теста..."
|
||||
className="animate-fade-in"
|
||||
/>
|
||||
)}
|
||||
|
||||
<Button onClick={generateTest} className="w-full">
|
||||
Сгенерировать тест
|
||||
</Button>
|
||||
|
||||
{tests.length > 0 && (
|
||||
<div className="space-y-2">
|
||||
<h2 className="text-sm font-medium text-muted-foreground uppercase tracking-wider">
|
||||
История
|
||||
</h2>
|
||||
{tests.map((t) => (
|
||||
<div key={t.id} className="flex items-center justify-between p-3.5 rounded-xl border text-sm">
|
||||
<div>
|
||||
<span className="font-medium">{t.topic}</span>
|
||||
<span className="text-xs text-muted-foreground ml-2">
|
||||
{new Date(t.createdAt).toLocaleDateString("ru")}
|
||||
</span>
|
||||
{t.results.length > 0 && (
|
||||
<span className={`ml-2 text-sm font-semibold ${
|
||||
t.results[t.results.length - 1].score / t.results[t.results.length - 1].total >= 0.7 ? "text-green-600" : "text-orange-500"
|
||||
}`}>
|
||||
{t.results[t.results.length - 1].score}/{t.results[t.results.length - 1].total}
|
||||
</span>
|
||||
)}
|
||||
{t.results.length > 1 && (
|
||||
<span className="text-[10px] text-muted-foreground ml-1">
|
||||
({t.results.length} попыток)
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => retakeTest(t)}
|
||||
>
|
||||
<RotateCcw size={13} />
|
||||
Пройти
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { BookOpen, ChevronRight, Search, Sparkles } from "lucide-react";
|
||||
import { apiFetch, API_BASE } from "@/lib/utils";
|
||||
import Markdown from "@/components/Markdown";
|
||||
|
||||
interface Textbook {
|
||||
id: number;
|
||||
topic: string;
|
||||
content: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export default function TextbookPage() {
|
||||
const [topic, setTopic] = useState("");
|
||||
const [generating, setGenerating] = useState(false);
|
||||
const [current, setCurrent] = useState("");
|
||||
const [textbooks, setTextbooks] = useState<Textbook[]>([]);
|
||||
const [selectedId, setSelectedId] = useState<number | null>(null);
|
||||
const [search, setSearch] = useState("");
|
||||
|
||||
useEffect(() => { loadTextbooks(); }, []);
|
||||
|
||||
async function loadTextbooks() {
|
||||
try { setTextbooks(await apiFetch<Textbook[]>("/textbooks")); } catch {}
|
||||
}
|
||||
|
||||
async function generate() {
|
||||
if (!topic.trim() || generating) return;
|
||||
setGenerating(true);
|
||||
setCurrent("");
|
||||
setSelectedId(null);
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/textbooks/generate`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ topic: topic.trim() }),
|
||||
});
|
||||
|
||||
const reader = res.body?.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let fullContent = "";
|
||||
|
||||
while (reader) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
for (const line of decoder.decode(value).split("\n").filter((l) => l.startsWith("data: "))) {
|
||||
const data = line.slice(6);
|
||||
if (data === "[DONE]") break;
|
||||
try {
|
||||
const parsed = JSON.parse(data);
|
||||
if (parsed.content) { fullContent += parsed.content; setCurrent(fullContent); }
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
setTopic("");
|
||||
loadTextbooks();
|
||||
} catch (err: any) { setCurrent(`Ошибка: ${err.message}`); }
|
||||
setGenerating(false);
|
||||
}
|
||||
|
||||
const displayContent = selectedId
|
||||
? textbooks.find((t) => t.id === selectedId)?.content || ""
|
||||
: current;
|
||||
|
||||
const filtered = textbooks.filter(
|
||||
(t) => t.topic.toLowerCase().includes(search.toLowerCase())
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold tracking-tight">Генерация учебника</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
ИИ составит учебник с понятными объяснениями по вашей теме
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
value={topic}
|
||||
onChange={(e) => setTopic(e.target.value)}
|
||||
onKeyDown={(e) => e.key === "Enter" && generate()}
|
||||
placeholder="Введите тему..."
|
||||
disabled={generating}
|
||||
className="flex-1"
|
||||
/>
|
||||
<Button onClick={generate} disabled={generating || !topic.trim()}>
|
||||
{generating ? <Sparkles size={16} className="animate-spin-glow" /> : <BookOpen size={16} />}
|
||||
Создать
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{generating && !displayContent && (
|
||||
<div className="shimmer rounded-2xl h-40" />
|
||||
)}
|
||||
|
||||
{displayContent && (
|
||||
<Card className="animate-fade-in">
|
||||
<CardContent className="pt-5">
|
||||
<Markdown exportable exportTitle={selectedId ? textbooks.find((t) => t.id === selectedId)?.topic || "textbook" : topic || "textbook"}>
|
||||
{displayContent}
|
||||
</Markdown>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{textbooks.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h2 className="text-sm font-medium text-muted-foreground uppercase tracking-wider">
|
||||
Созданные учебники
|
||||
</h2>
|
||||
|
||||
<div className="relative">
|
||||
<Search size={15} className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
placeholder="Поиск по учебникам..."
|
||||
className="pl-9"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
{filtered.map((tb) => (
|
||||
<button
|
||||
key={tb.id}
|
||||
onClick={() => setSelectedId(tb.id === selectedId ? null : tb.id)}
|
||||
className={`w-full text-left flex items-center justify-between p-3.5 rounded-xl border transition-all duration-200 cursor-pointer group ${
|
||||
tb.id === selectedId
|
||||
? "bg-accent border-primary/20 shadow-sm"
|
||||
: "hover:bg-secondary/60 hover:border-border"
|
||||
}`}
|
||||
>
|
||||
<div>
|
||||
<span className="text-sm font-medium">{tb.topic}</span>
|
||||
<span className="text-xs text-muted-foreground ml-2">
|
||||
{new Date(tb.createdAt).toLocaleDateString("ru")}
|
||||
</span>
|
||||
</div>
|
||||
<ChevronRight
|
||||
size={15}
|
||||
className={`text-muted-foreground transition-transform duration-200 ${
|
||||
tb.id === selectedId ? "rotate-90" : "group-hover:translate-x-0.5"
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
))}
|
||||
{filtered.length === 0 && search && (
|
||||
<p className="text-center text-sm text-muted-foreground py-6">Ничего не найдено</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"types": ["vite/client"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"types": ["node"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
import path from "path";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "./src"),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
port: 5173,
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: "http://localhost:3001",
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user