forked from React-Group/interstellar_ai
AHHHHHHH
This commit is contained in:
parent
e0e711f1a9
commit
6bd941031b
1 changed files with 29 additions and 8 deletions
|
@ -15,7 +15,8 @@ import {
|
|||
changeSettings,
|
||||
createAccount,
|
||||
deleteAccount,
|
||||
getSettings
|
||||
getSettings,
|
||||
sendToDatabase
|
||||
} from '../../backend/database';
|
||||
import ThemeDropdown from './DropDownTheme';
|
||||
|
||||
|
@ -299,11 +300,13 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
let useName = localStorage.getItem("accountName")
|
||||
let usePassword = localStorage.getItem("accountPassword")
|
||||
const useName = localStorage.getItem("accountName");
|
||||
const usePassword = localStorage.getItem("accountPassword");
|
||||
|
||||
if (useName && usePassword) {
|
||||
importDatabase(useName, usePassword)
|
||||
importDatabase(useName, usePassword);
|
||||
}
|
||||
|
||||
const savedTheme = localStorage.getItem('selectedTheme');
|
||||
if (savedTheme) {
|
||||
setSelectedTheme(savedTheme);
|
||||
|
@ -311,10 +314,27 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
|||
}
|
||||
}, []); // Runs only once when the component mounts
|
||||
|
||||
const importDatabase = async (useName : string, usePassword : string) => {
|
||||
const databaseSettings = await getSettings(useName, usePassword)
|
||||
importSettings(databaseSettings)
|
||||
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
|
||||
useEffect(() => {
|
||||
// Flatten nested objects
|
||||
|
@ -365,7 +385,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
|||
}
|
||||
|
||||
if (await createAccount(useName, useEmail, usePassword)) {
|
||||
if (await changeSettings(useName, usePassword, handleExport)) {
|
||||
if (await changeSettings(useName, usePassword, settings)) {
|
||||
localStorage.setItem("currentName", useName)
|
||||
localStorage.setItem("currentPassword", usePassword)
|
||||
localStorage.setItem("currentEmail", useEmail)
|
||||
|
@ -774,6 +794,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
|||
<button className="apply" onClick={async () => {
|
||||
getAllLocalStorageItems();
|
||||
closeSettings();
|
||||
sendToDatabase();
|
||||
window.location.reload();
|
||||
}}>
|
||||
Apply
|
||||
|
|
Loading…
Reference in a new issue