feat: add recent plans history to homepage
This commit is contained in:
35
components/plan-tracker.tsx
Normal file
35
components/plan-tracker.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect } from "react"
|
||||
|
||||
export function PlanTracker({ planId, title }: { planId: string, title: string }) {
|
||||
useEffect(() => {
|
||||
const stored = localStorage.getItem("csp_recent_plans")
|
||||
let plans: { id: string, title: string, lastVisited: number }[] = []
|
||||
|
||||
if (stored) {
|
||||
try {
|
||||
plans = JSON.parse(stored)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
// Remove existing entry for this plan
|
||||
plans = plans.filter(p => p.id !== planId)
|
||||
|
||||
// Add to top
|
||||
plans.unshift({
|
||||
id: planId,
|
||||
title: title,
|
||||
lastVisited: Date.now()
|
||||
})
|
||||
|
||||
// Keep max 5
|
||||
plans = plans.slice(0, 5)
|
||||
|
||||
localStorage.setItem("csp_recent_plans", JSON.stringify(plans))
|
||||
}, [planId, title])
|
||||
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user