main #43

Merged
YasinOnm08 merged 11 commits from React-Group/interstellar_ai:main into main 2024-10-03 13:16:59 +02:00
Showing only changes of commit 29fd6d0a05 - Show all commits

View file

@ -2,35 +2,34 @@
// Method to export localStorage to a JSON object
export function exportSettings(): string {
const settings: { [key: string]: any } = {};
const settings: { [key: string]: any } = {};
// Loop through all keys in localStorage and add them to the settings object
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key) {
settings[key] = localStorage.getItem(key);
}
}
// Loop through all keys in localStorage and add them to the settings object
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key) {
if (key !== "accountName" && key !== "accountPassword" && key !== "accountEmail") {
settings[key] = localStorage.getItem(key);
}
}
}
// Convert settings object to JSON string
return JSON.stringify(settings, null, 2);
// Convert settings object to JSON string
return JSON.stringify(settings, null, 2);
}
// Method to import settings from a JSON object, clearing old localStorage
export function importSettings(jsonData: string): void {
try {
const parsedSettings = JSON.parse(jsonData);
try {
const parsedSettings = JSON.parse(jsonData);
// Clear the current localStorage
localStorage.clear();
// Loop through parsed settings and save them in localStorage
Object.keys(parsedSettings).forEach((key) => {
localStorage.setItem(key, parsedSettings[key]);
});
// Loop through parsed settings and save them in localStorage
Object.keys(parsedSettings).forEach((key) => {
localStorage.setItem(key, parsedSettings[key]);
});
console.log("Settings imported successfully!");
} catch (error) {
console.error("Invalid JSON data:", error);
}
console.log("Settings imported successfully!");
} catch (error) {
console.error("Invalid JSON data:", error);
}
}