Persist results to sessionStorage on all pages - prevents data loss on external link clicks

This commit is contained in:
root
2026-03-31 19:13:26 -05:00
parent 88e7bc9c30
commit 2b56d0c06b
8 changed files with 130 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useState, useEffect } from 'react'
import { ListMusic, Loader2, Save, Copy, Check, ExternalLink } from 'lucide-react'
import { generatePlaylist, type GeneratedPlaylistResponse } from '../lib/api'
@@ -9,11 +9,22 @@ export default function PlaylistGenerator() {
const [count, setCount] = useState(25)
const [loading, setLoading] = useState(false)
const [error, setError] = useState('')
const [result, setResult] = useState<GeneratedPlaylistResponse | null>(null)
const [result, setResult] = useState<GeneratedPlaylistResponse | null>(() => {
try {
const saved = sessionStorage.getItem('vynl_playlist_gen_results')
return saved ? JSON.parse(saved) : null
} catch { return null }
})
const [saving, setSaving] = useState(false)
const [saved, setSaved] = useState(false)
const [copied, setCopied] = useState(false)
useEffect(() => {
if (result) {
sessionStorage.setItem('vynl_playlist_gen_results', JSON.stringify(result))
}
}, [result])
const handleGenerate = async () => {
if (!theme.trim()) return
setLoading(true)