mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-07 08:24:27 +00:00
Fix settings not closing on submit bug
This commit is contained in:
@@ -120,6 +120,15 @@ func UpdateSettings(db *db.DB) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch the saved settings to return
|
||||||
|
savedSettings, err := db.GetSettings(settings.UserID)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Settings saved but could not be retrieved", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
json.NewEncoder(w).Encode(savedSettings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,15 +34,15 @@ function App() {
|
|||||||
loadUserSettings();
|
loadUserSettings();
|
||||||
}, [userId]);
|
}, [userId]);
|
||||||
|
|
||||||
const toggleTheme = () => {
|
const setTheme = (newTheme) => {
|
||||||
setThemeType(prevTheme => prevTheme === 'light' ? 'dark' : 'light');
|
setThemeType(newTheme);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GeistProvider themeType={themeType}>
|
<GeistProvider themeType={themeType}>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<Page>
|
<Page>
|
||||||
<Header currentTheme={themeType} onThemeChange={toggleTheme} />
|
<Header currentTheme={themeType} onThemeChange={setTheme} />
|
||||||
<Page.Content>
|
<Page.Content>
|
||||||
<MainContent
|
<MainContent
|
||||||
content={content}
|
content={content}
|
||||||
|
|||||||
@@ -1,30 +1,35 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Modal, Text, Toggle, Tooltip, Spacer, useTheme } from '@geist-ui/core';
|
import { Modal, Text, Toggle, Tooltip, Spacer, useTheme, useToasts } from '@geist-ui/core';
|
||||||
import { saveUserSettings } from '../services/api';
|
import { saveUserSettings } from '../services/api';
|
||||||
|
|
||||||
const Settings = ({ visible, onClose, currentTheme, onThemeChange }) => {
|
const Settings = ({ visible, onClose, currentTheme, onThemeChange }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [autoSave, setAutoSave] = useState(false);
|
const [autoSave, setAutoSave] = useState(false);
|
||||||
const userId = 1;
|
const userId = 1;
|
||||||
|
const { setToast } = useToasts();
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
try {
|
try {
|
||||||
await saveUserSettings({
|
const savedSettings = await saveUserSettings({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
settings: {
|
settings: {
|
||||||
theme: currentTheme,
|
theme: currentTheme,
|
||||||
autoSave: autoSave
|
autoSave: autoSave
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
setToast({ text: 'Settings saved successfully', type: 'success' });
|
||||||
|
// Update local state with saved settings
|
||||||
|
setAutoSave(savedSettings.settings.autoSave);
|
||||||
|
onThemeChange(savedSettings.settings.theme);
|
||||||
onClose();
|
onClose();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to save settings:', error);
|
console.error('Failed to save settings:', error);
|
||||||
// You might want to show an error message to the user here
|
setToast({ text: 'Failed to save settings: ' + error.message, type: 'error' });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleThemeChange = () => {
|
const handleThemeChange = () => {
|
||||||
onThemeChange();
|
onThemeChange(currentTheme === 'light' ? 'dark' : 'light');
|
||||||
};
|
};
|
||||||
|
|
||||||
const disabledMessage = "This feature is not yet implemented";
|
const disabledMessage = "This feature is not yet implemented";
|
||||||
|
|||||||
@@ -64,10 +64,14 @@ export const saveUserSettings = async (settings) => {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify(settings),
|
body: JSON.stringify(settings),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to save user settings');
|
const errorData = await response.json().catch(() => null);
|
||||||
|
throw new Error(errorData?.message || `HTTP error! status: ${response.status}`);
|
||||||
}
|
}
|
||||||
return await response.json();
|
|
||||||
|
const savedSettings = await response.json();
|
||||||
|
return savedSettings;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error saving user settings:', error);
|
console.error('Error saving user settings:', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
Reference in New Issue
Block a user