Nahrát soubory do „z1/frontend/src/components“

This commit is contained in:
Tetiana Mohorian 2025-03-18 21:08:49 +00:00
parent 18a06b71a5
commit 9d9e53ef72
5 changed files with 130 additions and 0 deletions

View File

@ -0,0 +1,51 @@
import React, { useState } from 'react';
import { Send } from 'lucide-react';
const ChatInput = ({ onSubmit }) => {
const [input, setInput] = useState('');
const handleSubmit = async (e) => {
e.preventDefault();
console.log("Formulár bol odoslaný!", input); // Добавили лог
if (input.trim()) {
try {
const response = await fetch("http://localhost:5000/api/predict", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: input }),
});
const data = await response.json();
//alert(`Výsledok analýzy: ${data.prediction}`);
if (onSubmit)
{
onSubmit(input, data.prediction);
}
setInput('');
} catch (error) {
console.error("Ошибка запроса:", error);
alert("Chyba pri analýze textu!");
}
}
};
return (
<div className="input-container">
<form onSubmit={handleSubmit} className="input-wrapper">
<input
type="text"
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="Zadajte text na analýzu"
className="text-input"
/>
<button type="submit" className="submit-button">
<Send size={24} />
</button>
</form>
</div>
);
};
export default ChatInput;

View File

@ -0,0 +1,16 @@
import React from "react";
const ChatWindow = ({ messages }) => {
return (
<div className="chat-window">
{messages.map((msg, index) => (
<div key={index} className={`message ${msg.sender}`}>
{msg.text}
</div>
))}
</div>
);
};
export default ChatWindow;

View File

@ -0,0 +1,20 @@
import React from 'react';
import { FaTelegram, FaGooglePlay } from 'react-icons/fa';
const Footer = () => {
return (
<footer className="footer-container">
<p>Created by Tetiana Mohorian</p>
<div className="footer-icons">
<a href="https://t.me/yourtelegram" target="_blank" rel="noopener noreferrer">
<FaTelegram size={32} />
</a>
<a href="https://play.google.com/store" target="_blank" rel="noopener noreferrer">
<FaGooglePlay size={28} />
</a>
</div>
</footer>
);
};
export default Footer;

View File

@ -0,0 +1,9 @@
import React from 'react';
const Header = () => (
<header className="header-container">
<h1 className="app-title">Detektor nenávistného jazyka</h1>
</header>
);
export default Header;

View File

@ -0,0 +1,34 @@
import React, { useState } from 'react';
import ChatInput from './ChatInput.jsx';
const InfoBox = () => {
const [headerText, setHeaderText] = useState('Analyzujte text na nenávistný jazyk');
const [paragraphText, setParagraphText] = useState('Tento nástroj využíva umelú inteligenciu na identifikáciu toxického obsahu v textoch. Stačí zadať text a zistiť, či obsahuje nenávistný jazyk.');
const handleSendMessage = (userMessage, serverResponse) => {
console.log('Отправлено сообщение:', userMessage);
console.log('Ответ от сервера:', serverResponse);
setHeaderText(serverResponse); // В заголовок пишем ответ от сервера
setParagraphText(`Váš text bol: "${userMessage}"`);// В параграф пишем сообщение пользователя
};
return (
<div className="info-container">
<h2>{headerText}</h2>
<p>{paragraphText}</p>
<ChatInput onSubmit={handleSendMessage} /> {}
</div>
);
}
export default InfoBox;