mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 23:44:22 +00:00
FE Settings integration
This commit is contained in:
@@ -13,7 +13,7 @@ type UserSettings struct {
|
|||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
UserID int `json:"userId" validate:"required,min=1"`
|
UserID int `json:"userId" validate:"required,min=1"`
|
||||||
Settings UserSettings `json:"settings" validate:"required,dive"`
|
Settings UserSettings `json:"settings" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var validate = validator.New()
|
var validate = validator.New()
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { GeistProvider, CssBaseline, Page } from '@geist-ui/core';
|
import { GeistProvider, CssBaseline, Page } from '@geist-ui/core';
|
||||||
import Header from './components/Header';
|
import Header from './components/Header';
|
||||||
import MainContent from './components/MainContent';
|
import MainContent from './components/MainContent';
|
||||||
import useFileManagement from './hooks/useFileManagement';
|
import useFileManagement from './hooks/useFileManagement';
|
||||||
|
import { fetchUserSettings } from './services/api';
|
||||||
import './App.scss';
|
import './App.scss';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [themeType, setThemeType] = useState('light');
|
const [themeType, setThemeType] = useState('light');
|
||||||
|
const [userId, setUserId] = useState(1);
|
||||||
const {
|
const {
|
||||||
content,
|
content,
|
||||||
files,
|
files,
|
||||||
@@ -19,6 +21,19 @@ function App() {
|
|||||||
handleSave,
|
handleSave,
|
||||||
} = useFileManagement();
|
} = useFileManagement();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadUserSettings = async () => {
|
||||||
|
try {
|
||||||
|
const settings = await fetchUserSettings(userId);
|
||||||
|
setThemeType(settings.settings.theme);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load user settings:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadUserSettings();
|
||||||
|
}, [userId]);
|
||||||
|
|
||||||
const toggleTheme = () => {
|
const toggleTheme = () => {
|
||||||
setThemeType(prevTheme => prevTheme === 'light' ? 'dark' : 'light');
|
setThemeType(prevTheme => prevTheme === 'light' ? 'dark' : 'light');
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,30 @@
|
|||||||
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 } from '@geist-ui/core';
|
||||||
|
import { saveUserSettings } from '../services/api';
|
||||||
|
|
||||||
const Settings = ({ visible, onClose, currentTheme, onThemeChange, onSettingsChange }) => {
|
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 handleSubmit = () => {
|
const handleSubmit = async () => {
|
||||||
onSettingsChange({ fontSize, autoSave });
|
try {
|
||||||
onClose();
|
await saveUserSettings({
|
||||||
|
userId: userId,
|
||||||
|
settings: {
|
||||||
|
theme: currentTheme,
|
||||||
|
autoSave: autoSave
|
||||||
|
}
|
||||||
|
});
|
||||||
|
onClose();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to save settings:', error);
|
||||||
|
// You might want to show an error message to the user here
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleThemeChange = () => {
|
||||||
|
onThemeChange();
|
||||||
};
|
};
|
||||||
|
|
||||||
const disabledMessage = "This feature is not yet implemented";
|
const disabledMessage = "This feature is not yet implemented";
|
||||||
@@ -22,7 +39,7 @@ const Settings = ({ visible, onClose, currentTheme, onThemeChange, onSettingsCha
|
|||||||
<Text>Dark Mode</Text>
|
<Text>Dark Mode</Text>
|
||||||
<Toggle
|
<Toggle
|
||||||
checked={currentTheme === 'dark'}
|
checked={currentTheme === 'dark'}
|
||||||
onChange={() => onThemeChange()}
|
onChange={handleThemeChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -40,4 +40,36 @@ export const saveFileContent = async (filePath, content) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return await response.text();
|
return await response.text();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fetchUserSettings = async (userId) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/settings?userId=${userId}`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to fetch user settings');
|
||||||
|
}
|
||||||
|
return await response.json();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching user settings:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const saveUserSettings = async (settings) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/settings`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(settings),
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to save user settings');
|
||||||
|
}
|
||||||
|
return await response.json();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error saving user settings:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user