forked from React-Group/interstellar_ai
Compare commits
No commits in common. "dc44bd22d7cc0c6a123305005836b04e53c7d595" and "76da6aed0e54b0ab6bef32028a51f46a2cdce2e0" have entirely different histories.
dc44bd22d7
...
76da6aed0e
2 changed files with 27 additions and 52 deletions
|
@ -1,4 +1,3 @@
|
||||||
//#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 } from './settingUtils'; // Import utility functions
|
import { exportSettings, importSettings } from './settingUtils'; // Import utility functions
|
||||||
|
@ -35,8 +34,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
return false; // Default to false if item is null or empty
|
return false; // Default to false if item is null or empty
|
||||||
};
|
};
|
||||||
|
|
||||||
//#region variables
|
|
||||||
|
|
||||||
// Active section
|
// Active section
|
||||||
const [activeSection, setActiveSection] = useState(() => localStorage.getItem('activeSection') || 'general');
|
const [activeSection, setActiveSection] = useState(() => localStorage.getItem('activeSection') || 'general');
|
||||||
|
|
||||||
|
@ -290,7 +287,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
{ value: "'Zilla Slab Highlight', serif", label: 'Zilla Slab Highlight' },
|
{ value: "'Zilla Slab Highlight', serif", label: 'Zilla Slab Highlight' },
|
||||||
];
|
];
|
||||||
|
|
||||||
//#region Start of the code
|
|
||||||
const handleLogout = () => {
|
const handleLogout = () => {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
alert('Successfully logged out!');
|
alert('Successfully logged out!');
|
||||||
|
@ -383,11 +379,10 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//#region rendered content
|
|
||||||
// Render settings content based on the active section
|
// Render settings content based on the active section
|
||||||
const renderSettingsContent = () => {
|
const renderSettingsContent = () => {
|
||||||
switch (activeSection) {
|
switch (activeSection) {
|
||||||
//#region general
|
|
||||||
case 'general':
|
case 'general':
|
||||||
return (
|
return (
|
||||||
<div className="settings-section">
|
<div className="settings-section">
|
||||||
|
@ -444,7 +439,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
);
|
);
|
||||||
|
|
||||||
case 'privacy':
|
case 'privacy':
|
||||||
//#region privacy
|
|
||||||
return (
|
return (
|
||||||
<div className="settings-section">
|
<div className="settings-section">
|
||||||
<h2>Privacy Settings</h2>
|
<h2>Privacy Settings</h2>
|
||||||
|
@ -471,8 +465,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
|
|
||||||
|
|
||||||
case 'theme':
|
case 'theme':
|
||||||
//#region theme
|
|
||||||
//#region Basic
|
|
||||||
return (
|
return (
|
||||||
<div className="settings-section">
|
<div className="settings-section">
|
||||||
<h2>Theme Settings</h2>
|
<h2>Theme Settings</h2>
|
||||||
|
@ -481,6 +473,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
selectedTheme={selectedTheme}
|
selectedTheme={selectedTheme}
|
||||||
setSelectedTheme={setSelectedTheme}
|
setSelectedTheme={setSelectedTheme}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{selectedTheme === 'BASIC-CUSTOM' && (
|
{selectedTheme === 'BASIC-CUSTOM' && (
|
||||||
<>
|
<>
|
||||||
<h3>Basic Colors</h3>
|
<h3>Basic Colors</h3>
|
||||||
|
@ -515,19 +508,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
setValue={setBasicTextColor}
|
setValue={setBasicTextColor}
|
||||||
cssVariable=""
|
cssVariable=""
|
||||||
/>
|
/>
|
||||||
<DropdownSetting
|
|
||||||
label="Font Family"
|
|
||||||
value={fontFamily}
|
|
||||||
setValue={(newFont) => {
|
|
||||||
setFontFamily(newFont);
|
|
||||||
document.documentElement.style.setProperty('--font-family', newFont);
|
|
||||||
}}
|
|
||||||
options={fontOptions}
|
|
||||||
/>
|
|
||||||
<FontSizeSetting
|
|
||||||
fontSize={fontSize}
|
|
||||||
setFontSize={setFontSize}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
@ -563,7 +543,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
//#region custom --> foss
|
|
||||||
case 'foss':
|
case 'foss':
|
||||||
return (
|
return (
|
||||||
<div className="settings-section">
|
<div className="settings-section">
|
||||||
|
@ -576,7 +556,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
//#region account
|
|
||||||
case 'account':
|
case 'account':
|
||||||
return (
|
return (
|
||||||
<div className="settings-section">
|
<div className="settings-section">
|
||||||
|
@ -619,7 +599,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
//#region api
|
|
||||||
case 'api':
|
case 'api':
|
||||||
return (
|
return (
|
||||||
<div className="settings-section">
|
<div className="settings-section">
|
||||||
|
@ -673,7 +653,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
//#region import export
|
|
||||||
case 'im/export':
|
case 'im/export':
|
||||||
return (
|
return (
|
||||||
<div className="settings-section">
|
<div className="settings-section">
|
||||||
|
@ -727,7 +707,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
URL.revokeObjectURL(url); // Clean up the URL object
|
URL.revokeObjectURL(url); // Clean up the URL object
|
||||||
};
|
};
|
||||||
|
|
||||||
//#region overall export
|
|
||||||
return (
|
return (
|
||||||
<div className="popup-overlay">
|
<div className="popup-overlay">
|
||||||
<div className="settings-content">
|
<div className="settings-content">
|
||||||
|
|
46
py/db.py
46
py/db.py
|
@ -9,11 +9,11 @@ class DB:
|
||||||
self.database = {}
|
self.database = {}
|
||||||
|
|
||||||
def ensure_username(self, data):
|
def ensure_username(self, data):
|
||||||
if "username" in data:
|
if 'username' in data:
|
||||||
return data.get("username")
|
return data.get('username')
|
||||||
elif "email" in data:
|
elif 'email' in data:
|
||||||
for index, entry in self.database.items():
|
for index, entry in self.database:
|
||||||
if entry.get("email") == data.get("email"):
|
if entry.get('email') == data.get('email'):
|
||||||
return index
|
return index
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -23,16 +23,11 @@ class DB:
|
||||||
return hashed_password
|
return hashed_password
|
||||||
|
|
||||||
def add_user(self, data):
|
def add_user(self, data):
|
||||||
username = data.get("username")
|
username = data.get('username')
|
||||||
password = data.get("password")
|
password = data.get('password')
|
||||||
email = data.get("email")
|
email = data.get('email')
|
||||||
hashed_password = self.hash_password(password)
|
hashed_password = self.hash_password(password)
|
||||||
user_data = {
|
user_data = {"hashed_password": hashed_password, "email": email, "settings": None, "history": None}
|
||||||
"hashed_password": hashed_password,
|
|
||||||
"email": email,
|
|
||||||
"settings": None,
|
|
||||||
"history": None,
|
|
||||||
}
|
|
||||||
if username not in self.database:
|
if username not in self.database:
|
||||||
self.database[username] = user_data
|
self.database[username] = user_data
|
||||||
self.save_database()
|
self.save_database()
|
||||||
|
@ -50,7 +45,7 @@ class DB:
|
||||||
|
|
||||||
def update_password(self, data):
|
def update_password(self, data):
|
||||||
username = self.ensure_username(data)
|
username = self.ensure_username(data)
|
||||||
new_password = data.get("new_password")
|
new_password = data.get('new_password')
|
||||||
if not self.check_credentials(data):
|
if not self.check_credentials(data):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -61,7 +56,7 @@ class DB:
|
||||||
|
|
||||||
def check_credentials(self, data):
|
def check_credentials(self, data):
|
||||||
username = self.ensure_username(data)
|
username = self.ensure_username(data)
|
||||||
password = data.get("password")
|
password = data.get('password')
|
||||||
if username not in self.database:
|
if username not in self.database:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -75,7 +70,7 @@ class DB:
|
||||||
if not self.check_credentials(data):
|
if not self.check_credentials(data):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.database[username]["settings"] = data.get("data")
|
self.database[username]['settings'] = data.get('data')
|
||||||
self.save_database()
|
self.save_database()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -84,7 +79,7 @@ class DB:
|
||||||
if not self.check_credentials(data):
|
if not self.check_credentials(data):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
send_back = self.database[username].get("settings")
|
send_back = self.database[username].get('settings')
|
||||||
return send_back
|
return send_back
|
||||||
|
|
||||||
def change_history(self, data):
|
def change_history(self, data):
|
||||||
|
@ -92,7 +87,7 @@ class DB:
|
||||||
if not self.check_credentials(data):
|
if not self.check_credentials(data):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.database[username]["history"] = data.get("data")
|
self.database[username]['history'] = data.get('data')
|
||||||
self.save_database()
|
self.save_database()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -101,7 +96,7 @@ class DB:
|
||||||
if not self.check_credentials(data):
|
if not self.check_credentials(data):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
send_back = self.database[username].get("history")
|
send_back = self.database[username].get('history')
|
||||||
return send_back
|
return send_back
|
||||||
|
|
||||||
def get_email(self, data):
|
def get_email(self, data):
|
||||||
|
@ -109,10 +104,11 @@ class DB:
|
||||||
if not self.check_credentials(data):
|
if not self.check_credentials(data):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
send_back = self.database[username].get("email")
|
send_back = self.database[username].get('email')
|
||||||
return send_back
|
return send_back
|
||||||
|
|
||||||
def get_name(self, data):
|
def get_name(self, data):
|
||||||
|
username = self.ensure_username(data)
|
||||||
if not self.check_credentials(data):
|
if not self.check_credentials(data):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -120,18 +116,18 @@ class DB:
|
||||||
return send_back
|
return send_back
|
||||||
|
|
||||||
def save_database(self):
|
def save_database(self):
|
||||||
if os.environ.get("PRODUCTION") == "YES":
|
if os.environ.get('PRODUCTION') == "YES":
|
||||||
server = pycouchdb.Server("http://admin:admin@localhost:5984/")
|
server = pycouchdb.Server("http://admin:admin@localhost:5984/")
|
||||||
db = server.database("interstellar_ai")
|
db = server.database("interstellar_ai")
|
||||||
db.save(self.database)
|
db.save(self.database)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
with open("database.json", "w") as file:
|
with open("database.json", 'w') as file:
|
||||||
print("saving")
|
print("saving")
|
||||||
json.dump(self.database, file)
|
json.dump(self.database, file)
|
||||||
|
|
||||||
def load_database(self):
|
def load_database(self):
|
||||||
if os.environ.get("PRODUCTION") == "YES":
|
if os.environ.get('PRODUCTION') == "YES":
|
||||||
server = pycouchdb.Server("http://admin:admin@localhost:5984/")
|
server = pycouchdb.Server("http://admin:admin@localhost:5984/")
|
||||||
db = server.database("interstellar_ai")
|
db = server.database("interstellar_ai")
|
||||||
if db:
|
if db:
|
||||||
|
@ -142,7 +138,7 @@ class DB:
|
||||||
db.save(self.database)
|
db.save(self.database)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
with open("database.json", "r") as file:
|
with open("database.json", 'r') as file:
|
||||||
self.database = json.load(file)
|
self.database = json.load(file)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue