fix: persist saved idea state across navigation, fix UTC timestamp

- Dashboard: track saved ideas in React state (Set), compare against
  suggestion texts to show "✓ Salvata" persistently
- Backend: append 'Z' to saved_at ISO timestamp so JS parses as UTC
  (fixes "2h fa" bug for UTC+2 users)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Michele
2026-04-06 02:06:16 +02:00
parent 228edf2a91
commit de769aca71
2 changed files with 31 additions and 19 deletions

View File

@@ -493,7 +493,7 @@ def save_idea(
"id": str(uuid.uuid4())[:8],
"text": text,
"note": data.get("note", ""),
"saved_at": datetime.utcnow().isoformat(),
"saved_at": datetime.utcnow().isoformat() + "Z",
"used": False,
}
ideas.insert(0, new_idea)

View File

@@ -15,6 +15,7 @@ export default function Dashboard() {
const [loading, setLoading] = useState(true)
const [suggestions, setSuggestions] = useState(null)
const [suggestionsLoading, setSuggestionsLoading] = useState(false)
const [savedTexts, setSavedTexts] = useState(new Set())
useEffect(() => {
Promise.all([
@@ -38,6 +39,12 @@ export default function Dashboard() {
setRecentPosts(posts.slice(0, 5))
setProviderStatus(providers)
setLoading(false)
// Load saved ideas to know which suggestions are already saved
api.get('/content/ideas').then(data => {
const texts = new Set((data.ideas || []).map(i => i.text))
setSavedTexts(texts)
}).catch(() => {})
// Load cached suggestions (won't regenerate if already generated today)
if (providers?.llm?.configured && chars.length > 0) {
setSuggestionsLoading(true)
@@ -170,24 +177,29 @@ export default function Dashboard() {
>
Genera
</Link>
<button
onClick={async () => {
try {
await api.post('/content/ideas', { text: topic })
// Brief visual feedback
const btn = document.getElementById(`save-idea-${i}`)
if (btn) { btn.textContent = '✓ Salvata'; btn.style.color = 'var(--success)' }
} catch {}
}}
id={`save-idea-${i}`}
style={{
fontSize: '0.72rem', color: 'var(--ink-muted)', fontWeight: 500,
background: 'none', border: 'none', cursor: 'pointer', padding: 0,
transition: 'color 0.15s',
}}
>
Salva idea
</button>
{savedTexts.has(topic) ? (
<span style={{ fontSize: '0.72rem', color: 'var(--success)', fontWeight: 600 }}>
Salvata
</span>
) : (
<button
onClick={async () => {
try {
await api.post('/content/ideas', { text: topic })
setSavedTexts(prev => new Set([...prev, topic]))
} catch {}
}}
style={{
fontSize: '0.72rem', color: 'var(--ink-muted)', fontWeight: 500,
background: 'none', border: 'none', cursor: 'pointer', padding: 0,
transition: 'color 0.15s',
}}
onMouseEnter={e => e.target.style.color = 'var(--accent)'}
onMouseLeave={e => e.target.style.color = 'var(--ink-muted)'}
>
Salva idea
</button>
)}
</div>
</div>
))}