From a995c114b678c9a8fc939bafb7ac97e14a68d6f4 Mon Sep 17 00:00:00 2001 From: sageTheDM Date: Mon, 7 Oct 2024 14:55:24 +0200 Subject: [PATCH 1/2] minor changes --- app/components/settings/Settings.tsx | 33 +++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/app/components/settings/Settings.tsx b/app/components/settings/Settings.tsx index 874ebe1..23734f2 100644 --- a/app/components/settings/Settings.tsx +++ b/app/components/settings/Settings.tsx @@ -1,3 +1,4 @@ +//#region imports import React, { useState, useEffect } from 'react'; import { applyTheme } from './theme'; import { exportSettings, importSettings } from './settingUtils'; // Import utility functions @@ -34,6 +35,8 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( return false; // Default to false if item is null or empty }; + //#region variables + // Active section const [activeSection, setActiveSection] = useState(() => localStorage.getItem('activeSection') || 'general'); @@ -287,6 +290,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( { value: "'Zilla Slab Highlight', serif", label: 'Zilla Slab Highlight' }, ]; + //#region Start of the code const handleLogout = () => { localStorage.clear(); alert('Successfully logged out!'); @@ -379,10 +383,11 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( } }; - + //#region rendered content // Render settings content based on the active section const renderSettingsContent = () => { switch (activeSection) { + //#region general case 'general': return (
@@ -439,6 +444,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( ); case 'privacy': + //#region privacy return (

Privacy Settings

@@ -465,6 +471,8 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( case 'theme': + //#region theme + //#region Basic return (

Theme Settings

@@ -473,7 +481,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( selectedTheme={selectedTheme} setSelectedTheme={setSelectedTheme} /> - {selectedTheme === 'BASIC-CUSTOM' && ( <>

Basic Colors

@@ -508,6 +515,19 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( setValue={setBasicTextColor} cssVariable="" /> + { + setFontFamily(newFont); + document.documentElement.style.setProperty('--font-family', newFont); + }} + options={fontOptions} + /> + )} @@ -543,7 +563,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( )}
); - + //#region custom --> foss case 'foss': return (
@@ -556,7 +576,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
); - + //#region account case 'account': return (
@@ -599,7 +619,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( />
); - + //#region api case 'api': return (
@@ -653,7 +673,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
); - + //#region import export case 'im/export': return (
@@ -707,6 +727,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( URL.revokeObjectURL(url); // Clean up the URL object }; + //#region overall export return (
-- 2.39.5 From 8ccf86bcb7daab99c9ba6332e4bb664c5cb5f8a4 Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Mon, 7 Oct 2024 15:01:06 +0200 Subject: [PATCH 2/2] such good code (joke) --- py/db.py | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/py/db.py b/py/db.py index 5a15957..a773552 100644 --- a/py/db.py +++ b/py/db.py @@ -9,11 +9,11 @@ class DB: self.database = {} def ensure_username(self, data): - if 'username' in data: - return data.get('username') - elif 'email' in data: - for index, entry in self.database: - if entry.get('email') == data.get('email'): + if "username" in data: + return data.get("username") + elif "email" in data: + for index, entry in self.database.items(): + if entry.get("email") == data.get("email"): return index @staticmethod @@ -23,11 +23,16 @@ class DB: return hashed_password def add_user(self, data): - username = data.get('username') - password = data.get('password') - email = data.get('email') + username = data.get("username") + password = data.get("password") + email = data.get("email") hashed_password = self.hash_password(password) - user_data = {"hashed_password": hashed_password, "email": email, "settings": None, "history": None} + user_data = { + "hashed_password": hashed_password, + "email": email, + "settings": None, + "history": None, + } if username not in self.database: self.database[username] = user_data self.save_database() @@ -45,7 +50,7 @@ class DB: def update_password(self, data): username = self.ensure_username(data) - new_password = data.get('new_password') + new_password = data.get("new_password") if not self.check_credentials(data): return False @@ -56,7 +61,7 @@ class DB: def check_credentials(self, data): username = self.ensure_username(data) - password = data.get('password') + password = data.get("password") if username not in self.database: return False @@ -70,7 +75,7 @@ class DB: if not self.check_credentials(data): return False - self.database[username]['settings'] = data.get('data') + self.database[username]["settings"] = data.get("data") self.save_database() return True @@ -79,7 +84,7 @@ class DB: if not self.check_credentials(data): return None - send_back = self.database[username].get('settings') + send_back = self.database[username].get("settings") return send_back def change_history(self, data): @@ -87,7 +92,7 @@ class DB: if not self.check_credentials(data): return False - self.database[username]['history'] = data.get('data') + self.database[username]["history"] = data.get("data") self.save_database() return True @@ -96,7 +101,7 @@ class DB: if not self.check_credentials(data): return None - send_back = self.database[username].get('history') + send_back = self.database[username].get("history") return send_back def get_email(self, data): @@ -104,11 +109,10 @@ class DB: if not self.check_credentials(data): return None - send_back = self.database[username].get('email') + send_back = self.database[username].get("email") return send_back def get_name(self, data): - username = self.ensure_username(data) if not self.check_credentials(data): return None @@ -116,18 +120,18 @@ class DB: return send_back def save_database(self): - if os.environ.get('PRODUCTION') == "YES": + if os.environ.get("PRODUCTION") == "YES": server = pycouchdb.Server("http://admin:admin@localhost:5984/") db = server.database("interstellar_ai") db.save(self.database) else: - with open("database.json", 'w') as file: + with open("database.json", "w") as file: print("saving") json.dump(self.database, file) def load_database(self): - if os.environ.get('PRODUCTION') == "YES": + if os.environ.get("PRODUCTION") == "YES": server = pycouchdb.Server("http://admin:admin@localhost:5984/") db = server.database("interstellar_ai") if db: @@ -138,7 +142,7 @@ class DB: db.save(self.database) else: try: - with open("database.json", 'r') as file: + with open("database.json", "r") as file: self.database = json.load(file) except FileNotFoundError: pass -- 2.39.5