I have immense pain in the left temple.
This commit is contained in:
parent
5adb7ff56e
commit
6435bfad8d
3 changed files with 96 additions and 78 deletions
|
@ -5,6 +5,7 @@ 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
|
||||||
|
@ -40,6 +41,14 @@ 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();
|
||||||
|
@ -69,6 +78,14 @@ 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 } from './settingUtils'; // Import utility functions
|
import { exportSettings, importSettings, sendToDatabase, importDatabase } 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,8 +15,6 @@ import {
|
||||||
changeSettings,
|
changeSettings,
|
||||||
createAccount,
|
createAccount,
|
||||||
deleteAccount,
|
deleteAccount,
|
||||||
getSettings,
|
|
||||||
sendToDatabase
|
|
||||||
} from '../../backend/database';
|
} from '../../backend/database';
|
||||||
import ThemeDropdown from './DropDownTheme';
|
import ThemeDropdown from './DropDownTheme';
|
||||||
|
|
||||||
|
@ -314,27 +312,6 @@ 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
|
||||||
|
@ -795,7 +772,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
getAllLocalStorageItems();
|
getAllLocalStorageItems();
|
||||||
closeSettings();
|
closeSettings();
|
||||||
sendToDatabase();
|
sendToDatabase();
|
||||||
window.location.reload();
|
|
||||||
}}>
|
}}>
|
||||||
Apply
|
Apply
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// 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 {
|
||||||
|
@ -37,3 +38,27 @@ 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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue