forked from React-Group/interstellar_ai
Compare commits
No commits in common. "219b301d62905332ddea9ec97bb2852993edf77b" and "363a7d2fc3a407cc46dc8d0e81e3fe80091f0ed1" have entirely different histories.
219b301d62
...
363a7d2fc3
8 changed files with 81 additions and 164 deletions
|
@ -40,8 +40,7 @@ python3 api.py
|
||||||
```
|
```
|
||||||
3. In the main project folder, you will run:
|
3. In the main project folder, you will run:
|
||||||
```
|
```
|
||||||
npm run build
|
npm run dev
|
||||||
npm start
|
|
||||||
npx electron .
|
|
||||||
```
|
```
|
||||||
4. Enjoy!
|
4. Open http://localhost:3000/ in your browser.
|
||||||
|
5. Enjoy!
|
|
@ -5,7 +5,6 @@ import {
|
||||||
getSettings
|
getSettings
|
||||||
} from '../backend/database';
|
} from '../backend/database';
|
||||||
import Settings from './settings/Settings'; // Import the Settings component
|
import Settings from './settings/Settings'; // Import the Settings component
|
||||||
import { importDatabase } from './settings/settingUtils';
|
|
||||||
|
|
||||||
const Login: React.FC = () => {
|
const Login: React.FC = () => {
|
||||||
// State to handle popup visibility
|
// State to handle popup visibility
|
||||||
|
@ -24,9 +23,9 @@ const Login: React.FC = () => {
|
||||||
|
|
||||||
// On component mount, check if there are credentials in localStorage
|
// On component mount, check if there are credentials in localStorage
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let savedAccountName: string | null;
|
let savedAccountName:string|null;
|
||||||
let savedAccountEmail: string | null;
|
let savedAccountEmail:string|null;
|
||||||
let savedAccountPassword: string | null;
|
let savedAccountPassword:string|null;
|
||||||
if (typeof localStorage !== 'undefined') {
|
if (typeof localStorage !== 'undefined') {
|
||||||
savedAccountName = localStorage.getItem('accountName');
|
savedAccountName = localStorage.getItem('accountName');
|
||||||
savedAccountEmail = localStorage.getItem('accountEmail');
|
savedAccountEmail = localStorage.getItem('accountEmail');
|
||||||
|
@ -41,14 +40,6 @@ const Login: React.FC = () => {
|
||||||
if (savedAccountName !== null && savedAccountPassword !== null) {
|
if (savedAccountName !== null && savedAccountPassword !== null) {
|
||||||
const success = await checkCredentials(savedAccountName, savedAccountPassword);
|
const success = await checkCredentials(savedAccountName, savedAccountPassword);
|
||||||
setIsLoggedIn(success); // Automatically log in
|
setIsLoggedIn(success); // Automatically log in
|
||||||
const useName = localStorage.getItem("accountName");
|
|
||||||
const usePassword = localStorage.getItem("accountPassword");
|
|
||||||
|
|
||||||
if (useName && usePassword) {
|
|
||||||
await importDatabase(useName, usePassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
check();
|
check();
|
||||||
|
@ -78,14 +69,6 @@ const Login: React.FC = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setShowLoginPopup(false); // Close the login popup
|
setShowLoginPopup(false); // Close the login popup
|
||||||
const useName = localStorage.getItem("accountName");
|
|
||||||
const usePassword = localStorage.getItem("accountPassword");
|
|
||||||
|
|
||||||
if (useName && usePassword) {
|
|
||||||
await importDatabase(useName, usePassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.location.reload();
|
|
||||||
} else {
|
} else {
|
||||||
alert('Incorrect credentials');
|
alert('Incorrect credentials');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//#region imports
|
//#region imports
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { applyTheme } from './theme';
|
import { applyTheme } from './theme';
|
||||||
import { exportSettings, importSettings, sendToDatabase, importDatabase } from './settingUtils'; // Import utility functions
|
import { exportSettings, importSettings } from './settingUtils'; // Import utility functions
|
||||||
import { getAllLocalStorageItems } from '../../backend/GetLocalStorage';
|
import { getAllLocalStorageItems } from '../../backend/GetLocalStorage';
|
||||||
import ColorSetting from './ColorSettings';
|
import ColorSetting from './ColorSettings';
|
||||||
import TextSettings from './TextSettings'
|
import TextSettings from './TextSettings'
|
||||||
|
@ -15,6 +15,8 @@ import {
|
||||||
changeSettings,
|
changeSettings,
|
||||||
createAccount,
|
createAccount,
|
||||||
deleteAccount,
|
deleteAccount,
|
||||||
|
getSettings,
|
||||||
|
sendToDatabase
|
||||||
} from '../../backend/database';
|
} from '../../backend/database';
|
||||||
import ThemeDropdown from './DropDownTheme';
|
import ThemeDropdown from './DropDownTheme';
|
||||||
|
|
||||||
|
@ -312,6 +314,27 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
}
|
}
|
||||||
}, []); // Runs only once when the component mounts
|
}, []); // Runs only once when the component mounts
|
||||||
|
|
||||||
|
const importDatabase = async (useName: string, usePassword: string) => {
|
||||||
|
const databaseSettings = await getSettings(useName, usePassword);
|
||||||
|
|
||||||
|
// Ensure user settings exist before flattening and storing
|
||||||
|
if (typeof databaseSettings == 'object' && databaseSettings) {
|
||||||
|
JSON.stringify(importSettings(databaseSettings), null, 2); // Pass only the current user's settings
|
||||||
|
} else {
|
||||||
|
console.error('Database settings are not in the expected format.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const sendToDatabase = async () => {
|
||||||
|
let useName = localStorage.getItem("accountName")
|
||||||
|
let usePassword = localStorage.getItem("accountPassword")
|
||||||
|
if (useName && usePassword) {
|
||||||
|
if (await changeSettings(useName, usePassword, JSON.parse(exportSettings()))) {
|
||||||
|
alert('Data has been transferred')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Effect hooks to update localStorage whenever any state changes
|
// Effect hooks to update localStorage whenever any state changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Flatten nested objects
|
// Flatten nested objects
|
||||||
|
@ -570,7 +593,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
//#region custom --> foss
|
//#region custom --> foss
|
||||||
case 'foss':
|
case 'foss':
|
||||||
return (
|
return (
|
||||||
<div className="settings-section">
|
<div className="settings-section">
|
||||||
|
@ -583,7 +606,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
//#region account
|
//#region account
|
||||||
case 'account':
|
case 'account':
|
||||||
return (
|
return (
|
||||||
<div className="settings-section">
|
<div className="settings-section">
|
||||||
|
@ -626,7 +649,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
//#region api
|
//#region api
|
||||||
case 'api':
|
case 'api':
|
||||||
return (
|
return (
|
||||||
<div className="settings-section">
|
<div className="settings-section">
|
||||||
|
@ -680,7 +703,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
//#region import export
|
//#region import export
|
||||||
case 'im/export':
|
case 'im/export':
|
||||||
return (
|
return (
|
||||||
<div className="settings-section">
|
<div className="settings-section">
|
||||||
|
@ -736,51 +759,52 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
//#region overall export
|
//#region overall export
|
||||||
return (
|
return (
|
||||||
<div className="popup-overlay">
|
<div className="popup-overlay">
|
||||||
<div className="settings-content">
|
<div className="settings-content">
|
||||||
<div className="settings-container">
|
<div className="settings-container">
|
||||||
{/* Sidebar for desktop */}
|
{/* Sidebar for desktop */}
|
||||||
<div className="sidebar">
|
<div className="sidebar">
|
||||||
<ul>
|
<ul>
|
||||||
<li onClick={() => setActiveSection('general')}>General</li>
|
<li onClick={() => setActiveSection('general')}>General</li>
|
||||||
<li onClick={() => setActiveSection('privacy')}>Privacy</li>
|
<li onClick={() => setActiveSection('privacy')}>Privacy</li>
|
||||||
<li onClick={() => setActiveSection('theme')}>Theme</li>
|
<li onClick={() => setActiveSection('theme')}>Theme</li>
|
||||||
<li onClick={() => setActiveSection('foss')}>FOSS</li>
|
<li onClick={() => setActiveSection('foss')}>FOSS</li>
|
||||||
<li onClick={() => setActiveSection('account')}>Account</li>
|
<li onClick={() => setActiveSection('account')}>Account</li>
|
||||||
<li onClick={() => setActiveSection('api')}>API Keys</li>
|
<li onClick={() => setActiveSection('api')}>API Keys</li>
|
||||||
<li onClick={() => setActiveSection('im/export')}>Import/Export</li>
|
<li onClick={() => setActiveSection('im/export')}>Import/Export</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="settings-main">
|
<div className="settings-main">
|
||||||
{/* Dropdown for selections in responsive mode */}
|
{/* Dropdown for selections in responsive mode */}
|
||||||
<div className="settings-option dropdown">
|
<div className="settings-option dropdown">
|
||||||
<div className="dropdown-header"><h2>Select a Setting</h2></div>
|
<div className="dropdown-header"><h2>Select a Setting</h2></div>
|
||||||
<select onChange={(e) => setActiveSection(e.target.value)} value={activeSection}>
|
<select onChange={(e) => setActiveSection(e.target.value)} value={activeSection}>
|
||||||
<option value="general">General</option>
|
<option value="general">General</option>
|
||||||
<option value="privacy">Privacy</option>
|
<option value="privacy">Privacy</option>
|
||||||
<option value="theme">Theme</option>
|
<option value="theme">Theme</option>
|
||||||
<option value="foss">FOSS</option>
|
<option value="foss">FOSS</option>
|
||||||
<option value="account">Account</option>
|
<option value="account">Account</option>
|
||||||
<option value="api">API Keys</option>
|
<option value="api">API Keys</option>
|
||||||
<option value="im/export">Import/Export</option>
|
<option value="im/export">Import/Export</option>
|
||||||
</select>
|
</select>
|
||||||
|
</div>
|
||||||
|
<h2>Settings for {accountName}</h2>
|
||||||
|
{renderSettingsContent()}
|
||||||
|
<button className="close-popup" onClick={closeSettings}>Close</button>
|
||||||
|
<button className="apply" onClick={async () => {
|
||||||
|
getAllLocalStorageItems();
|
||||||
|
closeSettings();
|
||||||
|
sendToDatabase();
|
||||||
|
window.location.reload();
|
||||||
|
}}>
|
||||||
|
Apply
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h2>Settings for {accountName}</h2>
|
|
||||||
{renderSettingsContent()}
|
|
||||||
<button className="close-popup" onClick={closeSettings}>Close</button>
|
|
||||||
<button className="apply" onClick={async () => {
|
|
||||||
getAllLocalStorageItems();
|
|
||||||
closeSettings();
|
|
||||||
sendToDatabase();
|
|
||||||
}}>
|
|
||||||
Apply
|
|
||||||
</button>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
// settingsManager.ts
|
// settingsManager.ts
|
||||||
import { changeSettings, getSettings } from "@/app/backend/database";
|
|
||||||
|
|
||||||
// Method to export localStorage to a JSON object
|
// Method to export localStorage to a JSON object
|
||||||
export function exportSettings(): string {
|
export function exportSettings(): string {
|
||||||
|
@ -38,27 +37,3 @@ export function importSettings(jsonData: string): void {
|
||||||
console.error("Invalid JSON data:", error);
|
console.error("Invalid JSON data:", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sendToDatabase = async () => {
|
|
||||||
let useName = localStorage.getItem("accountName")
|
|
||||||
let usePassword = localStorage.getItem("accountPassword")
|
|
||||||
if (useName && usePassword) {
|
|
||||||
let result = await changeSettings(useName, usePassword, JSON.parse(exportSettings()))
|
|
||||||
if (result == true) {
|
|
||||||
alert('Data has been transferred')
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
window.location.reload();
|
|
||||||
};
|
|
||||||
|
|
||||||
export const importDatabase = async (useName: string, usePassword: string) => {
|
|
||||||
const databaseSettings = await getSettings(useName, usePassword);
|
|
||||||
|
|
||||||
// Ensure user settings exist before flattening and storing
|
|
||||||
if (typeof databaseSettings == 'object' && databaseSettings) {
|
|
||||||
importSettings(JSON.stringify(databaseSettings, null, 2)); // Pass only the current user's settings
|
|
||||||
} else {
|
|
||||||
console.error('Database settings are not in the expected format.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
chmod +x root.sh
|
|
||||||
pkexec ./root.sh
|
|
||||||
npm install
|
|
||||||
npm run build
|
|
||||||
|
|
||||||
cd py
|
|
||||||
python3 -m venv venv
|
|
||||||
source venv/bin/activate
|
|
||||||
python3 -m pip install -r requirements.txt
|
|
||||||
|
|
||||||
ollama pull qwen2-math:1.5b
|
|
||||||
ollama pull starcoder2
|
|
||||||
ollama pull llama3.2
|
|
||||||
|
|
||||||
ollama pull wizard-math
|
|
||||||
ollama pull starcoder2:7b
|
|
||||||
ollama pull llama3.1
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
chmod +x run.sh
|
|
|
@ -1,22 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
chmod +x root.sh
|
|
||||||
pkexec ./root.sh
|
|
||||||
npm install
|
|
||||||
npm run build
|
|
||||||
|
|
||||||
cd py
|
|
||||||
python3 -m venv venv
|
|
||||||
source venv/bin/activate
|
|
||||||
python3 -m pip install -r requirements.txt
|
|
||||||
|
|
||||||
ollama pull qwen2-math:1.5b
|
|
||||||
ollama pull qwen2.5-coder:1.5b
|
|
||||||
ollama pull phi3.5
|
|
||||||
|
|
||||||
ollama pull mathstral
|
|
||||||
ollama pull qwen2.5-coder
|
|
||||||
ollama pull qwen2.5
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
chmod +x run.sh
|
|
|
@ -1,7 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
apt install npm nodejs python3-full -y
|
|
||||||
if ! ollama; then
|
|
||||||
curl -fsSL https://ollama.com/install.sh | sh
|
|
||||||
fi
|
|
||||||
systemctl enable ollama --now
|
|
|
@ -1,13 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
cd py
|
|
||||||
python api.py &
|
|
||||||
pid_py=$!
|
|
||||||
|
|
||||||
npm start &
|
|
||||||
pid_node=$!
|
|
||||||
|
|
||||||
npx electron .
|
|
||||||
|
|
||||||
kill $pid_py
|
|
||||||
kill $pid_node
|
|
Loading…
Reference in a new issue