import { useState, useEffect } from 'react'; import { Box, TextField, Button, Typography, Alert, Paper, Stack } from '@mui/material'; import { getSetting, updateSetting, resetSetting } from '../services/settings'; export default function Settings({ onBack }: { onBack?: () => void }) { const [systemPrompt, setSystemPrompt] = useState(''); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [isDefault, setIsDefault] = useState(true); const [message, setMessage] = useState<{ text: string; type: 'success' | 'error' } | null>(null); useEffect(() => { loadSystemPrompt(); }, []); const loadSystemPrompt = async () => { try { setLoading(true); const data = await getSetting('system_prompt'); setSystemPrompt(data.value); setIsDefault(data.isDefault); } catch (err: any) { setMessage({ text: err?.message || 'Failed to load settings', type: 'error' }); } finally { setLoading(false); } }; const handleSave = async () => { try { setSaving(true); setMessage(null); await updateSetting('system_prompt', systemPrompt); setIsDefault(false); setMessage({ text: 'System prompt saved successfully!', type: 'success' }); } catch (err: any) { setMessage({ text: err?.message || 'Failed to save settings', type: 'error' }); } finally { setSaving(false); } }; const handleReset = async () => { if (!confirm('Reset to default system prompt? This will delete your custom prompt.')) { return; } try { setSaving(true); setMessage(null); await resetSetting('system_prompt'); await loadSystemPrompt(); setMessage({ text: 'Reset to default system prompt', type: 'success' }); } catch (err: any) { setMessage({ text: err?.message || 'Failed to reset settings', type: 'error' }); } finally { setSaving(false); } }; if (loading) { return ( Loading settings... ); } return ( Settings {onBack && ( )} {message && ( setMessage(null)}> {message.text} )} AI System Prompt This prompt defines how the AI generates article content. It controls the output format, HTML structure, image placeholder format, and writing style. {isDefault && ( Currently using default system prompt )} setSystemPrompt(e.target.value)} fullWidth multiline minRows={15} maxRows={30} sx={{ mb: 2, fontFamily: 'monospace' }} placeholder="Enter custom system prompt..." /> 💡 Tips for customizing the system prompt:
  • Keep the image placeholder format: {`{{IMAGE:description}}`}
  • Specify HTML tags to use (h2, h3, p, ul, ol, etc.)
  • Define the writing style and tone
  • Set content structure requirements
  • Add SEO or formatting guidelines
  • ); }