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], "id": str(uuid.uuid4())[:8],
"text": text, "text": text,
"note": data.get("note", ""), "note": data.get("note", ""),
"saved_at": datetime.utcnow().isoformat(), "saved_at": datetime.utcnow().isoformat() + "Z",
"used": False, "used": False,
} }
ideas.insert(0, new_idea) ideas.insert(0, new_idea)

View File

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