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:
@@ -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)
|
||||||
|
|||||||
@@ -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>
|
||||||
<button
|
{savedTexts.has(topic) ? (
|
||||||
onClick={async () => {
|
<span style={{ fontSize: '0.72rem', color: 'var(--success)', fontWeight: 600 }}>
|
||||||
try {
|
✓ Salvata
|
||||||
await api.post('/content/ideas', { text: topic })
|
</span>
|
||||||
// Brief visual feedback
|
) : (
|
||||||
const btn = document.getElementById(`save-idea-${i}`)
|
<button
|
||||||
if (btn) { btn.textContent = '✓ Salvata'; btn.style.color = 'var(--success)' }
|
onClick={async () => {
|
||||||
} catch {}
|
try {
|
||||||
}}
|
await api.post('/content/ideas', { text: topic })
|
||||||
id={`save-idea-${i}`}
|
setSavedTexts(prev => new Set([...prev, topic]))
|
||||||
style={{
|
} catch {}
|
||||||
fontSize: '0.72rem', color: 'var(--ink-muted)', fontWeight: 500,
|
}}
|
||||||
background: 'none', border: 'none', cursor: 'pointer', padding: 0,
|
style={{
|
||||||
transition: 'color 0.15s',
|
fontSize: '0.72rem', color: 'var(--ink-muted)', fontWeight: 500,
|
||||||
}}
|
background: 'none', border: 'none', cursor: 'pointer', padding: 0,
|
||||||
>
|
transition: 'color 0.15s',
|
||||||
Salva idea
|
}}
|
||||||
</button>
|
onMouseEnter={e => e.target.style.color = 'var(--accent)'}
|
||||||
|
onMouseLeave={e => e.target.style.color = 'var(--ink-muted)'}
|
||||||
|
>
|
||||||
|
Salva idea
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in New Issue
Block a user