Compare commits

..

No commits in common. "36ebd0d5c53804d0b41584decf53fa64447f00e5" and "0b5438ec82f97fc3c7d7d8d0109c1e9a8756a8fc" have entirely different histories.

8 changed files with 38 additions and 89 deletions

View file

@ -1,25 +1,23 @@
/* type ChatMessage = {
type Message = {
role: string;
content:string
}
type Chat = {
name: string; name: string;
messages: Message[]; messages: any;
timestamp: number; timestamp: number;
}; };
export let chatHistory: Chat[] = []; let chatHistory: ChatMessage[] = [];
export function addMessageToHistory(index: number, chat: Chat): void { function addMessageToHistory(name: string, message: any): void {
if (index >= 0 && index < chatHistory.length) { const newMessage: ChatMessage = {
chatHistory[index] = chat; name: name,
chatHistory.sort((a, b) => b.timestamp - a.timestamp) messages: message,
} timestamp: Date.now()
};
chatHistory.push(newMessage);
console.log(`Added message from ${name}: ${message}`);
chatHistory.sort((a,b) => b.timestamp - a.timestamp)
} }
export function removeMessageFromHistory(timestamp: number): void { function removeMessageFromHistory(timestamp: number): void {
const index = chatHistory.findIndex((msg) => msg.timestamp === timestamp); const index = chatHistory.findIndex((msg) => msg.timestamp === timestamp);
if (index > -1) { if (index > -1) {
chatHistory.splice(index, 1); chatHistory.splice(index, 1);
@ -28,3 +26,4 @@ export function removeMessageFromHistory(timestamp: number): void {
console.log(`Message not found with timestamp: ${timestamp}`); console.log(`Message not found with timestamp: ${timestamp}`);
} }
} }
*/

View file

@ -4,26 +4,14 @@ import ConversationFrontend from '../components/ConversationFrontend';
import InputFrontend from "../components/InputFrontend"; import InputFrontend from "../components/InputFrontend";
import { sendToVoiceRecognition } from "./voice_backend" import { sendToVoiceRecognition } from "./voice_backend"
import axios from "axios"; import axios from "axios";
import { changeHistory, checkCredentials, getHistory } from './database';
import { addMessageToHistory, removeMessageFromHistory } from "./ChatHistory";
interface InputOutputHandlerProps { const InputOutputBackend: React.FC = () => {
selectedIndex: number;
}
const InputOutputBackend: React.FC<InputOutputHandlerProps> = ({selectedIndex}) => {
// # variables // # variables
type Message = { type Message = {
role: string role: string
content: string content: string
} }
type Chat = {
name?: string
messages: Message[]
timestamp: string
}
// Define state variables for user preferences and messages // Define state variables for user preferences and messages
const [preferredCurrency, setPreferredCurrency] = useState<string>("USD"); const [preferredCurrency, setPreferredCurrency] = useState<string>("USD");
const [preferredLanguage, setPreferredLanguage] = useState<string>("english"); const [preferredLanguage, setPreferredLanguage] = useState<string>("english");
@ -254,7 +242,6 @@ const InputOutputBackend: React.FC<InputOutputHandlerProps> = ({selectedIndex})
const handleStopClick = () => { const handleStopClick = () => {
endGetWorker() endGetWorker()
getNewToken() getNewToken()
setInputDisabled(false)
} }
const handleResendClick = () => { const handleResendClick = () => {

View file

@ -75,7 +75,7 @@ export const changePassword = async (usernameOrEmail: string, password: string,
return await sendToDatabase(data); return await sendToDatabase(data);
}; };
export const getSettings = async (usernameOrEmail: string, password: string) => { export const getData = async (usernameOrEmail: string, password: string) => {
const data = { const data = {
action: "get_settings", action: "get_settings",
username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail, username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail,
@ -85,38 +85,6 @@ export const getSettings = async (usernameOrEmail: string, password: string) =>
return await sendToDatabaseAndGetString(data); return await sendToDatabaseAndGetString(data);
}; };
export const changeSettings = async (usernameOrEmail: string, password: string, newData: object) => {
const data = {
action: "change_settings",
username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail,
email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined,
password,
data: newData,
};
return await sendToDatabase(data);
};
export const getHistory = async (usernameOrEmail: string, password: string) => {
const data = {
action: "get_history",
username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail,
email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined,
password,
};
return await sendToDatabaseAndGetString(data);
};
export const changeHistory = async (usernameOrEmail: string, password: string, newData: object) => {
const data = {
action: "change_history",
username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail,
email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined,
password,
data: newData,
};
return await sendToDatabase(data);
};
export const getEmail = async (usernameOrEmail: string, password: string): Promise<string> => { export const getEmail = async (usernameOrEmail: string, password: string): Promise<string> => {
const data = { const data = {
action: "get_email", action: "get_email",
@ -137,6 +105,16 @@ export const getName = async (usernameOrEmail: string, password: string): Promis
return await sendToDatabaseAndGetString(data); return await sendToDatabaseAndGetString(data);
}; };
export const changeData = async (usernameOrEmail: string, password: string, newData: object) => {
const data = {
action: "change_settings",
username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail,
email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined,
password,
data: newData,
};
return await sendToDatabase(data);
};
export const checkCredentials = async (usernameOrEmail: string, password: string) => { export const checkCredentials = async (usernameOrEmail: string, password: string) => {
const data = { const data = {

View file

@ -2,14 +2,10 @@
import React from 'react'; import React from 'react';
import InputOutputBackend from '../backend/InputOutputHandler'; import InputOutputBackend from '../backend/InputOutputHandler';
interface AIProps{ const AI: React.FC = () => {
selectedIndex:number
}
const AI: React.FC<AIProps> = ({selectedIndex}) => {
return ( return (
<div className="ai-container"> <div className="ai-container">
<InputOutputBackend selectedIndex={selectedIndex}/> <InputOutputBackend />
</div> </div>
); );
}; };

View file

@ -1,16 +1,6 @@
import React, { useState } from 'react'; import React from 'react';
interface HistoryProps{
selectedIndex: number;
setSelectedIndex: (index: number) => void;
}
const History: React.FC<HistoryProps> = ({selectedIndex, setSelectedIndex}) => {
const handleHistoryClick = (index: number) => {
setSelectedIndex(index)
}
const History: React.FC = () => {
return ( return (
<div className="history-background"> <div className="history-background">
<div className="history"> <div className="history">
@ -18,7 +8,7 @@ const History: React.FC<HistoryProps> = ({selectedIndex, setSelectedIndex}) => {
{/* Populate with history items */} {/* Populate with history items */}
{Array.from({ length: 20 }, (_, index) => ( {Array.from({ length: 20 }, (_, index) => (
<li key={index}> <li key={index}>
<a href="#" onClick={()=>handleHistoryClick(index)}>history{index + 1}</a> <a href="#">history{index + 1}</a>
</li> </li>
))} ))}
</ul> </ul>

View file

@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import { import {
createAccount, createAccount,
checkCredentials, checkCredentials,
getSettings getData
} from '../backend/database'; } from '../backend/database';
import Settings from './settings/Settings'; // Import the Settings component import Settings from './settings/Settings'; // Import the Settings component
@ -62,7 +62,7 @@ const Login: React.FC = () => {
const success = await checkCredentials(accountName, password); const success = await checkCredentials(accountName, password);
if (success) { if (success) {
setIsLoggedIn(true); // Successful login setIsLoggedIn(true); // Successful login
const data = await getSettings(accountName, password) const data = await getData(accountName, password)
if (data) { if (data) {
if (typeof localStorage !== 'undefined') { if (typeof localStorage !== 'undefined') {
localStorage.setItem("dataFromServer", data) localStorage.setItem("dataFromServer", data)

View file

@ -12,7 +12,7 @@ import PrivacySettings from './PrivacySettings';
import FontSizeSetting from './FontSize'; import FontSizeSetting from './FontSize';
import OpenSourceModeToggle from './OpenSourceToggle'; import OpenSourceModeToggle from './OpenSourceToggle';
import { import {
changeSettings, changeData,
createAccount, createAccount,
deleteAccount, deleteAccount,
} from '../../backend/database'; } from '../../backend/database';
@ -355,7 +355,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
} }
if (await createAccount(useName, useEmail, usePassword)) { if (await createAccount(useName, useEmail, usePassword)) {
if (await changeSettings(useName, usePassword, settings)) { if (await changeData(useName, usePassword, settings)) {
localStorage.setItem("currentName", useName) localStorage.setItem("currentName", useName)
localStorage.setItem("currentPassword", usePassword) localStorage.setItem("currentPassword", usePassword)
localStorage.setItem("currentEmail", useEmail) localStorage.setItem("currentEmail", useEmail)
@ -750,7 +750,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
<button className="apply" onClick={async () => { <button className="apply" onClick={async () => {
getAllLocalStorageItems(); getAllLocalStorageItems();
closeSettings(); closeSettings();
await changeSettings(localStorage.getItem('accountName') ?? "hello", localStorage.getItem('accountPassword') ?? "hello", settings) // ???? await changeData(localStorage.getItem('accountName') ?? "hello", localStorage.getItem('accountPassword') ?? "hello", settings) // ????
window.location.reload(); window.location.reload();
}}> }}>
Apply Apply

View file

@ -14,7 +14,6 @@ const LandingPage: React.FC = () => {
const [showDivs, setShowDivs] = useState(true); const [showDivs, setShowDivs] = useState(true);
const [view, setView] = useState<'AI' | 'FAQ' | 'Documentation' | 'Credits'>('AI'); const [view, setView] = useState<'AI' | 'FAQ' | 'Documentation' | 'Credits'>('AI');
const conversationRef = useRef<HTMLDivElement>(null); const conversationRef = useRef<HTMLDivElement>(null);
const [selectedHistoryIndex, setSelectedHistoryIndex] = useState<number>(0)
const [primaryColor, setPrimaryColor] = useState("#fefefe"); const [primaryColor, setPrimaryColor] = useState("#fefefe");
const [secondaryColor, setSecondaryColor] = useState("#fefefe"); const [secondaryColor, setSecondaryColor] = useState("#fefefe");
@ -92,13 +91,13 @@ const LandingPage: React.FC = () => {
<div className={`left-panel ${showDivs ? 'visible' : 'hidden'}`}> <div className={`left-panel ${showDivs ? 'visible' : 'hidden'}`}>
{showDivs && ( {showDivs && (
<div className="history-models"> <div className="history-models">
<History selectedIndex={selectedHistoryIndex} setSelectedIndex={setSelectedHistoryIndex}/> <History />
<Models /> <Models />
</div> </div>
)} )}
</div> </div>
<div className={`conversation-container ${showDivs ? 'collapsed' : 'expanded'}`} ref={conversationRef}> <div className={`conversation-container ${showDivs ? 'collapsed' : 'expanded'}`} ref={conversationRef}>
{view === 'AI' && <AI selectedIndex={selectedHistoryIndex} />} {view === 'AI' && <AI />}
{view === 'FAQ' && <FAQ />} {view === 'FAQ' && <FAQ />}
{view === 'Documentation' && <Documentation />} {view === 'Documentation' && <Documentation />}
{view === 'Credits' && <Credits />} {view === 'Credits' && <Credits />}