Merge branch 'main' of https://github.com/devaine/CodeRED-Astra
This commit is contained in:
commit
5a9da85f07
31 changed files with 2831 additions and 54 deletions
16
web-app/src/app/index.jsx
Normal file
16
web-app/src/app/index.jsx
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import React from "react";
|
||||
<<<<<<< HEAD:src/app/index.jsx
|
||||
import ChatLayout from "../components/ui/ChatLayout";
|
||||
=======
|
||||
import ChatLayout from "src/components/layouts/chat-layout";
|
||||
>>>>>>> cb9cff44215b6de81ed81ef2a1c6abe090fbf1b1:web-app/src/app/index.jsx
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-900 text-white flex items-center justify-center p-6">
|
||||
<ChatLayout />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
34
web-app/src/components/layouts/chat-layout.jsx
Normal file
34
web-app/src/components/layouts/chat-layout.jsx
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import React, { useState } from "react";
|
||||
import ChatHeader from "src/components/ui/chat/chat-header";
|
||||
import ChatWindow from "src/components/ui/chat/chat-window";
|
||||
import MessageInput from "src/components/ui/chat/message-input";
|
||||
|
||||
export default function ChatLayout() {
|
||||
const [messages, setMessages] = useState([
|
||||
{
|
||||
role: "assistant",
|
||||
content: "Hello — I can help you with code, explanations, and more.",
|
||||
},
|
||||
]);
|
||||
|
||||
function handleSend(text) {
|
||||
const userMsg = { role: "user", content: text };
|
||||
setMessages((s) => [...s, userMsg]);
|
||||
|
||||
// fake assistant reply after short delay
|
||||
setTimeout(() => {
|
||||
setMessages((s) => [
|
||||
...s,
|
||||
{ role: "assistant", content: `You said: ${text}` },
|
||||
]);
|
||||
}, 600);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-[80vh] w-full max-w-3xl mx-auto rounded-lg overflow-hidden shadow-lg border border-slate-700">
|
||||
<ChatHeader />
|
||||
<ChatWindow messages={messages} />
|
||||
<MessageInput onSend={handleSend} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
0
web-app/src/components/layouts/dashboard-layout.jsx
Normal file
0
web-app/src/components/layouts/dashboard-layout.jsx
Normal file
29
web-app/src/components/ui/Button/ActionButton.css
Normal file
29
web-app/src/components/ui/Button/ActionButton.css
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
.action-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 12px;
|
||||
border: 2px solid var(--btn-color);
|
||||
border-radius: 6px;
|
||||
background-color: white;
|
||||
color: var(--btn-color);
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.25s ease;
|
||||
}
|
||||
|
||||
.action-btn:hover,
|
||||
.action-btn:focus {
|
||||
background-color: var(--btn-color);
|
||||
color: white;
|
||||
border-color: var(--btn-color);
|
||||
}
|
||||
|
||||
.action-btn svg {
|
||||
fill: currentColor;
|
||||
transition: fill 0.25s ease;
|
||||
}
|
||||
|
||||
.action-btn:hover {
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
57
web-app/src/components/ui/Button/ActionButton.jsx
Normal file
57
web-app/src/components/ui/Button/ActionButton.jsx
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import './ActionButton.css';
|
||||
|
||||
export default function ActionButton({
|
||||
onClick,
|
||||
children,
|
||||
type = 'add', // 'add' or 'delete'
|
||||
...props
|
||||
}) {
|
||||
// Define color and icon based on type
|
||||
const config = {
|
||||
add: {
|
||||
color: '#0F2862',
|
||||
svg: (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
fill="currentColor"
|
||||
viewBox="0 0 16 16"
|
||||
>
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
d="M8 2a.5.5 0 0 1 .5.5v5h5a.5.5 0 0 1 0 1h-5v5a.5.5 0 0 1-1 0v-5h-5a.5.5 0 0 1 0-1h5v-5A.5.5 0 0 1 8 2"
|
||||
/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
delete: {
|
||||
color: '#9E363A',
|
||||
svg: (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
fill="currentColor"
|
||||
viewBox="0 0 16 16"
|
||||
>
|
||||
<path d="M6.5 1h3a.5.5 0 0 1 .5.5v1H6v-1a.5.5 0 0 1 .5-.5M11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3A1.5 1.5 0 0 0 5 1.5v1H1.5a.5.5 0 0 0 0 1h.538l.853 10.66A2 2 0 0 0 4.885 16h6.23a2 2 0 0 0 1.994-1.84l.853-10.66h.538a.5.5 0 0 0 0-1zm1.958 1-.846 10.58a1 1 0 0 1-.997.92h-6.23a1 1 0 0 1-.997-.92L3.042 3.5zm-7.487 1a.5.5 0 0 1 .528.47l.5 8.5a.5.5 0 0 1-.998.06L5 5.03a.5.5 0 0 1 .47-.53Zm5.058 0a.5.5 0 0 1 .47.53l-.5 8.5a.5.5 0 1 1-.998-.06l.5-8.5a.5.5 0 0 1 .528-.47M8 4.5a.5.5 0 0 1 .5.5v8.5a.5.5 0 0 1-1 0V5a.5.5 0 0 1 .5-.5"/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
const { color, svg } = config[type] || config.add;
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
className="action-btn"
|
||||
style={{ '--btn-color': color }}
|
||||
{...props}
|
||||
>
|
||||
{ type === 'add' ? 'New Chat' : 'Delete Chat'}
|
||||
{svg}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
40
web-app/src/components/ui/chat/chat-header.jsx
Normal file
40
web-app/src/components/ui/chat/chat-header.jsx
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import React from "react";
|
||||
import ActionButton from "./Button/ActionButton.jsx";
|
||||
|
||||
export default function ChatHeader({ title = "AI Assistant" }) {
|
||||
// Delete chat log (frontend + backend)
|
||||
const handleDeleteChat = async () => {
|
||||
if (!window.confirm("Delete all messages?")) return;
|
||||
await fetch(`/api/chat/${conversationId}`, { method: "DELETE" });
|
||||
setMessages([]);
|
||||
};
|
||||
|
||||
// Restart chat (new conversation)
|
||||
const handleNewChat = async () => {
|
||||
const res = await fetch("/api/chat/new", { method: "POST" });
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
setConversationId(data.conversationId);
|
||||
setMessages([]);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<header className="flex items-center justify-between px-4 py-3 bg-gradient-to-r from-slate-800 to-slate-900 text-white">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-indigo-500 rounded flex items-center justify-center font-bold">
|
||||
AI
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-lg font-semibold">{title}</h1>
|
||||
<p className="text-sm text-slate-300">
|
||||
Ask anything — AI is listening
|
||||
</p>
|
||||
</div>
|
||||
<ActionButton type="add" onClick={handleNewChat}></ActionButton>
|
||||
<ActionButton type="delete" onClick={handleDeleteChat}></ActionButton>
|
||||
</div>
|
||||
|
||||
</header>
|
||||
);
|
||||
}
|
||||
38
web-app/src/components/ui/chat/chat-window.jsx
Normal file
38
web-app/src/components/ui/chat/chat-window.jsx
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import React, { useRef, useEffect } from "react";
|
||||
|
||||
|
||||
function MessageBubble({ message }) {
|
||||
const isUser = message.role === "user";
|
||||
return (
|
||||
<div
|
||||
className={`flex ${isUser ? "justify-end" : "justify-start"} px-4 py-2`}
|
||||
>
|
||||
<div
|
||||
className={`max-w-[70%] p-3 rounded-lg ${isUser ? "bg-indigo-600 text-white" : "bg-slate-700 text-slate-100"}`}
|
||||
>
|
||||
<div className="text-sm">{message.content}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ChatWindow({ messages }) {
|
||||
const chatRef = useRef(null);
|
||||
// Auto-scroll to bottom when new messages appear
|
||||
useEffect(() => {
|
||||
chatRef.current?.scrollTo({
|
||||
top: chatRef.current.scrollHeight,
|
||||
behavior: "smooth",
|
||||
});
|
||||
}, [messages]);
|
||||
|
||||
return (
|
||||
<main className="flex-1 overflow-auto p-2 bg-gradient-to-b from-slate-900 to-slate-800">
|
||||
<div className="space-y-2">
|
||||
{messages.map((m, i) => (
|
||||
<MessageBubble key={i} message={m} />
|
||||
))}
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
31
web-app/src/components/ui/chat/message-input.jsx
Normal file
31
web-app/src/components/ui/chat/message-input.jsx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import React, { useState } from "react";
|
||||
|
||||
export default function MessageInput({ onSend }) {
|
||||
const [text, setText] = useState("");
|
||||
|
||||
function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
if (!text.trim()) return;
|
||||
onSend(text.trim());
|
||||
setText("");
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="p-3 bg-slate-900">
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
placeholder="Type a message..."
|
||||
className="flex-1 rounded-md bg-slate-800 border border-slate-700 px-3 py-2 text-white focus:outline-none focus:ring-2 focus:ring-indigo-500"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-indigo-500 hover:bg-indigo-600 text-white px-4 py-2 rounded-md"
|
||||
>
|
||||
Send
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
24
web-app/src/index.css
Normal file
24
web-app/src/index.css
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
@import "tailwindcss/preflight";
|
||||
@import "tailwindcss/utilities";
|
||||
|
||||
:root {
|
||||
--color-primary: 15 40 98;
|
||||
--color-secondary: 79 95 118;
|
||||
--color-accent: 158 54 58;
|
||||
--color-paragraph: 255 255 255;
|
||||
--color-background: 9 31 54;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background-color: rgb(var(--color-background));
|
||||
color: rgb(var(--color-paragraph));
|
||||
font-family:
|
||||
ui-sans-serif,
|
||||
system-ui,
|
||||
-apple-system,
|
||||
"Segoe UI",
|
||||
Roboto,
|
||||
"Helvetica Neue",
|
||||
Arial;
|
||||
}
|
||||
10
web-app/src/main.jsx
Normal file
10
web-app/src/main.jsx
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import "./index.css";
|
||||
import App from "./app/index.jsx";
|
||||
|
||||
createRoot(document.getElementById("root")).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>
|
||||
);
|
||||
7
web-app/src/styles/theme.css
Normal file
7
web-app/src/styles/theme.css
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
@theme {
|
||||
--color-primary: rgba(15, 40, 98);
|
||||
--color-secondary: rgba(79, 95, 118);
|
||||
--color-accent: rgba(158, 54, 58);
|
||||
--color-paragraph: rgba(255, 255, 255);
|
||||
--color-background: rgba(9, 31, 54);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue